Files
clang-p2996/llvm/test/tools/obj2yaml/ELF/entsize.yaml
Georgii Rymar d5e48f1347 [yaml2obj][obj2yaml] - Improve how we set/dump the sh_entsize field.
We already set the `sh_entsize` field in a single place
for all non-implicit sections.

This patch reorders the logic slightly and with it
we finally have the only one place where the `sh_entsize` is set.

obj2yaml will not dump the `EntSize` key for `SHT_DYNSYM/SHT_SYMTAB` sections anymore,
when the value of `sh_entsize` is equal to `sizeof(Elf_Sym)`

Note that this also seems revealed an issue in llvm-objcopy:
Previously yaml2obj set the `sh_entsize` for the `.symtab` section to 0x18,
now we it sets it for `SHT_SYMTAB` sections, i.e. by type.
But the `llvm-objcopy/ELF/only-keep-debug.test` has a `.symtab` section of type `SHT_STRTAB`,
and now yaml2obj sets the `sh_entsize` to 0 for it.
I had to update the corresponding check lines for `ES`, but the behavior of
`llvm-objcopy` should be fixed instead I think.
I've added a TODO and a comment.

Differential revision: https://reviews.llvm.org/D95364
2021-01-26 13:33:02 +03:00

52 lines
1.6 KiB
YAML

## Check how obj2yaml dumps the sh_entsize field.
## Check we don't dump the "EntSize" key for SHT_SYMTAB/SHT_DYNSYM sections
## when the value of sh_entsize is equal to sizeof(ELF_Sym) == 0x18.
# RUN: yaml2obj %s -o %t
# RUN: obj2yaml %t | FileCheck %s
# CHECK: - Name: .rodata.cst4
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: EntSize: 0x4
# CHECK-NEXT: - Name: .mysymtab
# CHECK-NEXT: Type: SHT_SYMTAB
# CHECK-NEXT: Link: .strtab
# CHECK-NEXT: Size: 0x0
# CHECK-NEXT: - Name: .mydynsym
# CHECK-NEXT: Type: SHT_DYNSYM
# CHECK-NEXT: Size: 0x0
# CHECK-NEXT: ...
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .rodata.cst4
Type: SHT_PROGBITS
EntSize: 0x4
- Name: .mysymtab
Type: SHT_SYMTAB
EntSize: [[SYMTABES=0x18]]
- Name: .mydynsym
Type: SHT_DYNSYM
EntSize: [[DYNSYMES=0x18]]
## Document that we are unable to dump a SHT_SYMTAB section when its entry size
## is not equal to sizeof(ELF_Sym).
# RUN: yaml2obj %s -DSYMTABES=0x19 -o %t2
# RUN: not obj2yaml %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=ERR1
# ERR1: Error reading file: [[FILE]]: section [index 2] has invalid sh_entsize: expected 24, but got 25
## Document that we are unable to dump a SHT_DYNSYM section when its entry size
## is not equal to sizeof(ELF_Sym).
# RUN: yaml2obj %s -DDYNSYMES=0x19 -o %t3
# RUN: not obj2yaml %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=ERR2
# ERR2: Error reading file: [[FILE]]: section [index 3] has invalid sh_entsize: expected 24, but got 25