llvm-project/lld/test/elf/sectionGroups/sectiongroup-with-undef-external-reference.test
Shankar Easwaran 9e07346679 [ELF] Add section group/COMDAT support.
SHF_GROUP: Group Member Sections
----------------------------------
A section which is part of a group, and is to be retained or discarded with the
group as a whole, is identified by a new section header attribute: SHF_GROUP
This section is a member (perhaps the only one) of a group of sections, and the
linker should retain or discard all or none of the members. This section must be
referenced in a SHT_GROUP section. This attribute flag may be set in any section
header, and no other modification or indication is made in the grouped sections.
All additional information is contained in the associated SHT_GROUP section.

SHT_GROUP: Section Group Definition
-------------------------------------
Represents a group section.

The section group's sh_link field identifies a symbol table section, and its
sh_info field the index of a symbol in that section. The name of that symbol is
treated as the identifier of the section group.

More information: https://mentorembedded.github.io/cxx-abi/abi/prop-72-comdat.html

Added a lot of extensive tests, that tests functionality.

llvm-svn: 230195
2015-02-23 00:30:00 +00:00

240 lines
7.4 KiB
Plaintext

# This tests that comdat undef symbol is overridden by a global symbol.
# comdat1.s
#------------------------
# .global g1
# .section .foo,"axG",@progbits,g1,comdat
#g1:
# .word 5
#
#comdat2.s << \!
#-----------------
# .global g1
# .section .foo,"axG",@progbits,g1,comdat
#g1:
# nop
#
#g1.c
#-----------
#extern int g1;
#int fn() { return g1;}
#
#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.comdat1.o
#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.comdat2.o
#RUN: yaml2obj -format=elf -docnum 3 %s -o %t.g1.o
#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \
#RUN: %t.g1.o --noinhibit-exec --output-filetype=yaml -o %t2.out.yaml
#RUN: lld -flavor gnu -target x86_64 %t.comdat1.o %t.comdat2.o \
#RUN: %t.g1.o --noinhibit-exec -o %t2.out
#RUN: FileCheck %s -check-prefix=CHECKGROUP < %t2.out.yaml
#RUN: llvm-readobj -sections %t2.out | FileCheck %s -check-prefix=CHECKGROUPSECTIONS
#RUN: llvm-readobj -symbols %t2.out | FileCheck %s -check-prefix=CHECKSYMBOLS
#CHECKGROUP: - name: g1
#CHECKGROUP: scope: global
#CHECKGROUP: content: [ 05, 00 ]
#CHECKGROUP: section-name: .foo
#CHECKGROUPSECTIONS: Section {
#CHECKGROUPSECTIONS: Name: .foo
#CHECKGROUPSECTIONS: Type: SHT_PROGBITS
#CHECKGROUPSECTIONS: Flags [
#CHECKGROUPSECTIONS: SHF_ALLOC
#CHECKGROUPSECTIONS: SHF_EXECINSTR
#CHECKGROUPSECTIONS: ]
#CHECKGROUPSECTIONS: Size: 2
#CHECKGROUPSECTIONS: }
#CHECKSYMBOLS: Name: g1
#CHECKSYMBOLS: Section: .foo
#CHECKSYMBOLS: Name: fn
#CHECKSYMBOLS: Section: .text
---
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
OSABI: ELFOSABI_GNU
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .group
Type: SHT_GROUP
Link: .symtab
AddressAlign: 0x0000000000000004
Info: g1
Members:
- SectionOrType: GRP_COMDAT
- SectionOrType: .foo
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .bss
Type: SHT_NOBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .foo
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
AddressAlign: 0x0000000000000001
Content: '0500'
Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .data
Type: STT_SECTION
Section: .data
- Name: .bss
Type: STT_SECTION
Section: .bss
- Name: .foo
Type: STT_SECTION
Section: .foo
Global:
- Name: g1
Section: .foo
...
---
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
OSABI: ELFOSABI_GNU
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .group
Type: SHT_GROUP
Link: .symtab
AddressAlign: 0x0000000000000004
Info: g1
Members:
- SectionOrType: GRP_COMDAT
- SectionOrType: .foo
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .bss
Type: SHT_NOBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .foo
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
AddressAlign: 0x0000000000000001
Content: '90'
Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .data
Type: STT_SECTION
Section: .data
- Name: .bss
Type: STT_SECTION
Section: .bss
- Name: .foo
Type: STT_SECTION
Section: .foo
Global:
- Name: g1
Section: .foo
...
---
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
OSABI: ELFOSABI_GNU
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000010
Content: 554889E58B0425000000005DC3
- Name: .rela.text
Type: SHT_RELA
Link: .symtab
AddressAlign: 0x0000000000000008
Info: .text
Relocations:
- Offset: 0x0000000000000007
Symbol: g1
Type: R_X86_64_32S
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .bss
Type: SHT_NOBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: ''
- Name: .comment
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x0000000000000001
Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232393535372920286C6C766D2F7472756E6B203232393536332900
- Name: .note.GNU-stack
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: ''
- Name: .eh_frame
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000008
Content: 1400000000000000037A5200017810011B0C0708900100001C0000001C000000000000000D00000000410E108602430D0600000000000000
- Name: .rela.eh_frame
Type: SHT_RELA
Link: .symtab
AddressAlign: 0x0000000000000008
Info: .eh_frame
Relocations:
- Offset: 0x0000000000000020
Symbol: .text
Type: R_X86_64_PC32
Symbols:
Local:
- Name: global-g1.c
Type: STT_FILE
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .data
Type: STT_SECTION
Section: .data
- Name: .bss
Type: STT_SECTION
Section: .bss
- Name: .comment
Type: STT_SECTION
Section: .comment
- Name: .note.GNU-stack
Type: STT_SECTION
Section: .note.GNU-stack
- Name: .eh_frame
Type: STT_SECTION
Section: .eh_frame
Global:
- Name: fn
Type: STT_FUNC
Section: .text
Size: 0x000000000000000D
- Name: g1
...