Skip to content

Commit 3335f25

Browse files
committed
Reland r351529 "[llvm-objdump][NFC] Improve readability."
`SectionSymbol*` is cast from `void*` to `std::tuple<uint64_t, StringRef, uint8_t>` in AMDGPUSymbolizer, so it has to *be* one, not *act like* one. llvm-svn: 351553
1 parent d2c733b commit 3335f25

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,18 @@ cl::alias DisassembleZeroesShort("z",
279279

280280
static StringRef ToolName;
281281

282-
typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
282+
namespace {
283+
struct SectionSymbol : public std::tuple<uint64_t, StringRef, uint8_t> {
284+
SectionSymbol(uint64_t Address, StringRef Name, uint8_t Type)
285+
: std::tuple<uint64_t, StringRef, uint8_t>(Address, Name, Type) {}
286+
287+
uint64_t Address() const { return std::get<0>(*this); }
288+
StringRef Name() const { return std::get<1>(*this); }
289+
uint8_t Type() const { return std::get<2>(*this); }
290+
};
291+
292+
typedef std::vector<SectionSymbol> SectionSymbolsTy;
293+
} // namespace
283294

284295
SectionFilter llvm::ToolSectionFilter(llvm::object::ObjectFile const &O) {
285296
return SectionFilter(
@@ -1035,8 +1046,8 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
10351046
std::vector<uint64_t> TextMappingSymsAddr;
10361047
if (isArmElf(Obj)) {
10371048
for (const auto &Symb : Symbols) {
1038-
uint64_t Address = std::get<0>(Symb);
1039-
StringRef Name = std::get<1>(Symb);
1049+
uint64_t Address = Symb.Address();
1050+
StringRef Name = Symb.Name();
10401051
if (Name.startswith("$d"))
10411052
DataMappingSymsAddr.push_back(Address - SectionAddr);
10421053
if (Name.startswith("$x"))
@@ -1085,11 +1096,11 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
10851096
error(Section.getName(SectionName));
10861097

10871098
// If the section has no symbol at the start, just insert a dummy one.
1088-
if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) {
1099+
if (Symbols.empty() || Symbols[0].Address() != 0) {
10891100
Symbols.insert(
10901101
Symbols.begin(),
1091-
std::make_tuple(SectionAddr, SectionName,
1092-
Section.isText() ? ELF::STT_FUNC : ELF::STT_OBJECT));
1102+
SectionSymbol(SectionAddr, SectionName,
1103+
Section.isText() ? ELF::STT_FUNC : ELF::STT_OBJECT));
10931104
}
10941105

10951106
SmallString<40> Comments;
@@ -1108,12 +1119,11 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
11081119
std::vector<RelocationRef>::const_iterator RelEnd = Rels.end();
11091120
// Disassemble symbol by symbol.
11101121
for (unsigned SI = 0, SE = Symbols.size(); SI != SE; ++SI) {
1111-
uint64_t Start = std::get<0>(Symbols[SI]) - SectionAddr;
1122+
uint64_t Start = Symbols[SI].Address() - SectionAddr;
11121123
// The end is either the section end or the beginning of the next
11131124
// symbol.
1114-
uint64_t End = (SI == SE - 1)
1115-
? SectSize
1116-
: std::get<0>(Symbols[SI + 1]) - SectionAddr;
1125+
uint64_t End =
1126+
(SI == SE - 1) ? SectSize : Symbols[SI + 1].Address() - SectionAddr;
11171127
// Don't try to disassemble beyond the end of section contents.
11181128
if (End > SectSize)
11191129
End = SectSize;
@@ -1129,8 +1139,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
11291139
}
11301140

11311141
/// Skip if user requested specific symbols and this is not in the list
1132-
if (!DisasmFuncsSet.empty() &&
1133-
!DisasmFuncsSet.count(std::get<1>(Symbols[SI])))
1142+
if (!DisasmFuncsSet.empty() && !DisasmFuncsSet.count(Symbols[SI].Name()))
11341143
continue;
11351144

11361145
if (!PrintedSection) {
@@ -1146,12 +1155,12 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
11461155
End = StopAddress - SectionAddr;
11471156

11481157
if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
1149-
if (std::get<2>(Symbols[SI]) == ELF::STT_AMDGPU_HSA_KERNEL) {
1158+
if (Symbols[SI].Type() == ELF::STT_AMDGPU_HSA_KERNEL) {
11501159
// skip amd_kernel_code_t at the begining of kernel symbol (256 bytes)
11511160
Start += 256;
11521161
}
11531162
if (SI == SE - 1 ||
1154-
std::get<2>(Symbols[SI + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) {
1163+
Symbols[SI + 1].Type() == ELF::STT_AMDGPU_HSA_KERNEL) {
11551164
// cut trailing zeroes at the end of kernel
11561165
// cut up to 256 bytes
11571166
const uint64_t EndAlign = 256;
@@ -1166,7 +1175,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
11661175
if (!NoLeadingAddr)
11671176
outs() << format("%016" PRIx64 " ", SectionAddr + Start);
11681177

1169-
StringRef SymbolName = std::get<1>(Symbols[SI]);
1178+
StringRef SymbolName = Symbols[SI].Name();
11701179
if (Demangle)
11711180
outs() << demangle(SymbolName) << ":\n";
11721181
else
@@ -1204,7 +1213,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
12041213
// same section. We rely on the markers introduced to
12051214
// understand what we need to dump. If the data marker is within a
12061215
// function, it is denoted as a word/short etc
1207-
if (isArmElf(Obj) && std::get<2>(Symbols[SI]) != ELF::STT_OBJECT &&
1216+
if (isArmElf(Obj) && Symbols[SI].Type() != ELF::STT_OBJECT &&
12081217
!DisassembleAll) {
12091218
uint64_t Stride = 0;
12101219

@@ -1268,7 +1277,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
12681277
// disassembling text (applicable all architectures),
12691278
// we are in a situation where we must print the data and not
12701279
// disassemble it.
1271-
if (Obj->isELF() && std::get<2>(Symbols[SI]) == ELF::STT_OBJECT &&
1280+
if (Obj->isELF() && Symbols[SI].Type() == ELF::STT_OBJECT &&
12721281
!DisassembleAll && Section.isText()) {
12731282
// print out data up to 8 bytes at a time in hex and ascii
12741283
uint8_t AsciiData[9] = {'\0'};
@@ -1365,25 +1374,21 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
13651374
// the target, find the nearest preceding absolute symbol.
13661375
auto TargetSym = std::upper_bound(
13671376
TargetSectionSymbols->begin(), TargetSectionSymbols->end(),
1368-
Target, [](uint64_t LHS,
1369-
const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1370-
return LHS < std::get<0>(RHS);
1377+
Target, [](uint64_t LHS, const SectionSymbol &RHS) {
1378+
return LHS < RHS.Address();
13711379
});
13721380
if (TargetSym == TargetSectionSymbols->begin()) {
13731381
TargetSectionSymbols = &AbsoluteSymbols;
13741382
TargetSym = std::upper_bound(
1375-
AbsoluteSymbols.begin(), AbsoluteSymbols.end(),
1376-
Target, [](uint64_t LHS,
1377-
const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1378-
return LHS < std::get<0>(RHS);
1379-
});
1383+
AbsoluteSymbols.begin(), AbsoluteSymbols.end(), Target,
1384+
[](uint64_t LHS, const SectionSymbol &RHS) {
1385+
return LHS < RHS.Address();
1386+
});
13801387
}
13811388
if (TargetSym != TargetSectionSymbols->begin()) {
13821389
--TargetSym;
1383-
uint64_t TargetAddress = std::get<0>(*TargetSym);
1384-
StringRef TargetName = std::get<1>(*TargetSym);
1385-
outs() << " <" << TargetName;
1386-
uint64_t Disp = Target - TargetAddress;
1390+
outs() << " <" << TargetSym->Name();
1391+
uint64_t Disp = Target - TargetSym->Address();
13871392
if (Disp)
13881393
outs() << "+0x" << Twine::utohexstr(Disp);
13891394
outs() << '>';

0 commit comments

Comments
 (0)