130 lines · plain
1# RUN: yaml2obj %s -o %t2# RUN: llvm-objcopy --remove-section=.text.bar %t %t13# RUN: llvm-readobj --section-groups %t1 | FileCheck %s4 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: .group10# CHECK-NEXT: Index: 111# CHECK-NEXT: Link: 312# CHECK-NEXT: Info: 213# CHECK-NEXT: Type: COMDAT (0x1)14# CHECK-NEXT: Signature: foo15# CHECK: .text.foo (2)16 17--- !ELF18FileHeader: 19 Class: ELFCLASS6420 Data: ELFDATA2LSB21 Type: ET_REL22 Machine: EM_X86_6423Sections: 24 - Name: .group25 Type: SHT_GROUP26 Link: .symtab27 AddressAlign: 0x000000000000000428 Info: foo29 Members: 30 - SectionOrType: GRP_COMDAT31 - SectionOrType: .text.foo32 - Name: .text.bar33 Type: SHT_PROGBITS34 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]35 AddressAlign: 0x000000000000001036 - Name: .text.foo37 Type: SHT_PROGBITS38 Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]39 AddressAlign: 0x000000000000001040Symbols:41 - Name: .text.bar42 Type: STT_SECTION43 Section: .text.bar44 - Name: .text.foo45 Type: STT_SECTION46 Section: .text.foo47 - Name: bar48 Type: STT_FUNC49 Section: .text.bar50 Size: 0x000000000000000051 Binding: STB_WEAK52 - Name: foo53 Type: STT_FUNC54 Section: .text.foo55 Size: 0x000000000000000056 Binding: STB_WEAK57 58## This checks that tool will emit an error when trying to remove the symbol59## 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=%t61 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 %t366# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=SECTIONS67 68# SECTIONS: There are 6 section headers69# SECTIONS: Name Type Address Off Size ES Flg Lk Inf70# SECTIONS-NEXT: NULL71# SECTIONS-NEXT: .group {{.+}} {{.+}} {{.+}} {{.+}} {{.+}} 0 072# SECTIONS-NEXT: .text.bar73# SECTIONS-NEXT: .text.foo74# SECTIONS-NEXT: .strtab75# SECTIONS-NEXT: .shstrtab76 77## Show that llvm-objcopy can handle a group section with a zero sh_link and78## sh_info fields.79# RUN: llvm-objcopy --allow-broken-links -R .symtab %t3 %t480# RUN: cmp %t3 %t481 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 %t585# RUN: llvm-readelf -s --section-groups %t5 | FileCheck %s --check-prefix=LOCAL-SIG86 87# LOCAL-SIG: LOCAL DEFAULT [[#]] foo88# 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-SIG92 93# WEAK-SIG: WEAK DEFAULT [[#]] foo94# WEAK-SIG: COMDAT group section [ 1] `.group' [foo] contains 1 sections:95 96# RUN: llvm-objcopy --globalize-symbol=foo %t %t697# RUN: llvm-readelf -s --section-groups %t6 | FileCheck %s --check-prefix=GLOBAL-SIG98 99# GLOBAL-SIG: GLOBAL DEFAULT [[#]] foo100# 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 to103## 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, so105## our choice does not matter.106# RUN: yaml2obj --docnum=2 %s -o %t.localsig107# RUN: llvm-objcopy %t.localsig %t.localsig.out108# RUN: llvm-readelf -s --section-groups %t.localsig.out | FileCheck %s --check-prefix=LOCAL-SIG109 110--- !ELF111FileHeader:112 Class: ELFCLASS64113 Data: ELFDATA2LSB114 Type: ET_REL115 Machine: EM_X86_64116Sections:117 - Name: .group118 Type: SHT_GROUP119 Info: foo120 Members:121 - SectionOrType: GRP_COMDAT122 - SectionOrType: .text.foo123 - Name: .text.foo124 Type: SHT_PROGBITS125 Flags: [ SHF_GROUP ]126Symbols:127 - Name: foo128 Type: STT_FUNC129 Section: .text.foo130