[PATCH] D31901: LTO: Pass SF_Executable flag through to InputFile::Symbol

Tobias Edler von Koch via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:53:39 PDT 2017


tobiasvk created this revision.
Herald added a subscriber: inglorion.

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!


https://reviews.llvm.org/D31901

Files:
  include/llvm/LTO/LTO.h
  include/llvm/Object/IRSymtab.h
  lib/Object/IRSymtab.cpp


Index: lib/Object/IRSymtab.cpp
===================================================================
--- lib/Object/IRSymtab.cpp
+++ lib/Object/IRSymtab.cpp
@@ -125,6 +125,8 @@
     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<GlobalValue *>();
Index: include/llvm/Object/IRSymtab.h
===================================================================
--- include/llvm/Object/IRSymtab.h
+++ include/llvm/Object/IRSymtab.h
@@ -92,6 +92,7 @@
     FB_global,
     FB_format_specific,
     FB_unnamed_addr,
+    FB_executable,
   };
 
   /// The index into the Uncommon table, or -1 if this symbol does not have an
@@ -166,6 +167,7 @@
   bool isGlobal() const { return (Flags >> S::FB_global) & 1; }
   bool isFormatSpecific() const { return (Flags >> S::FB_format_specific) & 1; }
   bool isUnnamedAddr() const { return (Flags >> S::FB_unnamed_addr) & 1; }
+  bool isExecutable() const { return (Flags >> S::FB_executable) & 1; }
 
   uint64_t getCommonSize() const {
     assert(isCommon());
Index: include/llvm/LTO/LTO.h
===================================================================
--- include/llvm/LTO/LTO.h
+++ include/llvm/LTO/LTO.h
@@ -126,6 +126,7 @@
     using irsymtab::Symbol::getCommonSize;
     using irsymtab::Symbol::getCommonAlignment;
     using irsymtab::Symbol::getCOFFWeakExternalFallback;
+    using irsymtab::Symbol::isExecutable;
   };
 
   /// A range over the symbols in this InputFile.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31901.94711.patch
Type: text/x-patch
Size: 1699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170410/937abd10/attachment.bin>


More information about the llvm-commits mailing list