2018-02-10 01:39:06 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
|
2020-06-02 02:27:53 +08:00
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
|
2018-02-15 02:38:33 +08:00
|
|
|
|
2020-06-02 02:27:53 +08:00
|
|
|
## For an executable, --export-dynamic-symbol exports a symbol if it is non-local and defined.
|
2021-08-04 00:01:03 +08:00
|
|
|
# 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
|
2020-06-02 02:27:53 +08:00
|
|
|
# RUN: llvm-nm -D -p %t | FileCheck %s
|
2018-02-10 01:39:06 +08:00
|
|
|
|
2020-06-02 02:27:53 +08:00
|
|
|
## --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
|
2018-02-15 02:38:33 +08:00
|
|
|
|
2020-06-02 02:27:53 +08:00
|
|
|
# CHECK-NOT: .
|
|
|
|
# START: T _start
|
|
|
|
# CHECK: T foo
|
2021-08-04 00:01:03 +08:00
|
|
|
# CHECK: T qux
|
2020-06-02 02:27:53 +08:00
|
|
|
# CHECK-NOT: .
|
2018-02-10 01:39:06 +08:00
|
|
|
|
2020-06-02 02:27:53 +08:00
|
|
|
## --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
|
|
|
|
|
2021-08-04 00:01:03 +08:00
|
|
|
## 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
|
|
|
|
|
2020-06-02 02:27:53 +08:00
|
|
|
## --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
|
2021-08-04 00:01:03 +08:00
|
|
|
# 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
|
2020-06-02 02:27:53 +08:00
|
|
|
|
|
|
|
## '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
|
2021-08-04 00:01:03 +08:00
|
|
|
# RUN: llvm-objdump -d %t.preempt2 | FileCheck --check-prefix=PLT1 %s
|
2020-06-02 02:27:53 +08:00
|
|
|
|
|
|
|
# RUN: echo '{};' > %t.list
|
|
|
|
# RUN: ld.lld -shared --dynamic-list %t.list --export-dynamic-symbol foo %t.o -o %t.preempt3
|
2021-08-04 00:01:03 +08:00
|
|
|
# RUN: llvm-objdump -d %t.preempt3 | FileCheck --check-prefix=PLT1 %s
|
2020-06-02 02:27:53 +08:00
|
|
|
|
|
|
|
## The option value is a glob.
|
2020-06-18 08:11:38 +08:00
|
|
|
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o - | \
|
2021-08-04 00:01:03 +08:00
|
|
|
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
|
2020-06-18 08:11:38 +08:00
|
|
|
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol '[f]o[o]' %t.o -o - | \
|
2021-08-04 00:01:03 +08:00
|
|
|
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
|
2020-06-18 08:11:38 +08:00
|
|
|
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f?o' %t.o -o - | \
|
2021-08-04 00:01:03 +08:00
|
|
|
# RUN: llvm-objdump -d - | FileCheck --check-prefix=PLT1 %s
|
|
|
|
|
|
|
|
# PLT1: <foo@plt>
|
|
|
|
# PLT1: <qux>
|
|
|
|
|
|
|
|
# PLT2: <foo@plt>
|
|
|
|
# PLT2: <qux@plt>
|
2020-06-02 02:27:53 +08:00
|
|
|
|
|
|
|
# NOPLT-NOT: <foo@plt>
|
2021-08-04 00:01:03 +08:00
|
|
|
# NOPLT-NOT: <qux@plt>
|
2020-06-02 02:27:53 +08:00
|
|
|
|
2021-08-04 00:01:03 +08:00
|
|
|
.global _start, foo, qux
|
2020-06-02 02:27:53 +08:00
|
|
|
.type foo, @function
|
2021-08-04 00:01:03 +08:00
|
|
|
.type qux, @function
|
2018-02-10 01:39:06 +08:00
|
|
|
_start:
|
2020-06-02 02:27:53 +08:00
|
|
|
call foo
|
2021-08-04 00:01:03 +08:00
|
|
|
call qux
|
2020-06-02 02:27:53 +08:00
|
|
|
foo:
|
2021-08-04 00:01:03 +08:00
|
|
|
qux:
|