[ELF] Make SyntheticSection parameter order match InputSection
[llvm-project.git] / lld / test / ELF / export-dynamic-symbol.s
blob3a00f07a420cf0a14d9034aed92b66af495d5ab9
1 # REQUIRES: x86
3 # FIXME: this should be supported on Windows as well. There is a strange issue
4 # happening with command line processing though. The command line argument
5 # --export-dynamic-symbol 'f*'
6 # does not have the single quotes stripped on some Windows targets (but not
7 # all). This causes the glob matching to fail, which means the test fails on
8 # some Windows bots and passes on others. However, there's no clear indication
9 # as to what's changed to cause this behavior. Marking the test as unsupported
10 # so that we have time to investigate the issue without losing postcommit CI.
11 # UNSUPPORTED: system-windows
13 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
15 ## For an executable, --export-dynamic-symbol exports a symbol if it is non-local and defined.
16 # RUN: ld.lld -pie --export-dynamic-symbol foo --export-dynamic-symbol qux %t.o -o %t
17 # RUN: llvm-nm -D -p %t | FileCheck %s
18 # RUN: echo '{ foo; };' > %t1.list
19 # RUN: echo '{ foo; qux; };' > %t2.list
20 # RUN: ld.lld -pie --export-dynamic-symbol-list=%t2.list %t.o -o %t
21 # RUN: llvm-nm -D -p %t | FileCheck %s
23 ## --export-dynamic exports all non-local defined symbols.
24 ## --export-dynamic-symbol is shadowed.
25 # RUN: ld.lld -pie --export-dynamic --export-dynamic-symbol foo %t.o -o %t.start
26 # RUN: llvm-nm -D -p %t.start | FileCheck --check-prefixes=CHECK,START %s
28 # CHECK-NOT: .
29 # START: T _start
30 # CHECK: T foo
31 # CHECK: T qux
32 # CHECK-NOT: .
34 ## --export-dynamic-symbol does not imply -u: %t1.a(%t1.o) is not fetched.
35 ## This is compatible with GNU ld since binutils 2.35 onwards.
36 # RUN: echo '.globl foo, bar; foo: bar:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
37 # RUN: rm -f %t1.a && llvm-ar rc %t1.a %t1.o
38 # RUN: ld.lld --export-dynamic-symbol bar %t1.a %t.o -o %t.nofetch
39 # RUN: llvm-nm %t.nofetch | FileCheck /dev/null --implicit-check-not=bar
41 ## For -shared, if no option expresses a symbolic intention, --export-dynamic-symbol is a no-op.
42 # RUN: ld.lld -shared --export-dynamic-symbol foo %t.o -o %t.noop
43 # RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
44 # RUN: ld.lld -shared --export-dynamic-symbol-list %t2.list %t.o -o %t.noop
45 # RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
47 ## --export-dynamic-symbol can make a symbol preemptible even if it would be otherwise
48 ## non-preemptible (due to -Bsymbolic, -Bsymbolic-functions or --dynamic-list).
49 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol nomatch %t.o -o %t.nopreempt
50 # RUN: llvm-objdump -d %t.nopreempt | FileCheck --check-prefix=NOPLT %s
51 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol foo %t.o -o %t.preempt
52 # RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
53 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol-list %t1.list %t.o -o %t.preempt
54 # RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
56 ## 'nomatch' does not match any symbol. Don't warn.
57 # RUN: ld.lld --fatal-warnings -shared -Bsymbolic-functions --export-dynamic-symbol nomatch %t.o -o %t.nopreempt2
58 # RUN: llvm-objdump -d %t.nopreempt2 | FileCheck --check-prefix=NOPLT %s
59 # RUN: ld.lld -shared -Bsymbolic-functions --export-dynamic-symbol foo %t.o -o %t.preempt2
60 # RUN: llvm-objdump -d %t.preempt2 | FileCheck --check-prefix=PLT1 %s
62 # RUN: echo '{};' > %t.list
63 # RUN: ld.lld -shared --dynamic-list %t.list --export-dynamic-symbol foo %t.o -o %t.preempt3
64 # RUN: llvm-objdump -d %t.preempt3 | FileCheck --check-prefix=PLT1 %s
66 ## The option value is a glob.
67 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o - | \
68 # RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
69 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol '[f]o[o]' %t.o -o - | \
70 # RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
71 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f?o' %t.o -o - | \
72 # RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
74 # PLT1: <foo@plt>
75 # PLT1: <qux>
77 # PLT2: <foo@plt>
78 # PLT2: <qux@plt>
80 # NOPLT-NOT: <foo@plt>
81 # NOPLT-NOT: <qux@plt>
83 .global _start, foo, qux
84 .type foo, @function
85 .type qux, @function
86 _start:
87 call foo
88 call qux
89 foo:
90 qux: