[lld] r328738 - Strip @VER suffices from the LTO output.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 28 15:45:39 PDT 2018


Author: rafael
Date: Wed Mar 28 15:45:39 2018
New Revision: 328738

URL: http://llvm.org/viewvc/llvm-project?rev=328738&view=rev
Log:
Strip @VER suffices from the LTO output.

This fixes pr36623.

The problem is that we have to parse versions out of names before LTO
so that LTO can use that information.

When we get the LTO produced .o files, we replace the previous symbols
with the LTO produced ones, but they still have @ in their names.

We could just trim the name directly, but calling parseSymbolVersion
to do it is simpler.

Added:
    lld/trunk/test/ELF/lto/version-script2.ll
Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=328738&r1=328737&r2=328738&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Mar 28 15:45:39 2018
@@ -265,6 +265,10 @@ template <class ELFT> ArrayRef<Symbol *>
   return makeArrayRef(this->Symbols).slice(1, this->FirstNonLocal - 1);
 }
 
+template <class ELFT> ArrayRef<Symbol *> ObjFile<ELFT>::getGlobalSymbols() {
+  return makeArrayRef(this->Symbols).slice(this->FirstNonLocal);
+}
+
 template <class ELFT>
 void ObjFile<ELFT>::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
   // Read section and symbol tables.

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=328738&r1=328737&r2=328738&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Wed Mar 28 15:45:39 2018
@@ -165,6 +165,7 @@ public:
   static bool classof(const InputFile *F) { return F->kind() == Base::ObjKind; }
 
   ArrayRef<Symbol *> getLocalSymbols();
+  ArrayRef<Symbol *> getGlobalSymbols();
 
   ObjFile(MemoryBufferRef M, StringRef ArchiveName);
   void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=328738&r1=328737&r2=328738&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Mar 28 15:45:39 2018
@@ -130,7 +130,10 @@ template <class ELFT> void SymbolTable::
 
   for (InputFile *File : LTO->compile()) {
     DenseSet<CachedHashStringRef> DummyGroups;
-    cast<ObjFile<ELFT>>(File)->parse(DummyGroups);
+    auto *Obj = cast<ObjFile<ELFT>>(File);
+    Obj->parse(DummyGroups);
+    for (Symbol *Sym : Obj->getGlobalSymbols())
+      Sym->parseSymbolVersion();
     ObjectFiles.push_back(File);
   }
 }

Added: lld/trunk/test/ELF/lto/version-script2.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/version-script2.ll?rev=328738&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/version-script2.ll (added)
+++ lld/trunk/test/ELF/lto/version-script2.ll Wed Mar 28 15:45:39 2018
@@ -0,0 +1,15 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: echo "VER1 {};" > %t.script
+; RUN: ld.lld %t.o -o %t.so -shared --version-script %t.script
+; RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s
+
+; test that we have the correct version.
+; CHECK: Name: foo@@VER1 (
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+module asm ".global foo"
+module asm "foo:"
+module asm ".symver foo,foo@@@VER1"




More information about the llvm-commits mailing list