Skip to content

Commit 21bbdf9

Browse files
author
git apple-llvm automerger
committed
Merge commit 'fe2d5a59fd5d' from apple/master into swift/master-next
2 parents c5fa50a + fe2d5a5 commit 21bbdf9

File tree

2 files changed

+54
-51
lines changed

2 files changed

+54
-51
lines changed

llvm/test/tools/llvm-readobj/ELF/relocation-errors.test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66

77
# LLVM: Relocations [
88
# LLVM-NEXT: Section (3) .rel.text {
9-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
10-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 2 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
9+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
10+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
1111
# LLVM-NEXT: 0x2 R_X86_64_NONE - 0x0
12-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 4 in section 3: invalid section index: 255
13-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 5 in section 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
12+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_REL section with index 3: invalid section index: 255
13+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 5 in SHT_REL section with index 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
1414
# LLVM-NEXT: }
1515
# LLVM-NEXT: Section (4) .rela.text {
16-
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
16+
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
1717
# LLVM-NEXT: }
1818
# LLVM-NEXT: ]
1919

2020
# GNU: Relocation section '.rel.text' at offset 0x41 contains 5 entries:
2121
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
22-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
23-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 2 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
22+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
23+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
2424
# GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE
25-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 4 in section 3: invalid section index: 255
26-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 5 in section 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
25+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_REL section with index 3: invalid section index: 255
26+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 5 in SHT_REL section with index 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
2727
# GNU-EMPTY:
2828
# GNU-NEXT: Relocation section '.rela.text' at offset 0x91 contains 1 entries:
2929
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
30-
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
30+
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
3131

3232
--- !ELF
3333
FileHeader:

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,10 @@ template <typename ELFT> class DumpStyle {
747747
function_ref<void(const Elf_Shdr &)> OnSectionStart,
748748
function_ref<void(StringRef, uint64_t)> OnSectionEntry);
749749

750-
virtual void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
751-
const Elf_Rel &R, unsigned RelIndex) = 0;
752-
virtual void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
753-
const Elf_Rela &R, unsigned RelIndex) = 0;
750+
virtual void printRelReloc(const Elf_Rel &R, unsigned RelIndex,
751+
const Elf_Shdr *Sec, const Elf_Shdr *SymTab) = 0;
752+
virtual void printRelaReloc(const Elf_Rela &R, unsigned RelIndex,
753+
const Elf_Shdr *Sec, const Elf_Shdr *SymTab) = 0;
754754
virtual void printRelrReloc(const Elf_Relr &R) = 0;
755755
void printRelocationsHelper(const Elf_Shdr &Sec);
756756

@@ -863,15 +863,15 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
863863
}
864864
void printHashedSymbol(const Elf_Sym *FirstSym, uint32_t Sym,
865865
StringRef StrTable, uint32_t Bucket);
866-
void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
867-
const Elf_Rel &R, unsigned RelIndex) override;
868-
void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
869-
const Elf_Rela &R, unsigned RelIndex) override;
866+
void printRelReloc(const Elf_Rel &R, unsigned RelIndex, const Elf_Shdr *Sec,
867+
const Elf_Shdr *SymTab) override;
868+
void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, const Elf_Shdr *Sec,
869+
const Elf_Shdr *SymTab) override;
870870
void printRelrReloc(const Elf_Relr &R) override;
871871

872872
template <class RelTy>
873-
void printRelRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
874-
const RelTy &R, unsigned RelIndex);
873+
void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec,
874+
const Elf_Shdr *SymTab);
875875
template <class RelTy>
876876
void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName,
877877
const RelTy &R);
@@ -932,13 +932,13 @@ template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
932932
void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override;
933933

934934
private:
935-
void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
936-
const Elf_Rel &R, unsigned RelIndex) override;
937-
void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
938-
const Elf_Rela &R, unsigned RelIndex) override;
935+
void printRelReloc(const Elf_Rel &R, unsigned RelIndex, const Elf_Shdr *Sec,
936+
const Elf_Shdr *SymTab) override;
937+
void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, const Elf_Shdr *Sec,
938+
const Elf_Shdr *SymTab) override;
939939
void printRelrReloc(const Elf_Relr &R) override;
940940
template <class RelTy>
941-
void printRelRelaReloc(unsigned SecIndex, const RelTy &Rel, unsigned RelIndex,
941+
void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec,
942942
const Elf_Shdr *SymTab);
943943
template <class RelTy> void printDynamicRelocation(const RelTy &Rel);
944944

@@ -3601,15 +3601,17 @@ template <class ELFT> void GNUStyle<ELFT>::printGroupSections() {
36013601
}
36023602

36033603
template <class ELFT>
3604-
void GNUStyle<ELFT>::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
3605-
const Elf_Rel &R, unsigned RelIndex) {
3606-
printRelRelaReloc(SecIndex, SymTab, R, RelIndex);
3604+
void GNUStyle<ELFT>::printRelReloc(const Elf_Rel &R, unsigned RelIndex,
3605+
const Elf_Shdr *Sec,
3606+
const Elf_Shdr *SymTab) {
3607+
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
36073608
}
36083609

36093610
template <class ELFT>
3610-
void GNUStyle<ELFT>::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
3611-
const Elf_Rela &R, unsigned RelIndex) {
3612-
printRelRelaReloc(SecIndex, SymTab, R, RelIndex);
3611+
void GNUStyle<ELFT>::printRelaReloc(const Elf_Rela &R, unsigned RelIndex,
3612+
const Elf_Shdr *Sec,
3613+
const Elf_Shdr *SymTab) {
3614+
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
36133615
}
36143616

36153617
template <class ELFT> void GNUStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
@@ -3618,15 +3620,15 @@ template <class ELFT> void GNUStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
36183620

36193621
template <class ELFT>
36203622
template <class RelTy>
3621-
void GNUStyle<ELFT>::printRelRelaReloc(unsigned SecIndex,
3622-
const Elf_Shdr *SymTab, const RelTy &R,
3623-
unsigned RelIndex) {
3623+
void GNUStyle<ELFT>::printRelRelaReloc(const RelTy &R, unsigned RelIndex,
3624+
const Elf_Shdr &Sec,
3625+
const Elf_Shdr *SymTab) {
36243626
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
36253627
this->dumper()->getRelocationTarget(SymTab, R);
36263628
if (!Target)
36273629
this->reportUniqueWarning(createError(
3628-
"unable to print relocation " + Twine(RelIndex) + " in section " +
3629-
Twine(SecIndex) + ": " + toString(Target.takeError())));
3630+
"unable to print relocation " + Twine(RelIndex) + " in " +
3631+
describe(this->Obj, Sec) + ": " + toString(Target.takeError())));
36303632
else
36313633
printRelRelaReloc(/*Sym=*/Target->first, /*Name=*/Target->second, R);
36323634
}
@@ -5466,21 +5468,20 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) {
54665468
SymTab = *SymTabOrErr;
54675469
}
54685470

5469-
unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front();
54705471
unsigned RelNdx = 0;
54715472
switch (Sec.sh_type) {
54725473
case ELF::SHT_REL:
54735474
if (Expected<Elf_Rel_Range> RangeOrErr = Obj.rels(&Sec)) {
54745475
for (const Elf_Rel &R : *RangeOrErr)
5475-
printRelReloc(SecNdx, SymTab, R, ++RelNdx);
5476+
printRelReloc(R, ++RelNdx, &Sec, SymTab);
54765477
} else {
54775478
Warn(RangeOrErr.takeError());
54785479
}
54795480
break;
54805481
case ELF::SHT_RELA:
54815482
if (Expected<Elf_Rela_Range> RangeOrErr = Obj.relas(&Sec)) {
54825483
for (const Elf_Rela &R : *RangeOrErr)
5483-
printRelaReloc(SecNdx, SymTab, R, ++RelNdx);
5484+
printRelaReloc(R, ++RelNdx, &Sec, SymTab);
54845485
} else {
54855486
Warn(RangeOrErr.takeError());
54865487
}
@@ -5499,14 +5500,14 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) {
54995500
}
55005501

55015502
for (const Elf_Rel &R : Obj.decode_relrs(*RangeOrErr))
5502-
printRelReloc(SecNdx, /*SymTab=*/nullptr, R, ++RelNdx);
5503+
printRelReloc(R, ++RelNdx, &Sec, /*SymTab=*/nullptr);
55035504
break;
55045505
}
55055506
case ELF::SHT_ANDROID_REL:
55065507
case ELF::SHT_ANDROID_RELA:
55075508
if (Expected<std::vector<Elf_Rela>> RelasOrErr = Obj.android_relas(&Sec)) {
55085509
for (const Elf_Rela &R : *RelasOrErr)
5509-
printRelaReloc(SecNdx, SymTab, R, ++RelNdx);
5510+
printRelaReloc(R, ++RelNdx, &Sec, SymTab);
55105511
} else {
55115512
Warn(RelasOrErr.takeError());
55125513
}
@@ -6146,15 +6147,17 @@ template <class ELFT> void LLVMStyle<ELFT>::printRelocations() {
61466147
}
61476148

61486149
template <class ELFT>
6149-
void LLVMStyle<ELFT>::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
6150-
const Elf_Rel &R, unsigned RelIndex) {
6151-
printRelRelaReloc(SecIndex, R, RelIndex, SymTab);
6150+
void LLVMStyle<ELFT>::printRelReloc(const Elf_Rel &R, unsigned RelIndex,
6151+
const Elf_Shdr *Sec,
6152+
const Elf_Shdr *SymTab) {
6153+
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
61526154
}
61536155

61546156
template <class ELFT>
6155-
void LLVMStyle<ELFT>::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
6156-
const Elf_Rela &R, unsigned RelIndex) {
6157-
printRelRelaReloc(SecIndex, R, RelIndex, SymTab);
6157+
void LLVMStyle<ELFT>::printRelaReloc(const Elf_Rela &R, unsigned RelIndex,
6158+
const Elf_Shdr *Sec,
6159+
const Elf_Shdr *SymTab) {
6160+
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
61586161
}
61596162

61606163
template <class ELFT> void LLVMStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
@@ -6163,15 +6166,15 @@ template <class ELFT> void LLVMStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
61636166

61646167
template <class ELFT>
61656168
template <class RelTy>
6166-
void LLVMStyle<ELFT>::printRelRelaReloc(unsigned SecIndex, const RelTy &Rel,
6167-
unsigned RelIndex,
6169+
void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex,
6170+
const Elf_Shdr &Sec,
61686171
const Elf_Shdr *SymTab) {
61696172
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
61706173
this->dumper()->getRelocationTarget(SymTab, Rel);
61716174
if (!Target) {
61726175
this->reportUniqueWarning(createError(
6173-
"unable to print relocation " + Twine(RelIndex) + " in section " +
6174-
Twine(SecIndex) + ": " + toString(Target.takeError())));
6176+
"unable to print relocation " + Twine(RelIndex) + " in " +
6177+
describe(this->Obj, Sec) + ": " + toString(Target.takeError())));
61756178
return;
61766179
}
61776180

0 commit comments

Comments
 (0)