File: export-dynamic-symbol.s

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (80 lines) | stat: -rw-r--r-- 3,537 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o

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

## --export-dynamic exports all non-local defined symbols.
## --export-dynamic-symbol is shadowed.
# RUN: ld.lld -pie --export-dynamic --export-dynamic-symbol foo %t.o -o %t.start
# RUN: llvm-nm -D -p %t.start | FileCheck --check-prefixes=CHECK,START %s

# CHECK-NOT:  .
# START:      T _start
# CHECK:      T foo
# CHECK:      T qux
# CHECK-NOT:  .

## --export-dynamic-symbol does not imply -u: %t1.a(%t1.o) is not fetched.
## This is compatible with GNU ld since binutils 2.35 onwards.
# RUN: echo '.globl foo, bar; foo: bar:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
# RUN: rm -f %t1.a && llvm-ar rc %t1.a %t1.o
# RUN: ld.lld --export-dynamic-symbol bar %t1.a %t.o -o %t.nofetch
# RUN: llvm-nm %t.nofetch | FileCheck /dev/null --implicit-check-not=bar

## For -shared, if no option expresses a symbolic intention, --export-dynamic-symbol is a no-op.
# RUN: ld.lld -shared --export-dynamic-symbol foo %t.o -o %t.noop
# RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s
# RUN: ld.lld -shared --export-dynamic-symbol-list %t2.list %t.o -o %t.noop
# RUN: llvm-objdump -d %t.noop | FileCheck --check-prefix=PLT2 %s

## --export-dynamic-symbol can make a symbol preemptible even if it would be otherwise
## non-preemptible (due to -Bsymbolic, -Bsymbolic-functions or --dynamic-list).
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol nomatch %t.o -o %t.nopreempt
# RUN: llvm-objdump -d %t.nopreempt | FileCheck --check-prefix=NOPLT %s
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol foo %t.o -o %t.preempt
# RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol-list %t1.list %t.o -o %t.preempt
# RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s

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

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

## The option value is a glob.
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o - | \
# RUN:   llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol '[f]o[o]' %t.o -o - | \
# RUN:   llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f?o' %t.o -o - | \
# RUN:   llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s

# PLT1:      <foo@plt>
# PLT1:      <qux>

# PLT2:      <foo@plt>
# PLT2:      <qux@plt>

# NOPLT-NOT: <foo@plt>
# NOPLT-NOT: <qux@plt>

.global _start, foo, qux
.type foo, @function
.type qux, @function
_start:
  call foo
  call qux
foo:
qux: