Skip to content

Commit febcf0e

Browse files
author
git apple-llvm automerger
committed
Merge commit '0e6111d0ee86' from apple/master into swift/master-next
2 parents f6a3788 + 0e6111d commit febcf0e

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ namespace {
114114

115115
template <class ELFT> class DumpStyle;
116116

117+
template <class ELFT> struct RelSymbol {
118+
RelSymbol(const typename ELFT::Sym *S, StringRef N)
119+
: Sym(S), Name(N.str()) {}
120+
const typename ELFT::Sym *Sym;
121+
std::string Name;
122+
};
123+
117124
/// Represents a contiguous uniform range in the file. We cannot just create a
118125
/// range directly because when creating one of these from the .dynamic table
119126
/// the size, entity size and virtual address are different entries in arbitrary
@@ -364,8 +371,8 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
364371
getVersionDependencies(const Elf_Shdr *Sec) const;
365372

366373
template <class RelTy>
367-
Expected<std::pair<const Elf_Sym *, std::string>>
368-
getRelocationTarget(const Elf_Shdr *SymTab, const RelTy &R) const;
374+
Expected<RelSymbol<ELFT>> getRelocationTarget(const Elf_Shdr *SymTab,
375+
const RelTy &R) const;
369376

370377
std::function<Error(const Twine &Msg)> WarningHandler;
371378
void reportUniqueWarning(Error Err) const;
@@ -873,8 +880,7 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
873880
void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec,
874881
const Elf_Shdr *SymTab);
875882
template <class RelTy>
876-
void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName,
877-
const RelTy &R);
883+
void printRelRelaReloc(const RelTy &R, const RelSymbol<ELFT> &RelSym);
878884
void printSymbol(const Elf_Sym *Symbol, const Elf_Sym *First,
879885
Optional<StringRef> StrTable, bool IsDynamic,
880886
bool NonVisibilityBitsUsed) override;
@@ -1053,7 +1059,7 @@ Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym *Sym,
10531059

10541060
template <typename ELFT>
10551061
template <class RelTy>
1056-
Expected<std::pair<const typename ELFT::Sym *, std::string>>
1062+
Expected<RelSymbol<ELFT>>
10571063
ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
10581064
const RelTy &R) const {
10591065
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
@@ -1062,7 +1068,7 @@ ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
10621068
return SymOrErr.takeError();
10631069
const Elf_Sym *Sym = *SymOrErr;
10641070
if (!Sym)
1065-
return std::make_pair(nullptr, "");
1071+
return RelSymbol<ELFT>(nullptr, "");
10661072

10671073
// The st_name field of a STT_SECTION is usually 0 (empty string).
10681074
// This code block returns the section name.
@@ -1073,12 +1079,12 @@ ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
10731079
return SecOrErr.takeError();
10741080
// A section symbol describes the section at index 0.
10751081
if (*SecOrErr == nullptr)
1076-
return std::make_pair(Sym, "");
1082+
return RelSymbol<ELFT>(Sym, "");
10771083

10781084
Expected<StringRef> NameOrErr = Obj->getSectionName(*SecOrErr);
10791085
if (!NameOrErr)
10801086
return NameOrErr.takeError();
1081-
return std::make_pair(Sym, NameOrErr->str());
1087+
return RelSymbol<ELFT>(Sym, NameOrErr->str());
10821088
}
10831089

10841090
Expected<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*SymTab);
@@ -1087,7 +1093,7 @@ ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
10871093

10881094
std::string SymbolName =
10891095
getFullSymbolName(Sym, *StrTableOrErr, SymTab->sh_type == SHT_DYNSYM);
1090-
return std::make_pair(Sym, SymbolName);
1096+
return RelSymbol<ELFT>(Sym, SymbolName);
10911097
}
10921098

10931099
static std::string maybeDemangle(StringRef Name) {
@@ -3623,14 +3629,14 @@ template <class RelTy>
36233629
void GNUStyle<ELFT>::printRelRelaReloc(const RelTy &R, unsigned RelIndex,
36243630
const Elf_Shdr &Sec,
36253631
const Elf_Shdr *SymTab) {
3626-
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
3632+
Expected<RelSymbol<ELFT>> Target =
36273633
this->dumper()->getRelocationTarget(SymTab, R);
36283634
if (!Target)
36293635
this->reportUniqueWarning(createError(
36303636
"unable to print relocation " + Twine(RelIndex) + " in " +
36313637
describe(this->Obj, Sec) + ": " + toString(Target.takeError())));
36323638
else
3633-
printRelRelaReloc(/*Sym=*/Target->first, /*Name=*/Target->second, R);
3639+
printRelRelaReloc(R, *Target);
36343640
}
36353641

36363642
template <class ELFT>
@@ -3645,8 +3651,8 @@ static Optional<int64_t> getAddend(const typename ELFT::Rel &) {
36453651

36463652
template <class ELFT>
36473653
template <class RelTy>
3648-
void GNUStyle<ELFT>::printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName,
3649-
const RelTy &R) {
3654+
void GNUStyle<ELFT>::printRelRelaReloc(const RelTy &R,
3655+
const RelSymbol<ELFT> &RelSym) {
36503656
// First two fields are bit width dependent. The rest of them are fixed width.
36513657
unsigned Bias = ELFT::Is64Bits ? 8 : 0;
36523658
Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias};
@@ -3659,17 +3665,18 @@ void GNUStyle<ELFT>::printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName,
36593665
this->Obj.getRelocationTypeName(R.getType(this->Obj.isMips64EL()), RelocName);
36603666
Fields[2].Str = RelocName.c_str();
36613667

3662-
if (Sym)
3663-
Fields[3].Str = to_string(format_hex_no_prefix(Sym->getValue(), Width));
3668+
if (RelSym.Sym)
3669+
Fields[3].Str =
3670+
to_string(format_hex_no_prefix(RelSym.Sym->getValue(), Width));
36643671

3665-
Fields[4].Str = std::string(SymbolName);
3672+
Fields[4].Str = std::string(RelSym.Name);
36663673
for (const Field &F : Fields)
36673674
printField(F);
36683675

36693676
std::string Addend;
36703677
if (Optional<int64_t> A = getAddend<ELFT>(R)) {
36713678
int64_t RelAddend = *A;
3672-
if (!SymbolName.empty()) {
3679+
if (!RelSym.Name.empty()) {
36733680
if (RelAddend < 0) {
36743681
Addend = " - ";
36753682
RelAddend = std::abs(RelAddend);
@@ -4349,10 +4356,6 @@ template <class ELFT> void GNUStyle<ELFT>::printSectionMapping() {
43494356
}
43504357

43514358
namespace {
4352-
template <class ELFT> struct RelSymbol {
4353-
const typename ELFT::Sym *Sym;
4354-
std::string Name;
4355-
};
43564359

43574360
template <class ELFT, class RelTy>
43584361
RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
@@ -4394,9 +4397,8 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
43944397
template <class ELFT>
43954398
template <class RelTy>
43964399
void GNUStyle<ELFT>::printDynamicRelocation(const RelTy &R) {
4397-
RelSymbol<ELFT> S =
4398-
getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R);
4399-
printRelRelaReloc(S.Sym, S.Name, R);
4400+
printRelRelaReloc(
4401+
R, getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R));
44004402
}
44014403

44024404
template <class ELFT>
@@ -6169,7 +6171,7 @@ template <class RelTy>
61696171
void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex,
61706172
const Elf_Shdr &Sec,
61716173
const Elf_Shdr *SymTab) {
6172-
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
6174+
Expected<RelSymbol<ELFT>> Target =
61736175
this->dumper()->getRelocationTarget(SymTab, Rel);
61746176
if (!Target) {
61756177
this->reportUniqueWarning(createError(
@@ -6178,7 +6180,7 @@ void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex,
61786180
return;
61796181
}
61806182

6181-
std::string TargetName = Target->second;
6183+
std::string TargetName = Target->Name;
61826184
SmallString<32> RelocName;
61836185
this->Obj.getRelocationTypeName(Rel.getType(this->Obj.isMips64EL()),
61846186
RelocName);

0 commit comments

Comments
 (0)