Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit dc7a9f3

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@324752 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3ea2130 commit dc7a9f3

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

ELF/Driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,11 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
790790
if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
791791
readDynamicList(*Buffer);
792792

793-
for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol))
793+
for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol)) {
794794
Config->DynamicList.push_back(
795795
{Arg->getValue(), /*IsExternCpp*/ false, /*HasWildcard*/ false});
796+
Config->Undefined.push_back(Arg->getValue());
797+
}
796798
}
797799

798800
for (auto *Arg : Args.filtered(OPT_version_script))

test/ELF/dynamic-list-archive.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# REQUIRES: x86
2+
3+
# RUN: rm -f %t.a
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o
5+
# RUN: llvm-ar rcs %t.a %t1.o
6+
7+
# RUN: echo "{ foo; };" > %t.list
8+
9+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o
10+
# RUN: ld.lld -shared -o %t.so --dynamic-list %t.list %t.a %t2.o
11+
12+
# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s
13+
# CHECK-NOT: foo
14+
15+
.global _start
16+
_start:
17+
nop

test/ELF/export-dynamic-symbol.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# REQUIRES: x86
2+
3+
# RUN: rm -f %t.a
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o
5+
# RUN: llvm-ar rcs %t.a %t1.o
6+
7+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o
8+
# RUN: ld.lld -shared -o %t.so --export-dynamic-symbol foo %t.a %t2.o
9+
10+
# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s
11+
# CHECK: foo
12+
13+
.global _start
14+
_start:
15+
nop

0 commit comments

Comments
 (0)