Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Refine --export-dynamic-symbol semantics to be compatible GNU l…
…d 2.35 GNU ld from binutils 2.35 onwards will likely support --export-dynamic-symbol but with different semantics. https://sourceware.org/pipermail/binutils/2020-May/111302.html Differences: 1. -export-dynamic-symbol is not supported 2. --export-dynamic-symbol takes a glob argument 3. --export-dynamic-symbol can suppress binding the references to the definition within the shared object if (-Bsymbolic or -Bsymbolic-functions) 4. --export-dynamic-symbol does not imply -u I don't think the first three points can affect any user. For the fourth point, Not implying -u can lead to some archive members unfetched. Add -u foo to restore the previous behavior. Exact semantics: * -no-pie or -pie: matched non-local defined symbols will be added to the dynamic symbol table. * -shared: matched non-local STV_DEFAULT symbols will not be bound to definitions within the shared object even if they would otherwise be due to -Bsymbolic, -Bsymbolic-functions, or --dynamic-list. Reviewed By: psmith Differential Revision: https://reviews.llvm.org/D80487
- Loading branch information
Showing
9 changed files
with
92 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,54 @@ | ||
# REQUIRES: x86 | ||
|
||
# RUN: rm -f %t.a | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o | ||
# RUN: llvm-ar rcs %t.a %t1.o | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o | ||
|
||
# RUN: ld.lld -shared -o %t.so --export-dynamic-symbol foo %t.a %t2.o | ||
# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s | ||
## For an executable, --export-dynamic-symbol exports a symbol if it is non-local and defined. | ||
# RUN: ld.lld -pie --export-dynamic-symbol foo %t.o -o %t | ||
# RUN: llvm-nm -D -p %t | FileCheck %s | ||
|
||
# RUN: ld.lld -shared -o %t.so --export-dynamic --export-dynamic-symbol foo %t.a %t2.o | ||
# RUN: llvm-readelf -dyn-symbols %t.so | 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: foo | ||
# CHECK-NOT: . | ||
# START: T _start | ||
# CHECK: T foo | ||
# CHECK-NOT: . | ||
|
||
.global _start | ||
## --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 | ||
|
||
## --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=PLT %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=PLT %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=PLT %s | ||
|
||
## The option value is a glob. | ||
# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o %t.preempt4 | ||
# RUN: llvm-objdump -d %t.preempt4 | FileCheck --check-prefix=PLT %s | ||
|
||
# PLT: <foo@plt> | ||
# NOPLT-NOT: <foo@plt> | ||
|
||
.global _start, foo | ||
.type foo, @function | ||
_start: | ||
nop | ||
call foo | ||
foo: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters