2018-04-27 01:44:43 +08:00
|
|
|
# RUN: yaml2obj %s > %t
|
[llvm-objcopy] Don't apply --localize flags to common symbols
Summary:
--localize-symbol and --localize-hidden will currently localize common symbols. GNU objcopy will not localize these symbols even when explicitly requested, which seems reasonable; common symbols should always be global so they can be merged during linking.
See PR39461
Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola
Reviewed By: jakehehrlich, jhenderson, alexshap, MaskRay
Subscribers: emaste, arichardson, alexshap, MaskRay, llvm-commits
Differential Revision: https://reviews.llvm.org/D53782
llvm-svn: 345856
2018-11-02 01:26:36 +08:00
|
|
|
# RUN: llvm-objcopy \
|
|
|
|
# RUN: --localize-symbol Global \
|
[llvm-objcopy] Skip --localize-symbol for undefined symbols
Summary:
Include the symbol being defined in the list of requirements for using --localize-symbol.
This is used, for example, when someone is depending on two different projects that have the same (or close enough) method defined in each library, and using "-L sym" for a conflicting symbol in one of the libraries so that the definition from the other one is used. However, the library may have internal references to the symbol, which cause program crashes when those are used, i.e.:
```
$ cat foo.c
int foo() { return 5; }
$ cat bar.c
int foo();
int bar() { return 2 * foo(); }
$ cat foo2.c
int foo() { /* Safer implementation */ return 42; }
$ cat main.c
int bar();
int main() {
__builtin_printf("bar = %d\n", bar());
return 0;
}
$ ar rcs libfoo.a foo.o bar.o
$ ar rcs libfoo2.a foo2.o
# Picks the wrong foo() impl
$ clang main.o -lfoo -lfoo2 -L. -o main
# Picks the right foo() impl
$ objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main
# Links somehow, but crashes at runtime
$ llvm-objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main
```
Reviewers: jhenderson, alexshap, jakehehrlich, espindola
Subscribers: emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57417
llvm-svn: 352767
2019-02-01 00:45:16 +08:00
|
|
|
# RUN: -L GlobalUndef \
|
[llvm-objcopy] Don't apply --localize flags to common symbols
Summary:
--localize-symbol and --localize-hidden will currently localize common symbols. GNU objcopy will not localize these symbols even when explicitly requested, which seems reasonable; common symbols should always be global so they can be merged during linking.
See PR39461
Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola
Reviewed By: jakehehrlich, jhenderson, alexshap, MaskRay
Subscribers: emaste, arichardson, alexshap, MaskRay, llvm-commits
Differential Revision: https://reviews.llvm.org/D53782
llvm-svn: 345856
2018-11-02 01:26:36 +08:00
|
|
|
# RUN: -L Local \
|
|
|
|
# RUN: -L Weak \
|
|
|
|
# RUN: -L GlobalCommon \
|
|
|
|
# RUN: %t %t2
|
2019-01-12 02:06:31 +08:00
|
|
|
# RUN: llvm-readobj --symbols %t2 | FileCheck %s
|
2019-02-06 21:45:22 +08:00
|
|
|
# RUN: llvm-objcopy --regex --localize-symbol='.*' %t %t3
|
2019-02-06 19:00:07 +08:00
|
|
|
# RUN: cmp %t2 %t3
|
2019-02-08 22:37:54 +08:00
|
|
|
# RUN: echo " Global # comment " > %t-list.txt
|
|
|
|
# RUN: echo "GlobalUndef" >> %t-list.txt
|
|
|
|
# RUN: echo "Local" >> %t-list.txt
|
|
|
|
# RUN: echo "Weak" >> %t-list.txt
|
|
|
|
# RUN: echo "GlobalCommon" >> %t-list.txt
|
|
|
|
# RUN: echo " # comment " >> %t-list.txt
|
|
|
|
# RUN: llvm-objcopy --localize-symbols %t-list.txt %t %t4
|
|
|
|
# RUN: cmp %t2 %t4
|
|
|
|
# RUN: echo " .*al.* # Global + Local + GlobalCommon " > %t-list2.txt
|
|
|
|
# RUN: echo "Weak" >> %t-list2.txt
|
|
|
|
# RUN: llvm-objcopy --regex --localize-symbols %t-list2.txt %t %t5
|
|
|
|
# RUN: cmp %t2 %t5
|
2018-04-27 01:44:43 +08:00
|
|
|
|
|
|
|
!ELF
|
|
|
|
FileHeader:
|
|
|
|
Class: ELFCLASS64
|
|
|
|
Data: ELFDATA2LSB
|
|
|
|
Type: ET_REL
|
|
|
|
Machine: EM_X86_64
|
|
|
|
Sections:
|
|
|
|
- Name: .text
|
|
|
|
Type: SHT_PROGBITS
|
|
|
|
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
|
|
|
Address: 0x1000
|
|
|
|
AddressAlign: 0x0000000000000010
|
|
|
|
Size: 64
|
|
|
|
- Name: .data
|
|
|
|
Type: SHT_PROGBITS
|
|
|
|
Flags: [ SHF_ALLOC ]
|
|
|
|
Address: 0x2000
|
|
|
|
AddressAlign: 0x0000000000000010
|
|
|
|
Content: "0000000000000000"
|
|
|
|
Symbols:
|
2019-04-03 22:53:42 +08:00
|
|
|
- Name: Local
|
|
|
|
Type: STT_FUNC
|
|
|
|
Section: .text
|
|
|
|
Value: 0x1000
|
|
|
|
Size: 8
|
|
|
|
- Name: Global
|
|
|
|
Type: STT_FUNC
|
|
|
|
Size: 8
|
|
|
|
Section: .text
|
|
|
|
Value: 0x1010
|
|
|
|
Binding: STB_GLOBAL
|
|
|
|
- Name: GlobalUndef
|
|
|
|
Type: STT_FUNC
|
|
|
|
Binding: STB_GLOBAL
|
|
|
|
- Name: GlobalCommon
|
|
|
|
Type: STT_OBJECT
|
|
|
|
Index: SHN_COMMON
|
|
|
|
Value: 0x2006
|
|
|
|
Size: 2
|
|
|
|
Binding: STB_GLOBAL
|
|
|
|
- Name: Weak
|
|
|
|
Type: STT_FUNC
|
|
|
|
Size: 8
|
|
|
|
Section: .text
|
|
|
|
Value: 0x1008
|
|
|
|
Binding: STB_WEAK
|
2018-04-27 01:44:43 +08:00
|
|
|
|
|
|
|
#CHECK: Symbols [
|
|
|
|
#CHECK-NEXT: Symbol {
|
|
|
|
#CHECK-NEXT: Name:
|
|
|
|
#CHECK-NEXT: Value: 0x0
|
|
|
|
#CHECK-NEXT: Size: 0
|
|
|
|
#CHECK-NEXT: Binding: Local
|
|
|
|
#CHECK-NEXT: Type: None
|
|
|
|
#CHECK-NEXT: Other: 0
|
|
|
|
#CHECK-NEXT: Section: Undefined
|
|
|
|
#CHECK-NEXT: }
|
|
|
|
#CHECK-NEXT: Symbol {
|
|
|
|
#CHECK-NEXT: Name: Local
|
|
|
|
#CHECK-NEXT: Value: 0x1000
|
|
|
|
#CHECK-NEXT: Size: 8
|
|
|
|
#CHECK-NEXT: Binding: Local
|
|
|
|
#CHECK-NEXT: Type: Function
|
|
|
|
#CHECK-NEXT: Other: 0
|
|
|
|
#CHECK-NEXT: Section: .text
|
|
|
|
#CHECK-NEXT: }
|
|
|
|
#CHECK-NEXT: Symbol {
|
|
|
|
#CHECK-NEXT: Name: Global
|
|
|
|
#CHECK-NEXT: Value: 0x1010
|
|
|
|
#CHECK-NEXT: Size: 8
|
|
|
|
#CHECK-NEXT: Binding: Local
|
|
|
|
#CHECK-NEXT: Type: Function
|
|
|
|
#CHECK-NEXT: Other: 0
|
|
|
|
#CHECK-NEXT: Section: .text
|
|
|
|
#CHECK-NEXT: }
|
|
|
|
#CHECK-NEXT: Symbol {
|
|
|
|
#CHECK-NEXT: Name: Weak
|
|
|
|
#CHECK-NEXT: Value: 0x1008
|
|
|
|
#CHECK-NEXT: Size: 8
|
|
|
|
#CHECK-NEXT: Binding: Local
|
|
|
|
#CHECK-NEXT: Type: Function
|
|
|
|
#CHECK-NEXT: Other: 0
|
|
|
|
#CHECK-NEXT: Section: .text
|
|
|
|
#CHECK-NEXT: }
|
[llvm-objcopy] Don't apply --localize flags to common symbols
Summary:
--localize-symbol and --localize-hidden will currently localize common symbols. GNU objcopy will not localize these symbols even when explicitly requested, which seems reasonable; common symbols should always be global so they can be merged during linking.
See PR39461
Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola
Reviewed By: jakehehrlich, jhenderson, alexshap, MaskRay
Subscribers: emaste, arichardson, alexshap, MaskRay, llvm-commits
Differential Revision: https://reviews.llvm.org/D53782
llvm-svn: 345856
2018-11-02 01:26:36 +08:00
|
|
|
#CHECK-NEXT: Symbol {
|
[llvm-objcopy] Skip --localize-symbol for undefined symbols
Summary:
Include the symbol being defined in the list of requirements for using --localize-symbol.
This is used, for example, when someone is depending on two different projects that have the same (or close enough) method defined in each library, and using "-L sym" for a conflicting symbol in one of the libraries so that the definition from the other one is used. However, the library may have internal references to the symbol, which cause program crashes when those are used, i.e.:
```
$ cat foo.c
int foo() { return 5; }
$ cat bar.c
int foo();
int bar() { return 2 * foo(); }
$ cat foo2.c
int foo() { /* Safer implementation */ return 42; }
$ cat main.c
int bar();
int main() {
__builtin_printf("bar = %d\n", bar());
return 0;
}
$ ar rcs libfoo.a foo.o bar.o
$ ar rcs libfoo2.a foo2.o
# Picks the wrong foo() impl
$ clang main.o -lfoo -lfoo2 -L. -o main
# Picks the right foo() impl
$ objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main
# Links somehow, but crashes at runtime
$ llvm-objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main
```
Reviewers: jhenderson, alexshap, jakehehrlich, espindola
Subscribers: emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57417
llvm-svn: 352767
2019-02-01 00:45:16 +08:00
|
|
|
#CHECK-NEXT: Name: GlobalUndef
|
|
|
|
#CHECK-NEXT: Value:
|
|
|
|
#CHECK-NEXT: Size:
|
|
|
|
#CHECK-NEXT: Binding: Global
|
|
|
|
#CHECK-NEXT: Type: Function
|
|
|
|
#CHECK-NEXT: Other:
|
|
|
|
#CHECK-NEXT: Section: Undefined
|
|
|
|
#CHECK-NEXT: }
|
|
|
|
#CHECK-NEXT: Symbol {
|
[llvm-objcopy] Don't apply --localize flags to common symbols
Summary:
--localize-symbol and --localize-hidden will currently localize common symbols. GNU objcopy will not localize these symbols even when explicitly requested, which seems reasonable; common symbols should always be global so they can be merged during linking.
See PR39461
Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola
Reviewed By: jakehehrlich, jhenderson, alexshap, MaskRay
Subscribers: emaste, arichardson, alexshap, MaskRay, llvm-commits
Differential Revision: https://reviews.llvm.org/D53782
llvm-svn: 345856
2018-11-02 01:26:36 +08:00
|
|
|
#CHECK-NEXT: Name: GlobalCommon
|
|
|
|
#CHECK-NEXT: Value: 0x2006
|
|
|
|
#CHECK-NEXT: Size: 2
|
|
|
|
#CHECK-NEXT: Binding: Global
|
|
|
|
#CHECK-NEXT: Type: Object
|
|
|
|
#CHECK-NEXT: Other: 0
|
|
|
|
#CHECK-NEXT: Section: Common (0xF
|
|
|
|
#CHECK-NEXT: }
|
2018-04-27 01:44:43 +08:00
|
|
|
#CHECK-NEXT:]
|