Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions llvm/test/tools/llvm-readobj/ELF/sframe-header.test
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
## Check parsing and dumping of the SFrame header.
# RUN: yaml2obj --docnum=1 %s -o %t.1
# RUN: llvm-readobj --sframe=.sframe_1b --sframe=.sframe_bad_magic \
# RUN: --sframe=.sframe_bad_version --sframe=.sframe_6b \
# RUN: --sframe=.sframe_header %t.1 2>&1 \
# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=CASE1
# RUN: llvm-readobj --sframe=.sframe_bad_sh_size --sframe=.sframe_1b \
# RUN: --sframe=.sframe_bad_magic --sframe=.sframe_bad_version \
# RUN: --sframe=.sframe_6b --sframe=.sframe_header %t.1 2>&1 \
# RUN: | FileCheck %s --strict-whitespace --match-full-lines \
# RUN: -DFILE=%t.1 --check-prefix=CASE1

## Check big-endian support and the handling of --sframe argument default.
# RUN: yaml2obj --docnum=2 %s -o %t.2
# RUN: llvm-readobj --sframe %t.2 2>&1 \
# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=CASE2
# RUN: | FileCheck %s --strict-whitespace --match-full-lines \
# RUN: -DFILE=%t.2 --check-prefix=CASE2

## Check handling of corrupted elf files (bad sh_name)
# RUN: yaml2obj --docnum=3 %s -o %t.3
# RUN: not llvm-readobj --sframe %t.3 2>&1 \
# RUN: | FileCheck %s --strict-whitespace --match-full-lines \
# RUN: -DFILE=%t.3 --check-prefix=CASE3

--- !ELF
FileHeader:
Expand All @@ -17,42 +25,48 @@ FileHeader:
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .sframe_bad_sh_size
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ShSize: 0xfffff
# CASE1-LABEL:SFrame section '.sframe_bad_sh_size' {
# CASE1:{{.*}}: warning: '[[FILE]]': The end of the file was unexpectedly encountered
- Name: .sframe_1b
Type: SHT_PROGBITS
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ContentArray: [ 0x00 ]
# CASE1-LABEL:SFrame section '.sframe_1b' {
# CASE1:{{.*}}: warning: {{.*}}: unexpected end of data at offset 0x1 while reading [0x0, 0x4)
# CASE1:{{.*}}: warning: '[[FILE]]': unexpected end of data at offset 0x1 while reading [0x0, 0x4)

- Name: .sframe_bad_magic
Type: SHT_PROGBITS
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ContentArray: [ 0xde, 0xad, 0xbe, 0xef]
# CASE1-LABEL:SFrame section '.sframe_bad_magic' {
# CASE1:{{.*}}: warning: {{.*}}: invalid magic number
# CASE1:{{.*}}: warning: '[[FILE]]': invalid magic number

- Name: .sframe_bad_version
Type: SHT_PROGBITS
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ContentArray: [
0xe2, 0xde, 0x01, 0x00 # Preamble (magic, version, flags)
]
# CASE1-LABEL:SFrame section '.sframe_bad_version' {
# CASE1:{{.*}}: warning: {{.*}}: invalid/unsupported version number
# CASE1:{{.*}}: warning: '[[FILE]]': invalid/unsupported version number

- Name: .sframe_6b
Type: SHT_PROGBITS
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ContentArray: [
0xe2, 0xde, 0x02, 0x00, # Preamble (magic, version, flags)
0x01, 0x02
]

# CASE1-LABEL:SFrame section '.sframe_6b' {
# CASE1:{{.*}}: warning: {{.*}}: unexpected end of data at offset 0x6 while reading [0x0, 0x1c)
# CASE1:{{.*}}: warning: '[[FILE]]': unexpected end of data at offset 0x6 while reading [0x0, 0x1c)

- Name: .sframe_header
Type: SHT_PROGBITS
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ContentArray: [
0xe2, 0xde, 0x02, 0x06, # Preamble (magic, version, flags)
Expand Down Expand Up @@ -92,7 +106,7 @@ FileHeader:
Machine: EM_AARCH64
Sections:
- Name: .sframe
Type: SHT_PROGBITS
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ContentArray: [
0xde, 0xe2, 0x02, 0x01, # Preamble (magic, version, flags)
Expand Down Expand Up @@ -122,3 +136,16 @@ Sections:
# CASE2-NEXT: FRE subsection offset: 256
# CASE2-NEXT: }
# CASE2-NEXT:}

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2MSB
Type: ET_EXEC
Machine: EM_AARCH64
Sections:
- Name: .corrupted
Type: SHT_GNU_SFRAME
Flags: [ SHF_ALLOC ]
ShName: 0x10000
# CASE3:{{.*}}: error: '[[FILE]]': a section [index 1] has an invalid sh_name (0x10000) offset which goes past the end of the section name string table
7 changes: 2 additions & 5 deletions llvm/tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6438,11 +6438,8 @@ void ELFDumper<ELFT>::printSectionsAsSFrame(ArrayRef<std::string> Sections) {
constexpr endianness E = ELFT::Endianness;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(ObjF, Sections)) {
StringRef SectionName;
if (Error Err = Section.getName().moveInto(SectionName)) {
SectionName = "<error>";
reportWarning(std::move(Err), FileName);
}
// Validity of sections names checked in getSectionRefsByNameOrIndex
StringRef SectionName = cantFail(Section.getName());

DictScope SectionScope(W,
formatv("SFrame section '{0}'", SectionName).str());
Expand Down