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