From 90df1f48d56657586f77eb7e6e747866105937fd Mon Sep 17 00:00:00 2001 From: Tobias Edler von Koch Date: Thu, 13 Apr 2017 16:24:14 +0000 Subject: LTO: Pass SF_Executable flag through to InputFile::Symbol Summary: The linker needs to be able to determine whether a symbol is text or data to handle the case of a common being overridden by a strong definition in an archive. If the archive contains a text member of the same name as the common, that function is discarded. However, if the archive contains a data member of the same name, that strong definition overrides the common. This is a behavior of ld.bfd, which the Qualcomm linker also supports in LTO. Here's a test case to illustrate: #### cat > 1.c << \! int blah; ! cat > 2.c << \! int blah() { return 0; } ! cat > 3.c << \! int blah = 20; ! clang -c 1.c clang -c 2.c clang -c 3.c ar cr lib.a 2.o 3.o ld 1.o lib.a -t #### The correct output is: 1.o (lib.a)3.o Thanks to Shankar Easwaran and Hemant Kulkarni for the test case! Reviewers: mehdi_amini, rafael, pcc, davide Reviewed By: pcc Subscribers: davide, llvm-commits, inglorion Differential Revision: https://reviews.llvm.org/D31901 llvm-svn: 300205 --- llvm/lib/Object/IRSymtab.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'llvm/lib/Object/IRSymtab.cpp') diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index 1ef2c4bb730..f78b84b388a 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -125,6 +125,8 @@ Error Builder::addSymbol(ModuleSymbolTable::Symbol Msym) { Sym.Flags |= 1 << storage::Symbol::FB_global; if (Flags & object::BasicSymbolRef::SF_FormatSpecific) Sym.Flags |= 1 << storage::Symbol::FB_format_specific; + if (Flags & object::BasicSymbolRef::SF_Executable) + Sym.Flags |= 1 << storage::Symbol::FB_executable; Sym.ComdatIndex = -1; auto *GV = Msym.dyn_cast(); -- cgit v1.2.3