@@ -114,6 +114,13 @@ namespace {
114
114
115
115
template <class ELFT > class DumpStyle ;
116
116
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
+
117
124
// / Represents a contiguous uniform range in the file. We cannot just create a
118
125
// / range directly because when creating one of these from the .dynamic table
119
126
// / the size, entity size and virtual address are different entries in arbitrary
@@ -364,8 +371,8 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
364
371
getVersionDependencies (const Elf_Shdr *Sec) const ;
365
372
366
373
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 ;
369
376
370
377
std::function<Error(const Twine &Msg)> WarningHandler;
371
378
void reportUniqueWarning (Error Err) const ;
@@ -873,8 +880,7 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
873
880
void printRelRelaReloc (const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec,
874
881
const Elf_Shdr *SymTab);
875
882
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);
878
884
void printSymbol (const Elf_Sym *Symbol, const Elf_Sym *First,
879
885
Optional<StringRef> StrTable, bool IsDynamic,
880
886
bool NonVisibilityBitsUsed) override ;
@@ -1053,7 +1059,7 @@ Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym *Sym,
1053
1059
1054
1060
template <typename ELFT>
1055
1061
template <class RelTy >
1056
- Expected<std::pair< const typename ELFT::Sym *, std::string >>
1062
+ Expected<RelSymbol< ELFT>>
1057
1063
ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
1058
1064
const RelTy &R) const {
1059
1065
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
@@ -1062,7 +1068,7 @@ ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
1062
1068
return SymOrErr.takeError ();
1063
1069
const Elf_Sym *Sym = *SymOrErr;
1064
1070
if (!Sym)
1065
- return std::make_pair (nullptr , " " );
1071
+ return RelSymbol<ELFT> (nullptr , " " );
1066
1072
1067
1073
// The st_name field of a STT_SECTION is usually 0 (empty string).
1068
1074
// This code block returns the section name.
@@ -1073,12 +1079,12 @@ ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
1073
1079
return SecOrErr.takeError ();
1074
1080
// A section symbol describes the section at index 0.
1075
1081
if (*SecOrErr == nullptr )
1076
- return std::make_pair (Sym, " " );
1082
+ return RelSymbol<ELFT> (Sym, " " );
1077
1083
1078
1084
Expected<StringRef> NameOrErr = Obj->getSectionName (*SecOrErr);
1079
1085
if (!NameOrErr)
1080
1086
return NameOrErr.takeError ();
1081
- return std::make_pair (Sym, NameOrErr->str ());
1087
+ return RelSymbol<ELFT> (Sym, NameOrErr->str ());
1082
1088
}
1083
1089
1084
1090
Expected<StringRef> StrTableOrErr = Obj->getStringTableForSymtab (*SymTab);
@@ -1087,7 +1093,7 @@ ELFDumper<ELFT>::getRelocationTarget(const Elf_Shdr *SymTab,
1087
1093
1088
1094
std::string SymbolName =
1089
1095
getFullSymbolName (Sym, *StrTableOrErr, SymTab->sh_type == SHT_DYNSYM);
1090
- return std::make_pair (Sym, SymbolName);
1096
+ return RelSymbol<ELFT> (Sym, SymbolName);
1091
1097
}
1092
1098
1093
1099
static std::string maybeDemangle (StringRef Name) {
@@ -3623,14 +3629,14 @@ template <class RelTy>
3623
3629
void GNUStyle<ELFT>::printRelRelaReloc(const RelTy &R, unsigned RelIndex,
3624
3630
const Elf_Shdr &Sec,
3625
3631
const Elf_Shdr *SymTab) {
3626
- Expected<std::pair< const typename ELFT::Sym *, std::string >> Target =
3632
+ Expected<RelSymbol< ELFT>> Target =
3627
3633
this ->dumper ()->getRelocationTarget (SymTab, R);
3628
3634
if (!Target)
3629
3635
this ->reportUniqueWarning (createError (
3630
3636
" unable to print relocation " + Twine (RelIndex) + " in " +
3631
3637
describe (this ->Obj , Sec) + " : " + toString (Target.takeError ())));
3632
3638
else
3633
- printRelRelaReloc (/* Sym= */ Target-> first , /* Name= */ Target-> second , R );
3639
+ printRelRelaReloc (R, * Target);
3634
3640
}
3635
3641
3636
3642
template <class ELFT >
@@ -3645,8 +3651,8 @@ static Optional<int64_t> getAddend(const typename ELFT::Rel &) {
3645
3651
3646
3652
template <class ELFT >
3647
3653
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 ) {
3650
3656
// First two fields are bit width dependent. The rest of them are fixed width.
3651
3657
unsigned Bias = ELFT::Is64Bits ? 8 : 0 ;
3652
3658
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,
3659
3665
this ->Obj .getRelocationTypeName (R.getType (this ->Obj .isMips64EL ()), RelocName);
3660
3666
Fields[2 ].Str = RelocName.c_str ();
3661
3667
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));
3664
3671
3665
- Fields[4 ].Str = std::string (SymbolName );
3672
+ Fields[4 ].Str = std::string (RelSym. Name );
3666
3673
for (const Field &F : Fields)
3667
3674
printField (F);
3668
3675
3669
3676
std::string Addend;
3670
3677
if (Optional<int64_t > A = getAddend<ELFT>(R)) {
3671
3678
int64_t RelAddend = *A;
3672
- if (!SymbolName .empty ()) {
3679
+ if (!RelSym. Name .empty ()) {
3673
3680
if (RelAddend < 0 ) {
3674
3681
Addend = " - " ;
3675
3682
RelAddend = std::abs (RelAddend);
@@ -4349,10 +4356,6 @@ template <class ELFT> void GNUStyle<ELFT>::printSectionMapping() {
4349
4356
}
4350
4357
4351
4358
namespace {
4352
- template <class ELFT > struct RelSymbol {
4353
- const typename ELFT::Sym *Sym;
4354
- std::string Name;
4355
- };
4356
4359
4357
4360
template <class ELFT , class RelTy >
4358
4361
RelSymbol<ELFT> getSymbolForReloc (const ELFFile<ELFT> &Obj, StringRef FileName,
@@ -4394,9 +4397,8 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
4394
4397
template <class ELFT >
4395
4398
template <class RelTy >
4396
4399
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));
4400
4402
}
4401
4403
4402
4404
template <class ELFT >
@@ -6169,7 +6171,7 @@ template <class RelTy>
6169
6171
void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex,
6170
6172
const Elf_Shdr &Sec,
6171
6173
const Elf_Shdr *SymTab) {
6172
- Expected<std::pair< const typename ELFT::Sym *, std::string >> Target =
6174
+ Expected<RelSymbol< ELFT>> Target =
6173
6175
this ->dumper ()->getRelocationTarget (SymTab, Rel);
6174
6176
if (!Target) {
6175
6177
this ->reportUniqueWarning (createError (
@@ -6178,7 +6180,7 @@ void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex,
6178
6180
return ;
6179
6181
}
6180
6182
6181
- std::string TargetName = Target->second ;
6183
+ std::string TargetName = Target->Name ;
6182
6184
SmallString<32 > RelocName;
6183
6185
this ->Obj .getRelocationTypeName (Rel.getType (this ->Obj .isMips64EL ()),
6184
6186
RelocName);
0 commit comments