[PATCH] D18357: [LTO] Include in .symtab/.dynsym symbols introduced by optimizations

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 22 09:54:01 PDT 2016


davide created this revision.
davide added reviewers: rafael, joker.eph.
davide added a subscriber: llvm-commits.
Herald added a subscriber: joker.eph.

Some optimizations, e.g. SimplifyLibCalls, can replace functions with others as part of the lowering, e.g. printf => puts.
The new symbols don't have the isUsedInRegularObj flag set so they don't get included in the final symbol table (and dynamic symbol table), and the dynamic linker gets confused.

davide at foogoo:~/llvm/build/bin % ./clang blah.c -o blah -flto -fuse-ld=lld -Wl,-L/lib
davide at foogoo:~/llvm/build/bin % ./blah
Segmentation fault (core dumped)
davide at foogoo:~/llvm/build/bin % ./llvm-nm ./blah | grep puts

% cat blah.c
#include <stdio.h>

int main(void)
{
  printf("blah\n");
  return (0);
}

My proposed fix is to set the flag in addCombinedLtoObject() once we see the new symbols. I'm working on a testcase now, but I would like to hear if this sounds reasonable to you.

http://reviews.llvm.org/D18357

Files:
  ELF/SymbolTable.cpp
  ELF/Symbols.h

Index: ELF/Symbols.h
===================================================================
--- ELF/Symbols.h
+++ ELF/Symbols.h
@@ -73,6 +73,7 @@
   bool isShared() const { return SymbolKind == SharedKind; }
   bool isLocal() const { return IsLocal; }
   bool isUsedInRegularObj() const { return IsUsedInRegularObj; }
+  void setUsedInRegularObj() { IsUsedInRegularObj = true; }
   bool isPreemptible() const;
   template <class ELFT> bool isGnuIfunc() const;

@@ -317,7 +318,6 @@
   std::unique_ptr<InputFile> getMember();

   void setWeak() { IsWeak = true; }
-  void setUsedInRegularObj() { IsUsedInRegularObj = true; }

 private:
   ArchiveFile *File;
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -229,8 +229,10 @@
   Obj->parse(DummyGroups);
   for (SymbolBody *Body : Obj->getNonLocalSymbols()) {
     Symbol *Sym = insert(Body);
-    if (!Sym->Body->isUndefined() && Body->isUndefined())
+    if (!Sym->Body->isUndefined() && Body->isUndefined()) {
+      Sym->Body->setUsedInRegularObj();
       continue;
+    }
     Sym->Body = Body;
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18357.51294.patch
Type: text/x-patch
Size: 1150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160322/cc0192e4/attachment.bin>


More information about the llvm-commits mailing list