[PATCH] D48554: Handle absolute symbols as branch targets in disassembly.
Sterling Augustine via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 25 11:10:04 PDT 2018
saugustine created this revision.
Herald added a subscriber: llvm-commits.
Certain tests and embedded systems use sectionless symbols
as the target of branches or calls. Handle them in the disassembly.
Repository:
rL LLVM
https://reviews.llvm.org/D48554
Files:
test/tools/llvm-objdump/Inputs/call-absolute-symbol.elf-x86_64
tools/llvm-objdump/llvm-objdump.cpp
Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -1323,6 +1323,7 @@
// Create a mapping from virtual address to symbol name. This is used to
// pretty print the symbols while disassembling.
std::map<SectionRef, SectionSymbolsTy> AllSymbols;
+ SectionSymbolsTy AbsoluteSymbols;
for (const SymbolRef &Symbol : Obj->symbols()) {
Expected<uint64_t> AddressOrErr = Symbol.getAddress();
if (!AddressOrErr)
@@ -1338,15 +1339,17 @@
Expected<section_iterator> SectionOrErr = Symbol.getSection();
if (!SectionOrErr)
report_error(Obj->getFileName(), SectionOrErr.takeError());
- section_iterator SecI = *SectionOrErr;
- if (SecI == Obj->section_end())
- continue;
uint8_t SymbolType = ELF::STT_NOTYPE;
if (Obj->isELF())
SymbolType = getElfSymbolType(Obj, Symbol);
- AllSymbols[*SecI].emplace_back(Address, *Name, SymbolType);
+ section_iterator SecI = *SectionOrErr;
+ if (SecI != Obj->section_end())
+ AllSymbols[*SecI].emplace_back(Address, *Name, SymbolType);
+ else
+ AbsoluteSymbols.emplace_back(Address, *Name, SymbolType);
+
}
if (AllSymbols.empty() && Obj->isELF())
@@ -1382,13 +1385,16 @@
if (Sec != SectionAddresses.end())
AllSymbols[Sec->second].emplace_back(VA, Name, ELF::STT_NOTYPE);
+ else
+ AbsoluteSymbols.emplace_back(VA, Name, ELF::STT_NOTYPE);
}
}
// Sort all the symbols, this allows us to use a simple binary search to find
// a symbol near an address.
for (std::pair<const SectionRef, SectionSymbolsTy> &SecSyms : AllSymbols)
array_pod_sort(SecSyms.second.begin(), SecSyms.second.end());
+ array_pod_sort(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
if (!DisassembleAll && (!Section.isText() || Section.isVirtual()))
@@ -1708,24 +1714,32 @@
}
// Find the first symbol in the section whose offset is less than
- // or equal to the target.
- if (TargetSectionSymbols) {
- auto TargetSym = std::upper_bound(
- TargetSectionSymbols->begin(), TargetSectionSymbols->end(),
+ // or equal to the target. If there isn't a section that contains
+ // the target, find the nearest preceding absolute symbol.
+ auto TargetSym = std::upper_bound(
+ TargetSectionSymbols->begin(), TargetSectionSymbols->end(),
+ Target, [](uint64_t LHS,
+ const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
+ return LHS < std::get<0>(RHS);
+ });
+ if (TargetSym == TargetSectionSymbols->begin()) {
+ TargetSym = std::upper_bound(
+ AbsoluteSymbols.begin(), AbsoluteSymbols.end(),
Target, [](uint64_t LHS,
const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
- return LHS < std::get<0>(RHS);
- });
- if (TargetSym != TargetSectionSymbols->begin()) {
- --TargetSym;
- uint64_t TargetAddress = std::get<0>(*TargetSym);
- StringRef TargetName = std::get<1>(*TargetSym);
- outs() << " <" << TargetName;
- uint64_t Disp = Target - TargetAddress;
- if (Disp)
- outs() << "+0x" << Twine::utohexstr(Disp);
- outs() << '>';
- }
+ return LHS < std::get<0>(RHS);
+ });
+ }
+
+ if (TargetSym != TargetSectionSymbols->begin()) {
+ --TargetSym;
+ uint64_t TargetAddress = std::get<0>(*TargetSym);
+ StringRef TargetName = std::get<1>(*TargetSym);
+ outs() << " <" << TargetName;
+ uint64_t Disp = Target - TargetAddress;
+ if (Disp)
+ outs() << "+0x" << Twine::utohexstr(Disp);
+ outs() << '>';
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48554.152729.patch
Type: text/x-patch
Size: 4237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180625/8d35fa82/attachment.bin>
More information about the llvm-commits
mailing list