[PATCH] D43103: Make --export-dynamic-symbol to pull out object files from archives.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 17:27:41 PST 2018


ruiu created this revision.
ruiu added a reviewer: rafael.
Herald added a subscriber: emaste.

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.


https://reviews.llvm.org/D43103

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/dynamic-list-archive.s
  lld/test/ELF/export-dynamic-symbol.s


Index: lld/test/ELF/export-dynamic-symbol.s
===================================================================
--- /dev/null
+++ lld/test/ELF/export-dynamic-symbol.s
@@ -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
Index: lld/test/ELF/dynamic-list-archive.s
===================================================================
--- /dev/null
+++ lld/test/ELF/dynamic-list-archive.s
@@ -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
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -790,9 +790,11 @@
       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))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43103.133543.patch
Type: text/x-patch
Size: 1844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180209/ad91a3e4/attachment.bin>


More information about the llvm-commits mailing list