[PATCH] D55329: [llvm-readobj] Little clean up inside `parseDynamicTable`
Xing via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 5 07:53:14 PST 2018
Higuoxing created this revision.
Higuoxing added reviewers: rupprecht, jhenderson.
Herald added a subscriber: llvm-commits.
This anoymous function actually has same logic with `Obj->toMappedAddr`.
Besides, I have a question on resolving illegal value. `gnu-readelf`, `gnu-objdump` and `llvm-objdump` could parse the test file 'test/tools/llvm-objdump/Inputs/private-headers-x86_64.elf', but `llvm-readobj` will fail when parse `DT_RELR` segment. Because, the value is 0x87654321 which is illegal. So, shall we do this clean up rather then remove the checking statements?
if (Delta >= Phdr.p_filesz)
return createError("Virtual address is not in any segment");
Repository:
rL LLVM
https://reviews.llvm.org/D55329
Files:
tools/llvm-readobj/ELFDumper.cpp
Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -1484,19 +1484,10 @@
void ELFDumper<ELFT>::parseDynamicTable(
ArrayRef<const Elf_Phdr *> LoadSegments) {
auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
- const Elf_Phdr *const *I =
- std::upper_bound(LoadSegments.begin(), LoadSegments.end(), VAddr,
- [](uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
- return VAddr < Phdr->p_vaddr;
- });
- if (I == LoadSegments.begin())
- report_fatal_error("Virtual address is not in any segment");
- --I;
- const Elf_Phdr &Phdr = **I;
- uint64_t Delta = VAddr - Phdr.p_vaddr;
- if (Delta >= Phdr.p_filesz)
- report_fatal_error("Virtual address is not in any segment");
- return Obj->base() + Phdr.p_offset + Delta;
+ auto MappedAddrOrError = Obj->toMappedAddr(VAddr);
+ if (!MappedAddrOrError)
+ report_fatal_error(MappedAddrOrError.takeError());
+ return MappedAddrOrError.get();
};
uint64_t SONameOffset = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55329.176829.patch
Type: text/x-patch
Size: 1194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181205/63ba1309/attachment.bin>
More information about the llvm-commits
mailing list