forked from OSchip/llvm-project
[llvm-objdump] -r: print non-SHF_ALLOC relocations for non-ET_REL files
ET_EXEC and ET_DYN files may contain non-SHF_ALLOC relocation sections (e.g. ld --emit-relocs). Match GNU objdump by dumping them. * Remove Object/dynamic-reloc.test. Replace it with a -r RUN line in dynamic-relocs.test * Update relocations-in-nonreloc.test to set sh_link/sh_info. GNU objdump seems to ignore a SHT_REL/SHT_RELA section not linking to SHT_SYMTAB. The test did not test what it intended to test. Fix https://github.com/llvm/llvm-project/issues/41246 Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D128959
This commit is contained in:
parent
38bcd483dd
commit
f80a4321ef
llvm
test
Object
tools/llvm-objdump
tools/llvm-objdump
|
@ -1,12 +0,0 @@
|
||||||
RUN: llvm-readobj -r %p/Inputs/dynamic-reloc.so | FileCheck --check-prefix=READOBJ %s
|
|
||||||
|
|
||||||
READOBJ: Relocations [
|
|
||||||
READOBJ-NEXT: Section (4) .rela.dyn {
|
|
||||||
READOBJ-NEXT: 0x1328 R_X86_64_RELATIVE - 0x1320
|
|
||||||
READOBJ-NEXT: }
|
|
||||||
READOBJ-NEXT: ]
|
|
||||||
|
|
||||||
RUN: llvm-objdump -r %p/Inputs/dynamic-reloc.so | FileCheck --check-prefix=OBJDUMP %s
|
|
||||||
|
|
||||||
OBJDUMP: file format elf64-x86-64
|
|
||||||
OBJDUMP-NOT: RELOCATION
|
|
|
@ -29,6 +29,11 @@ FileHeader:
|
||||||
# CHECK-NEXT:0000000000000008 R_X86_64_NONE foo
|
# CHECK-NEXT:0000000000000008 R_X86_64_NONE foo
|
||||||
#CHECK-EMPTY:
|
#CHECK-EMPTY:
|
||||||
|
|
||||||
|
## -r ignores dynamic relocations.
|
||||||
|
# RUN: llvm-objdump -r %t2 | FileCheck %s --check-prefix=STATIC-RELOC
|
||||||
|
|
||||||
|
# STATIC-RELOC-NOT: RELOCATION RECORDS
|
||||||
|
|
||||||
--- !ELF
|
--- !ELF
|
||||||
FileHeader:
|
FileHeader:
|
||||||
Class: ELFCLASS64
|
Class: ELFCLASS64
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
## Check that llvm-objdump -r prints non-SHF_ALLOC relocations.
|
||||||
|
|
||||||
|
## Non-SHF_ALLOC relocations may be due to ld --emit-relocs.
|
||||||
|
# RUN: yaml2obj -DTYPE=ET_EXEC %s -o %t1
|
||||||
|
# RUN: llvm-objdump -r %t1 | FileCheck %s -DFILE=%t1
|
||||||
|
# RUN: yaml2obj -DTYPE=ET_DYN %s -o %t2
|
||||||
|
# RUN: llvm-objdump -r %t2 | FileCheck %s -DFILE=%t2
|
||||||
|
## Non-SHF_ALLOC relocations are usually generated by compilers.
|
||||||
|
# RUN: yaml2obj -DTYPE=ET_REL %s -o %t3
|
||||||
|
# RUN: llvm-objdump -r %t3 | FileCheck %s -DFILE=%t3
|
||||||
|
|
||||||
|
# CHECK: [[FILE]]: file format elf64-x86-64
|
||||||
|
# CHECK-EMPTY:
|
||||||
|
# CHECK-NEXT: RELOCATION RECORDS FOR [.text]:
|
||||||
|
# CHECK-NEXT: OFFSET TYPE VALUE
|
||||||
|
# CHECK-NEXT: 0000000000000123 R_X86_64_NONE *ABS*+0x141
|
||||||
|
|
||||||
|
--- !ELF
|
||||||
|
FileHeader:
|
||||||
|
Class: ELFCLASS64
|
||||||
|
Data: ELFDATA2LSB
|
||||||
|
Type: [[TYPE]]
|
||||||
|
Machine: EM_X86_64
|
||||||
|
Sections:
|
||||||
|
- Name: .text
|
||||||
|
Type: SHT_PROGBITS
|
||||||
|
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
||||||
|
- Name: .rela.text
|
||||||
|
Type: SHT_RELA
|
||||||
|
Link: .symtab
|
||||||
|
Info: .text
|
||||||
|
Relocations:
|
||||||
|
- Offset: 0x123
|
||||||
|
Type: R_X86_64_NONE
|
||||||
|
Addend: 321
|
||||||
|
Symbols:
|
||||||
|
- Name: .text
|
||||||
|
Type: STT_SECTION
|
||||||
|
Section: .text
|
|
@ -1,59 +0,0 @@
|
||||||
## Check that objdump doesn't print relocations in non-relocatable object files.
|
|
||||||
|
|
||||||
# RUN: yaml2obj --docnum=1 %s -o %t1
|
|
||||||
# RUN: llvm-objdump -r %t1 | FileCheck %s -DFILE=%t1 --check-prefix=FMT --implicit-check-not={{.}}
|
|
||||||
# RUN: yaml2obj --docnum=2 %s -o %t2
|
|
||||||
# RUN: llvm-objdump -r %t2 | FileCheck %s -DFILE=%t2 --check-prefix=FMT --implicit-check-not={{.}}
|
|
||||||
# RUN: yaml2obj --docnum=3 %s -o %t3
|
|
||||||
# RUN: llvm-objdump -r %t3 | FileCheck %s -DFILE=%t3 --check-prefixes=FMT,REL --implicit-check-not={{.}}
|
|
||||||
|
|
||||||
# FMT: [[FILE]]: file format elf64-x86-64
|
|
||||||
|
|
||||||
# REL: RELOCATION RECORDS FOR []:
|
|
||||||
# REL-NEXT: OFFSET TYPE VALUE
|
|
||||||
# REL-NEXT: 0000000000000123 R_X86_64_NONE *ABS*+0x141
|
|
||||||
|
|
||||||
## Executable.
|
|
||||||
--- !ELF
|
|
||||||
FileHeader:
|
|
||||||
Class: ELFCLASS64
|
|
||||||
Data: ELFDATA2LSB
|
|
||||||
Type: ET_EXEC
|
|
||||||
Machine: EM_X86_64
|
|
||||||
Sections:
|
|
||||||
- Name: .rela.plt
|
|
||||||
Type: SHT_RELA
|
|
||||||
Relocations:
|
|
||||||
- Offset: 0x123
|
|
||||||
Type: R_X86_64_NONE
|
|
||||||
Addend: 321
|
|
||||||
|
|
||||||
## DSO.
|
|
||||||
--- !ELF
|
|
||||||
FileHeader:
|
|
||||||
Class: ELFCLASS64
|
|
||||||
Data: ELFDATA2LSB
|
|
||||||
Type: ET_DYN
|
|
||||||
Machine: EM_X86_64
|
|
||||||
Sections:
|
|
||||||
- Name: .rela.plt
|
|
||||||
Type: SHT_RELA
|
|
||||||
Relocations:
|
|
||||||
- Offset: 0x123
|
|
||||||
Type: R_X86_64_NONE
|
|
||||||
Addend: 321
|
|
||||||
|
|
||||||
## Relocatable.
|
|
||||||
--- !ELF
|
|
||||||
FileHeader:
|
|
||||||
Class: ELFCLASS64
|
|
||||||
Data: ELFDATA2LSB
|
|
||||||
Type: ET_REL
|
|
||||||
Machine: EM_X86_64
|
|
||||||
Sections:
|
|
||||||
- Name: .rela.plt
|
|
||||||
Type: SHT_RELA
|
|
||||||
Relocations:
|
|
||||||
- Offset: 0x123
|
|
||||||
Type: R_X86_64_NONE
|
|
||||||
Addend: 321
|
|
|
@ -1780,10 +1780,6 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
||||||
void objdump::printRelocations(const ObjectFile *Obj) {
|
void objdump::printRelocations(const ObjectFile *Obj) {
|
||||||
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
|
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
|
||||||
"%08" PRIx64;
|
"%08" PRIx64;
|
||||||
// Regular objdump doesn't print relocations in non-relocatable object
|
|
||||||
// files.
|
|
||||||
if (!Obj->isRelocatableObject())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Build a mapping from relocation target to a vector of relocation
|
// Build a mapping from relocation target to a vector of relocation
|
||||||
// sections. Usually, there is an only one relocation section for
|
// sections. Usually, there is an only one relocation section for
|
||||||
|
@ -1791,6 +1787,8 @@ void objdump::printRelocations(const ObjectFile *Obj) {
|
||||||
MapVector<SectionRef, std::vector<SectionRef>> SecToRelSec;
|
MapVector<SectionRef, std::vector<SectionRef>> SecToRelSec;
|
||||||
uint64_t Ndx;
|
uint64_t Ndx;
|
||||||
for (const SectionRef &Section : ToolSectionFilter(*Obj, &Ndx)) {
|
for (const SectionRef &Section : ToolSectionFilter(*Obj, &Ndx)) {
|
||||||
|
if (Obj->isELF() && (ELFSectionRef(Section).getFlags() & ELF::SHF_ALLOC))
|
||||||
|
continue;
|
||||||
if (Section.relocation_begin() == Section.relocation_end())
|
if (Section.relocation_begin() == Section.relocation_end())
|
||||||
continue;
|
continue;
|
||||||
Expected<section_iterator> SecOrErr = Section.getRelocatedSection();
|
Expected<section_iterator> SecOrErr = Section.getRelocatedSection();
|
||||||
|
|
Loading…
Reference in New Issue