[lld] r324752 - Make --export-dynamic-symbol to pull out object files from archives.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 9 09:39:06 PST 2018


Author: ruiu
Date: Fri Feb  9 09:39:06 2018
New Revision: 324752

URL: http://llvm.org/viewvc/llvm-project?rev=324752&view=rev
Log:
Make --export-dynamic-symbol to pull out object files from archives.

This is for compatiblity with GNU gold. GNU gold tries to resolve
symbols specified by --export-dynamic-symbol. So, if a symbol specified
by --export-dynamic-symbol is in an archive file, lld's result is
currently different from gold's.

Interestingly, that behavior is different for --dynamic-list.
I added a new test to ensure that.

Differential Revision: https://reviews.llvm.org/D43103

Added:
    lld/trunk/test/ELF/dynamic-list-archive.s
    lld/trunk/test/ELF/export-dynamic-symbol.s
Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=324752&r1=324751&r2=324752&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Feb  9 09:39:06 2018
@@ -790,9 +790,11 @@ void LinkerDriver::readConfigs(opt::Inpu
       if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
         readDynamicList(*Buffer);
 
-    for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol))
+    for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol)) {
       Config->DynamicList.push_back(
           {Arg->getValue(), /*IsExternCpp*/ false, /*HasWildcard*/ false});
+      Config->Undefined.push_back(Arg->getValue());
+    }
   }
 
   for (auto *Arg : Args.filtered(OPT_version_script))

Added: lld/trunk/test/ELF/dynamic-list-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-list-archive.s?rev=324752&view=auto
==============================================================================
--- lld/trunk/test/ELF/dynamic-list-archive.s (added)
+++ lld/trunk/test/ELF/dynamic-list-archive.s Fri Feb  9 09:39:06 2018
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+
+# RUN: rm -f %t.a
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o
+# RUN: llvm-ar rcs %t.a %t1.o
+
+# RUN: echo "{ foo; };" > %t.list
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o
+# RUN: ld.lld -shared -o %t.so --dynamic-list %t.list %t.a %t2.o
+
+# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s
+# CHECK-NOT: foo
+
+.global _start
+_start:
+  nop

Added: lld/trunk/test/ELF/export-dynamic-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/export-dynamic-symbol.s?rev=324752&view=auto
==============================================================================
--- lld/trunk/test/ELF/export-dynamic-symbol.s (added)
+++ lld/trunk/test/ELF/export-dynamic-symbol.s Fri Feb  9 09:39:06 2018
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+
+# RUN: rm -f %t.a
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o
+# RUN: llvm-ar rcs %t.a %t1.o
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o
+# RUN: ld.lld -shared -o %t.so --export-dynamic-symbol foo %t.a %t2.o
+
+# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s
+# CHECK: foo
+
+.global _start
+_start:
+  nop




More information about the llvm-commits mailing list