Skip to content

Commit 44361e5

Browse files
committed
[ELF] Add --export-dynamic-symbol-list
This is available in GNU ld 2.35 and can be seen as a shortcut for multiple --export-dynamic-symbol, or a --dynamic-list variant without the symbolic intention. In the long term, this option probably should be preferred over --dynamic-list. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D107317
1 parent ccf1038 commit 44361e5

File tree

5 files changed

+50
-20
lines changed

5 files changed

+50
-20
lines changed

lld/ELF/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,8 @@ static void readConfigs(opt::InputArgList &args) {
13791379
// symbols not specified by --dynamic-list are non-preemptible.
13801380
config->symbolic =
13811381
config->bsymbolic == BsymbolicKind::All || args.hasArg(OPT_dynamic_list);
1382-
for (auto *arg : args.filtered(OPT_dynamic_list))
1382+
for (auto *arg :
1383+
args.filtered(OPT_dynamic_list, OPT_export_dynamic_symbol_list))
13831384
if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue()))
13841385
readDynamicList(*buffer);
13851386

lld/ELF/Options.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ def discard_none: F<"discard-none">,
156156
defm dynamic_linker: Eq<"dynamic-linker", "Which dynamic linker to use">;
157157

158158
defm dynamic_list : Eq<"dynamic-list",
159-
"Read a list of dynamic symbols. (executable) Put matched non-local defined"
160-
"symbols to the dynamic symbol table. (shared object) References to matched"
161-
"non-local STV_DEFAULT symbols shouldn't be bound to definitions within the "
162-
"shared object. Implies -Bsymbolic but does not set DF_SYMBOLIC">,
159+
"Similar to --export-dynamic-symbol-list. When creating a shared object, "
160+
"this additionally implies -Bsymbolic but does not set DF_SYMBOLIC">,
163161
MetaVarName<"<file>">;
164162

165163
def eb: F<"EB">, HelpText<"Select the big-endian format in OUTPUT_FORMAT">;
@@ -209,6 +207,10 @@ defm export_dynamic_symbol : EEq<"export-dynamic-symbol",
209207
"Does not imply -Bsymbolic.">,
210208
MetaVarName<"glob">;
211209

210+
defm export_dynamic_symbol_list : EEq<"export-dynamic-symbol-list",
211+
"Read a list of dynamic symbol patterns. Apply --export-dynamic-symbol on each pattern">,
212+
MetaVarName<"file">;
213+
212214
defm fatal_warnings: B<"fatal-warnings",
213215
"Treat warnings as errors",
214216
"Do not treat warnings as errors (default)">;

lld/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Non-comprehensive list of changes in this release
2424
ELF Improvements
2525
----------------
2626

27-
* ``-Bsymbolic-non-weak-functions`` has been added as a ``STB_GLOBAL`` subset of ``-Bsymbolic-functions``.
28-
(`D102570 <https://reviews.llvm.org/D102570>`_)
27+
* ``--export-dynamic-symbol-list`` has been added.
28+
(`D107317 <https://reviews.llvm.org/D107317>`_)
2929

3030
Breaking changes
3131
----------------

lld/docs/ld.lld.1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,9 @@ Specify the dynamic linker to be used for a dynamically linked executable.
167167
This is recorded in an ELF segment of type
168168
.Dv PT_INTERP .
169169
.It Fl -dynamic-list Ns = Ns Ar file
170-
Read a list of dynamic symbols from
171-
.Ar file .
172-
(executable) Put matched non-local defined symbols to the dynamic symbol table.
173-
(shared object) References to matched non-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object. Implies
170+
Similar to
171+
.Cm --export-dynamic-symbol-list .
172+
When creating a shared object, implies
174173
.Cm -Bsymbolic
175174
but does not set DF_SYMBOLIC
176175
.It Fl -EB
@@ -225,6 +224,12 @@ Put symbols in the dynamic symbol table.
225224
.Cm -Bsymbolic-functions
226225
or
227226
.Cm --dynamic-list
227+
.It Fl -export-dynamic-symbol-list Ns = Ns Ar file
228+
Read a list of dynamic symbol patterns from
229+
.Ar file .
230+
Apply
231+
.Cm --export-dynamic-symbol
232+
on each pattern.
228233
.It Fl -fatal-warnings
229234
Treat warnings as errors.
230235
.It Fl -filter Ns = Ns Ar value , Fl F Ar value

lld/test/ELF/export-dynamic-symbol.s

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
44

55
## For an executable, --export-dynamic-symbol exports a symbol if it is non-local and defined.
6-
# RUN: ld.lld -pie --export-dynamic-symbol foo %t.o -o %t
6+
# RUN: ld.lld -pie --export-dynamic-symbol foo --export-dynamic-symbol qux %t.o -o %t
7+
# RUN: llvm-nm -D -p %t | FileCheck %s
8+
# RUN: echo '{ foo; };' > %t1.list
9+
# RUN: echo '{ foo; qux; };' > %t2.list
10+
# RUN: ld.lld -pie --export-dynamic-symbol-list=%t2.list %t.o -o %t
711
# RUN: llvm-nm -D -p %t | FileCheck %s
812

913
## --export-dynamic exports all non-local defined symbols.
@@ -14,6 +18,7 @@
1418
# CHECK-NOT: .
1519
# START: T _start
1620
# CHECK: T foo
21+
# CHECK: T qux
1722
# CHECK-NOT: .
1823

1924
## --export-dynamic-symbol does not imply -u: %t1.a(%t1.o) is not fetched.
@@ -23,36 +28,53 @@
2328
# RUN: ld.lld --export-dynamic-symbol bar %t1.a %t.o -o %t.nofetch
2429
# RUN: llvm-nm %t.nofetch | FileCheck /dev/null --implicit-check-not=bar
2530

31+
## For -shared, if no option expresses a symbolic intention, --export-dynamic-symbol is a no-op.
32+
# RUN: ld.lld -shared --export-dynamic-symbol foo %t.o -o %t.noop
33+
# RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
34+
# RUN: ld.lld -shared --export-dynamic-symbol-list %t2.list %t.o -o %t.noop
35+
# RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
36+
2637
## --export-dynamic-symbol can make a symbol preemptible even if it would be otherwise
2738
## non-preemptible (due to -Bsymbolic, -Bsymbolic-functions or --dynamic-list).
2839
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol nomatch %t.o -o %t.nopreempt
2940
# RUN: llvm-objdump -d %t.nopreempt | FileCheck --check-prefix=NOPLT %s
3041
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol foo %t.o -o %t.preempt
31-
# RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT %s
42+
# RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
43+
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol-list %t1.list %t.o -o %t.preempt
44+
# RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
3245

3346
## 'nomatch' does not match any symbol. Don't warn.
3447
# RUN: ld.lld --fatal-warnings -shared -Bsymbolic-functions --export-dynamic-symbol nomatch %t.o -o %t.nopreempt2
3548
# RUN: llvm-objdump -d %t.nopreempt2 | FileCheck --check-prefix=NOPLT %s
3649
# RUN: ld.lld -shared -Bsymbolic-functions --export-dynamic-symbol foo %t.o -o %t.preempt2
37-
# RUN: llvm-objdump -d %t.preempt2 | FileCheck --check-prefix=PLT %s
50+
# RUN: llvm-objdump -d %t.preempt2 | FileCheck --check-prefix=PLT1 %s
3851

3952
# RUN: echo '{};' > %t.list
4053
# RUN: ld.lld -shared --dynamic-list %t.list --export-dynamic-symbol foo %t.o -o %t.preempt3
41-
# RUN: llvm-objdump -d %t.preempt3 | FileCheck --check-prefix=PLT %s
54+
# RUN: llvm-objdump -d %t.preempt3 | FileCheck --check-prefix=PLT1 %s
4255

4356
## The option value is a glob.
4457
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o - | \
45-
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT %s
58+
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
4659
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol '[f]o[o]' %t.o -o - | \
47-
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT %s
60+
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
4861
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f?o' %t.o -o - | \
49-
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT %s
62+
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
63+
64+
# PLT1: <foo@plt>
65+
# PLT1: <qux>
66+
67+
# PLT2: <foo@plt>
68+
# PLT2: <qux@plt>
5069

51-
# PLT: <foo@plt>
5270
# NOPLT-NOT: <foo@plt>
71+
# NOPLT-NOT: <qux@plt>
5372

54-
.global _start, foo
73+
.global _start, foo, qux
5574
.type foo, @function
75+
.type qux, @function
5676
_start:
5777
call foo
78+
call qux
5879
foo:
80+
qux:

0 commit comments

Comments
 (0)