| 1 |
# RUN: yaml2obj %s -o %t |
| 2 |
# RUN: llvm-objcopy --remove-section=.text.bar %t %t1 |
| 3 |
# RUN: llvm-readobj --section-groups %t1 | FileCheck %s |
| 4 |
|
| 5 |
# In this test the section .text.bar is getting removed, as a result, |
| 6 |
# the indices of the sections which go after .text.bar will change, |
| 7 |
# thus the fields Link, Info and the content of .group should be updated. |
| 8 |
|
| 9 |
# CHECK: Name: .group |
| 10 |
# CHECK-NEXT: Index: 1 |
| 11 |
# CHECK-NEXT: Link: 3 |
| 12 |
# CHECK-NEXT: Info: 2 |
| 13 |
# CHECK-NEXT: Type: COMDAT (0x1) |
| 14 |
# CHECK-NEXT: Signature: foo |
| 15 |
# CHECK: .text.foo (2) |
| 16 |
|
| 17 |
--- !ELF |
| 18 |
FileHeader: |
| 19 |
Class: ELFCLASS64 |
| 20 |
Data: ELFDATA2LSB |
| 21 |
Type: ET_REL |
| 22 |
Machine: EM_X86_64 |
| 23 |
Sections: |
| 24 |
- Name: .group |
| 25 |
Type: SHT_GROUP |
| 26 |
Link: .symtab |
| 27 |
AddressAlign: 0x0000000000000004 |
| 28 |
Info: foo |
| 29 |
Members: |
| 30 |
- SectionOrType: GRP_COMDAT |
| 31 |
- SectionOrType: .text.foo |
| 32 |
- Name: .text.bar |
| 33 |
Type: SHT_PROGBITS |
| 34 |
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] |
| 35 |
AddressAlign: 0x0000000000000010 |
| 36 |
- Name: .text.foo |
| 37 |
Type: SHT_PROGBITS |
| 38 |
Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] |
| 39 |
AddressAlign: 0x0000000000000010 |
| 40 |
Symbols: |
| 41 |
- Name: .text.bar |
| 42 |
Type: STT_SECTION |
| 43 |
Section: .text.bar |
| 44 |
- Name: .text.foo |
| 45 |
Type: STT_SECTION |
| 46 |
Section: .text.foo |
| 47 |
- Name: bar |
| 48 |
Type: STT_FUNC |
| 49 |
Section: .text.bar |
| 50 |
Size: 0x0000000000000000 |
| 51 |
Binding: STB_WEAK |
| 52 |
- Name: foo |
| 53 |
Type: STT_FUNC |
| 54 |
Section: .text.foo |
| 55 |
Size: 0x0000000000000000 |
| 56 |
Binding: STB_WEAK |
| 57 |
|
| 58 |
## This checks that tool will emit an error when trying to remove the symbol |
| 59 |
## table when we have a group section linked with symtab. |
| 60 |
# RUN: not llvm-objcopy -R .symtab %t %t2 2>&1 | FileCheck %s --check-prefix=ERR -DINPUT=%t |
| 61 |
|
| 62 |
# ERR: error: '[[INPUT]]': section '.symtab' cannot be removed because it is referenced by the group section '.group' |
| 63 |
|
| 64 |
## The '.symtab' section could be removed using --allow-broken-links option. |
| 65 |
# RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t3 |
| 66 |
# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=SECTIONS |
| 67 |
|
| 68 |
# SECTIONS: There are 6 section headers |
| 69 |
# SECTIONS: Name Type Address Off Size ES Flg Lk Inf |
| 70 |
# SECTIONS-NEXT: NULL |
| 71 |
# SECTIONS-NEXT: .group {{.+}} {{.+}} {{.+}} {{.+}} {{.+}} 0 0 |
| 72 |
# SECTIONS-NEXT: .text.bar |
| 73 |
# SECTIONS-NEXT: .text.foo |
| 74 |
# SECTIONS-NEXT: .strtab |
| 75 |
# SECTIONS-NEXT: .shstrtab |
| 76 |
|
| 77 |
## Show that llvm-objcopy can handle a group section with a zero sh_link and |
| 78 |
## sh_info fields. |
| 79 |
# RUN: llvm-objcopy --allow-broken-links -R .symtab %t3 %t4 |
| 80 |
# RUN: cmp %t3 %t4 |
| 81 |
|
| 82 |
## The signature symbol becomes local. Assume the intention is to localize the group. |
| 83 |
## Drop GRP_COMDAT so that the linker will suppress deduplication. |
| 84 |
# RUN: llvm-objcopy --keep-global-symbol=bar %t %t5 |
| 85 |
# RUN: llvm-readelf -s --section-groups %t5 | FileCheck %s --check-prefix=LOCAL-SIG |
| 86 |
|
| 87 |
# LOCAL-SIG: LOCAL DEFAULT [[#]] foo |
| 88 |
# LOCAL-SIG: (unknown) group section [ 1] `.group' [foo] contains 1 sections: |
| 89 |
|
| 90 |
## The signature symbol remains non-local. Keep GRP_COMDAT. |
| 91 |
# RUN: llvm-readelf -s --section-groups %t1 | FileCheck %s --check-prefix=WEAK-SIG |
| 92 |
|
| 93 |
# WEAK-SIG: WEAK DEFAULT [[#]] foo |
| 94 |
# WEAK-SIG: COMDAT group section [ 1] `.group' [foo] contains 1 sections: |
| 95 |
|
| 96 |
# RUN: llvm-objcopy --globalize-symbol=foo %t %t6 |
| 97 |
# RUN: llvm-readelf -s --section-groups %t6 | FileCheck %s --check-prefix=GLOBAL-SIG |
| 98 |
|
| 99 |
# GLOBAL-SIG: GLOBAL DEFAULT [[#]] foo |
| 100 |
# GLOBAL-SIG: COMDAT group section [ 1] `.group' [foo] contains 1 sections: |
| 101 |
|
| 102 |
## If the signature is initially local and no operation has been performed to |
| 103 |
## specifically localize it, it isn't clear whether we should drop GRP_COMDAT. |
| 104 |
## The current convention is that compilers should not produce such input, so |
| 105 |
## our choice does not matter. |
| 106 |
# RUN: yaml2obj --docnum=2 %s -o %t.localsig |
| 107 |
# RUN: llvm-objcopy %t.localsig %t.localsig.out |
| 108 |
# RUN: llvm-readelf -s --section-groups %t.localsig.out | FileCheck %s --check-prefix=LOCAL-SIG |
| 109 |
|
| 110 |
--- !ELF |
| 111 |
FileHeader: |
| 112 |
Class: ELFCLASS64 |
| 113 |
Data: ELFDATA2LSB |
| 114 |
Type: ET_REL |
| 115 |
Machine: EM_X86_64 |
| 116 |
Sections: |
| 117 |
- Name: .group |
| 118 |
Type: SHT_GROUP |
| 119 |
Info: foo |
| 120 |
Members: |
| 121 |
- SectionOrType: GRP_COMDAT |
| 122 |
- SectionOrType: .text.foo |
| 123 |
- Name: .text.foo |
| 124 |
Type: SHT_PROGBITS |
| 125 |
Flags: [ SHF_GROUP ] |
| 126 |
Symbols: |
| 127 |
- Name: foo |
| 128 |
Type: STT_FUNC |
| 129 |
Section: .text.foo |