From 90b395e93acf4cf860bbedc19d39d88278c892be Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 9 Feb 2018 17:39:06 +0000 Subject: [PATCH] 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 llvm-svn: 324752 --- lld/ELF/Driver.cpp | 4 +++- lld/test/ELF/dynamic-list-archive.s | 17 +++++++++++++++++ lld/test/ELF/export-dynamic-symbol.s | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/dynamic-list-archive.s create mode 100644 lld/test/ELF/export-dynamic-symbol.s diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 94e5397..25740a6 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -790,9 +790,11 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { if (Optional 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)) diff --git a/lld/test/ELF/dynamic-list-archive.s b/lld/test/ELF/dynamic-list-archive.s new file mode 100644 index 0000000..5879bf1 --- /dev/null +++ b/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 diff --git a/lld/test/ELF/export-dynamic-symbol.s b/lld/test/ELF/export-dynamic-symbol.s new file mode 100644 index 0000000..75d0459 --- /dev/null +++ b/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 -- 2.7.4