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,
// The section VirtualAddress does not include ImageBase, and we want to
// return virtual addresses.
- Result += getImageBase().get();
+ Result += getImageBase();
return Result;
}
// The section VirtualAddress does not include ImageBase, and we want to
// return virtual addresses.
- Result += getImageBase().get();
+ Result += getImageBase();
return Result;
}
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);
+++ /dev/null
-0x5009
-0x5038
-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
+++ /dev/null
-0x401000
-0x401010
-0x401070
-0x401030
-0x401040
-0x401050
-0x401060
-0x500000
-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
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;
}