mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[yaml2obj][elf2yaml] - Add a support for the EntSize
field for SHT_HASH
sections.
Specification for SHT_HASH table says (https://refspecs.linuxbase.org/elf/gabi4+/ch5.dynamic.html#hash) that it contains Elf32_Word entries for both 32/64 bit objects. Currently both GNU linkers and LLD sets the `sh_entsize` field to `4`. At the same time, `yaml2obj` ignores the `EntSize` field for SHT_HASH sections. This patch fixes this and also adds a support for obj2yaml: it will not dump this field when the `sh_entsize` contains the default value (`4`). Differential revision: https://reviews.llvm.org/D88652
This commit is contained in:
parent
6a5c2de672
commit
d37400ab28
@ -1396,6 +1396,11 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
|
||||
SN2I.lookup(".dynsym", Link))
|
||||
SHeader.sh_link = Link;
|
||||
|
||||
if (Section.EntSize)
|
||||
SHeader.sh_entsize = *Section.EntSize;
|
||||
else
|
||||
SHeader.sh_entsize = sizeof(typename ELFT::Word);
|
||||
|
||||
if (Section.Content || Section.Size) {
|
||||
SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size);
|
||||
return;
|
||||
|
@ -74,3 +74,40 @@ Sections:
|
||||
- Name: .oversized
|
||||
Type: SHT_HASH
|
||||
Content: '0100000002000000030000000400000000'
|
||||
|
||||
## Check how we dump the "EntSize" field. When the sh_entsize is 4,
|
||||
## we don't print it, because it is the default value for the SHT_HASH section.
|
||||
|
||||
# RUN: yaml2obj --docnum=3 %s -o %t3
|
||||
# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=ENT-SIZE
|
||||
|
||||
# ENT-SIZE: - Name: .hash.entsize.0
|
||||
# ENT-SIZE-NEXT: Type: SHT_HASH
|
||||
# ENT-SIZE-NEXT: EntSize: 0x0000000000000000
|
||||
# ENT-SIZE-NEXT: Content: ''
|
||||
# ENT-SIZE-NEXT: - Name: .hash.entsize.4.default
|
||||
# ENT-SIZE-NEXT: Type: SHT_HASH
|
||||
# ENT-SIZE-NEXT: Content: ''
|
||||
# ENT-SIZE-NEXT: - Name: .hash.entsize.255
|
||||
# ENT-SIZE-NEXT: Type: SHT_HASH
|
||||
# ENT-SIZE-NEXT: EntSize: 0x00000000000000FF
|
||||
# ENT-SIZE-NEXT: Content: ''
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS32
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_DYN
|
||||
Sections:
|
||||
- Name: .hash.entsize.0
|
||||
Type: SHT_HASH
|
||||
EntSize: 0
|
||||
Size: 0
|
||||
- Name: .hash.entsize.4.default
|
||||
Type: SHT_HASH
|
||||
EntSize: 4
|
||||
Size: 0
|
||||
- Name: .hash.entsize.255
|
||||
Type: SHT_HASH
|
||||
EntSize: 255
|
||||
Size: 0
|
||||
|
@ -1,9 +1,11 @@
|
||||
## Check how yaml2obj produces SHT_HASH sections.
|
||||
|
||||
## Check we can describe a SHT_HASH section using the "Content" tag.
|
||||
## Check default values of section fields.
|
||||
|
||||
# RUN: yaml2obj --docnum=1 %s -o %t1
|
||||
# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=CONTENT
|
||||
# RUN: llvm-readobj --sections --section-data %t1 | \
|
||||
# RUN: FileCheck %s -DENTSIZE=4 --check-prefix=CONTENT
|
||||
|
||||
# CONTENT: Name: .hash
|
||||
# CONTENT-NEXT: Type: SHT_HASH
|
||||
@ -15,7 +17,7 @@
|
||||
# CONTENT-NEXT: Link: 1
|
||||
# CONTENT-NEXT: Info: 0
|
||||
# CONTENT-NEXT: AddressAlignment: 0
|
||||
# CONTENT-NEXT: EntrySize: 0
|
||||
# CONTENT-NEXT: EntrySize: [[ENTSIZE]]{{$}}
|
||||
# CONTENT-NEXT: SectionData (
|
||||
# CONTENT-NEXT: 0000: 01000000 02000000 03000000 04000000
|
||||
# CONTENT-NEXT: 0010: 05000000
|
||||
@ -33,6 +35,13 @@ Sections:
|
||||
- Name: .hash
|
||||
Type: SHT_HASH
|
||||
Content: '0100000002000000030000000400000005000000'
|
||||
EntSize: [[ENTSIZE=<none>]]
|
||||
|
||||
## Check we can set an arbitrary entry size for the SHT_HASH section.
|
||||
|
||||
# RUN: yaml2obj --docnum=1 -DENTSIZE=0xFF %s -o %t1.entsize
|
||||
# RUN: llvm-readobj --sections --section-data %t1.entsize | \
|
||||
# RUN: FileCheck %s -DENTSIZE=255 --check-prefix=CONTENT
|
||||
|
||||
## Check we can describe a SHT_HASH section using "Bucket" and "Chain" tags.
|
||||
|
||||
@ -280,7 +289,7 @@ Sections:
|
||||
# OVERRIDE-NEXT: Link: 0
|
||||
# OVERRIDE-NEXT: Info: 0
|
||||
# OVERRIDE-NEXT: AddressAlignment: 0
|
||||
# OVERRIDE-NEXT: EntrySize: 0
|
||||
# OVERRIDE-NEXT: EntrySize: 4
|
||||
# OVERRIDE-NEXT: SectionData (
|
||||
# OVERRIDE-NEXT: 0000: AA000000 BB000000 01000000 02000000
|
||||
# OVERRIDE-NEXT: 0010: 03000000 04000000 05000000
|
||||
|
@ -406,7 +406,7 @@ SectionHeaderTable:
|
||||
# RUN: llvm-readelf %t8 --section-headers | FileCheck %s --check-prefix=LINK-HASH
|
||||
|
||||
# LINK-HASH: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
|
||||
# LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 00 0 0 0
|
||||
# LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 04 0 0 0
|
||||
# LINK-HASH-NEXT: [ 2] .gnu_hash GNU_HASH 0000000000000000 000040 000000 00 0 0 0
|
||||
|
||||
--- !ELF
|
||||
|
@ -659,6 +659,8 @@ static unsigned getDefaultShEntSize(ELFYAML::ELF_SHT SecType,
|
||||
return sizeof(typename ELFT::Relr);
|
||||
case ELF::SHT_DYNAMIC:
|
||||
return sizeof(typename ELFT::Dyn);
|
||||
case ELF::SHT_HASH:
|
||||
return sizeof(typename ELFT::Word);
|
||||
default:
|
||||
if (SecName == ".debug_str")
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user