[ELF] Refine isExported/isPreemptible condition
[llvm-project.git] / lld / test / ELF / export-dynamic-symbol.s
blob66050555e0c3dd75dad3da2e9b9573d4145e4aa2
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: rm -rf %t && split-file %s %t && cd %t
14 # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o %t.o
16 ## For an executable, --export-dynamic-symbol exports a symbol if it is non-local and defined.
17 # RUN: ld.lld -pie --export-dynamic-symbol foo --export-dynamic-symbol qux %t.o -o out
18 # RUN: llvm-nm -D -p out | FileCheck %s
19 # RUN: echo '{ foo; };' > %t1.list
20 # RUN: echo '{ foo; qux; };' > %t2.list
21 # RUN: ld.lld -pie --export-dynamic-symbol-list=%t2.list %t.o -o out
22 # RUN: llvm-nm -D -p out | FileCheck %s
24 ## --export-dynamic exports all non-local defined symbols.
25 ## --export-dynamic-symbol is shadowed.
26 # RUN: ld.lld -pie --export-dynamic --export-dynamic-symbol foo %t.o -o %t.start
27 # RUN: llvm-nm -D -p %t.start | FileCheck --check-prefixes=CHECK,START %s
29 # CHECK-NOT: .
30 # START: T _start
31 # CHECK: T foo
32 # CHECK: T qux
33 # CHECK-NOT: .
35 ## --export-dynamic-symbol does not imply -u: %t1.a(%t1.o) is not fetched.
36 ## This is compatible with GNU ld since binutils 2.35 onwards.
37 # RUN: echo '.globl foo, bar; foo: bar:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
38 # RUN: rm -f %t1.a && llvm-ar rc %t1.a %t1.o
39 # RUN: ld.lld --export-dynamic-symbol bar %t1.a %t.o -o %t.nofetch
40 # RUN: llvm-nm %t.nofetch | FileCheck /dev/null --implicit-check-not=bar
42 ## For -shared, if no option expresses a symbolic intention, --export-dynamic-symbol is a no-op.
43 # RUN: ld.lld -shared --export-dynamic-symbol foo %t.o -o %t.noop
44 # RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
45 # RUN: ld.lld -shared --export-dynamic-symbol-list %t2.list %t.o -o %t.noop
46 # RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
48 ## --export-dynamic-symbol can make a symbol preemptible even if it would be otherwise
49 ## non-preemptible (due to -Bsymbolic, -Bsymbolic-functions or --dynamic-list).
50 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol nomatch %t.o -o %t.nopreempt
51 # RUN: llvm-objdump -d %t.nopreempt | FileCheck --check-prefix=NOPLT %s
52 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol foo %t.o -o %t.preempt
53 # RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
54 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol-list %t1.list %t.o -o %t.preempt
55 # RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
57 ## Hidden symbols cannot be exported by --export-dynamic-symbol family options.
58 # RUN: llvm-mc -filetype=obj -triple=x86_64 hidden.s -o hidden.o
59 # RUN: ld.lld -pie %t.o hidden.o --dynamic-list hidden.list -o out.hidden
60 # RUN: llvm-readelf -s out.hidden | FileCheck %s --check-prefix=HIDDEN
62 # HIDDEN: '.dynsym' contains 2 entries:
63 # HIDDEN: NOTYPE GLOBAL DEFAULT [[#]] _end
64 # HIDDEN: '.symtab' contains 6 entries:
65 # HIDDEN: FUNC LOCAL HIDDEN [[#]] foo
66 # HIDDEN-NEXT: NOTYPE LOCAL HIDDEN [[#]] _DYNAMIC
67 # HIDDEN-NEXT: NOTYPE GLOBAL DEFAULT [[#]] _start
68 # HIDDEN-NEXT: FUNC GLOBAL DEFAULT [[#]] qux
69 # HIDDEN-NEXT: NOTYPE GLOBAL DEFAULT [[#]] _end
71 ## 'nomatch' does not match any symbol. Don't warn.
72 # RUN: ld.lld --fatal-warnings -shared -Bsymbolic-functions --export-dynamic-symbol nomatch %t.o -o %t.nopreempt2
73 # RUN: llvm-objdump -d %t.nopreempt2 | FileCheck --check-prefix=NOPLT %s
74 # RUN: ld.lld -shared -Bsymbolic-functions --export-dynamic-symbol foo %t.o -o %t.preempt2
75 # RUN: llvm-objdump -d %t.preempt2 | FileCheck --check-prefix=PLT1 %s
77 # RUN: echo '{};' > %t.list
78 # RUN: ld.lld -shared --dynamic-list %t.list --export-dynamic-symbol foo %t.o -o %t.preempt3
79 # RUN: llvm-objdump -d %t.preempt3 | FileCheck --check-prefix=PLT1 %s
81 ## The option value is a glob.
82 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o - | \
83 # RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
84 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol '[f]o[o]' %t.o -o - | \
85 # RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
86 # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f?o' %t.o -o - | \
87 # RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
89 # PLT1: <foo@plt>
90 # PLT1: <qux>
92 # PLT2: <foo@plt>
93 # PLT2: <qux@plt>
95 # NOPLT-NOT: <foo@plt>
96 # NOPLT-NOT: <qux@plt>
98 #--- a.s
99 .global _start, foo, qux
100 .type foo, @function
101 .type qux, @function
102 _start:
103 call foo
104 call qux
105 foo:
106 qux:
108 #--- hidden.s
109 .hidden foo
111 .data
112 .quad _DYNAMIC
113 .quad _end
115 #--- hidden.list
116 {foo;_end;_DYNAMIC;};