forked from OSchip/llvm-project
Address review comments, remove error case and return 0 instead as required by tests
llvm-svn: 249785
This commit is contained in:
parent
e94fef7b3d
commit
21427ada3e
|
@ -773,7 +773,7 @@ public:
|
|||
std::error_code getSectionContents(const coff_section *Sec,
|
||||
ArrayRef<uint8_t> &Res) const;
|
||||
|
||||
ErrorOr<uint64_t> getImageBase() const;
|
||||
uint64_t getImageBase() const;
|
||||
std::error_code getVaPtr(uint64_t VA, uintptr_t &Res) const;
|
||||
std::error_code getRvaPtr(uint32_t Rva, uintptr_t &Res) const;
|
||||
std::error_code getHintName(uint32_t Rva, uint16_t &Hint,
|
||||
|
|
|
@ -174,7 +174,7 @@ ErrorOr<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const {
|
|||
|
||||
// The section VirtualAddress does not include ImageBase, and we want to
|
||||
// return virtual addresses.
|
||||
Result += getImageBase().get();
|
||||
Result += getImageBase();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ uint64_t COFFObjectFile::getSectionAddress(DataRefImpl Ref) const {
|
|||
|
||||
// The section VirtualAddress does not include ImageBase, and we want to
|
||||
// return virtual addresses.
|
||||
Result += getImageBase().get();
|
||||
Result += getImageBase();
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
@ -418,17 +418,18 @@ std::error_code COFFObjectFile::initSymbolTablePtr() {
|
|||
return std::error_code();
|
||||
}
|
||||
|
||||
ErrorOr<uint64_t> COFFObjectFile::getImageBase() const {
|
||||
uint64_t COFFObjectFile::getImageBase() const {
|
||||
if (PE32Header)
|
||||
return uint64_t(PE32Header->ImageBase);
|
||||
return PE32Header->ImageBase;
|
||||
else if (PE32PlusHeader)
|
||||
return uint64_t(PE32PlusHeader->ImageBase);
|
||||
return object_error::parse_failed;
|
||||
return PE32PlusHeader->ImageBase;
|
||||
// This actually comes up in practice.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Returns the file offset for the given VA.
|
||||
std::error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const {
|
||||
uint64_t ImageBase = getImageBase().get();
|
||||
uint64_t ImageBase = getImageBase();
|
||||
uint64_t Rva = Addr - ImageBase;
|
||||
assert(Rva <= UINT32_MAX);
|
||||
return getRvaPtr((uint32_t)Rva, Res);
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
0x5009
|
||||
0x5038
|
|
@ -1,5 +1,9 @@
|
|||
RUN: llvm-symbolizer --inlining --relative-address -obj="%p/Inputs/coff-dwarf.exe" \
|
||||
RUN: < %p/Inputs/coff-dwarf.input | FileCheck %s
|
||||
RUN: grep '^ADDR:' %s | sed -s 's/ADDR: //' \
|
||||
RUN: | llvm-symbolizer --inlining --relative-address -obj="%p/Inputs/coff-dwarf.exe" \
|
||||
RUN: | FileCheck %s
|
||||
|
||||
ADDR: 0x5009
|
||||
ADDR: 0x5038
|
||||
|
||||
CHECK: foo(void)
|
||||
CHECK: coff-dwarf.cpp:7
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
0x401000
|
||||
0x401010
|
||||
0x401070
|
||||
0x401030
|
||||
0x401040
|
||||
0x401050
|
||||
0x401060
|
||||
0x500000
|
|
@ -1,18 +1,27 @@
|
|||
RUN: llvm-symbolizer -obj="%p/Inputs/test.exe" < "%p/Inputs/test.exe.input" | \
|
||||
RUN: FileCheck %s --check-prefix=CHECK
|
||||
RUN: llvm-symbolizer -obj="%p/Inputs/test.exe" < "%p/Inputs/test.exe.input" | \
|
||||
RUN: FileCheck %s --check-prefix=CHECK
|
||||
RUN: llvm-symbolizer -obj="%p/Inputs/test.exe" -demangle=false < \
|
||||
RUN: "%p/Inputs/test.exe.input" | FileCheck %s --check-prefix=CHECK-NO-DEMANGLE
|
||||
RUN: grep '^ADDR:' %s | sed -s 's/ADDR: //' \
|
||||
RUN: | llvm-symbolizer -obj="%p/Inputs/test.exe" \
|
||||
RUN: | FileCheck %s --check-prefix=CHECK
|
||||
RUN: grep '^ADDR:' %s | sed -s 's/ADDR: //' \
|
||||
RUN: | llvm-symbolizer -obj="%p/Inputs/test.exe" -demangle=false \
|
||||
RUN: | FileCheck %s --check-prefix=CHECK-NO-DEMANGLE
|
||||
|
||||
Subtract ImageBase from all the offsets and run the test again with
|
||||
--relative-address.
|
||||
|
||||
RUN: python -c 'import sys;print "\n".join([hex(int(x, 16) - 0x400000) for x in sys.stdin])' \
|
||||
RUN: < %p/Inputs/test.exe.input \
|
||||
RUN: grep '^ADDR:' %s | sed -s 's/ADDR: //' \
|
||||
RUN: | python -c 'import sys;print "\n".join([hex(int(x, 16) - 0x400000) for x in sys.stdin])' \
|
||||
RUN: | llvm-symbolizer -obj="%p/Inputs/test.exe" -demangle=false --relative-address \
|
||||
RUN: | FileCheck %s --check-prefix=CHECK-NO-DEMANGLE
|
||||
|
||||
ADDR: 0x401000
|
||||
ADDR: 0x401010
|
||||
ADDR: 0x401070
|
||||
ADDR: 0x401030
|
||||
ADDR: 0x401040
|
||||
ADDR: 0x401050
|
||||
ADDR: 0x401060
|
||||
ADDR: 0x500000
|
||||
|
||||
CHECK: foo(void)
|
||||
CHECK-NEXT: test.cpp:10
|
||||
CHECK: main
|
||||
|
|
|
@ -128,8 +128,7 @@ bool ModuleInfo::isWin32Module() const {
|
|||
|
||||
uint64_t ModuleInfo::getModulePreferredBase() const {
|
||||
if (auto *CoffObject = dyn_cast<COFFObjectFile>(Module))
|
||||
if (auto Base = CoffObject->getImageBase())
|
||||
return Base.get();
|
||||
return CoffObject->getImageBase();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue