1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[llvm-symbolizer] Add switch to adjust addresses by fixed offset

If a stack trace or similar has a list of addresses from an executable
or DSO loaded at a variable address (e.g. due to ASLR), the addresses
will not directly correspond to the addresses stored in the object file.
If a user wishes to use llvm-symbolizer, they have to subtract the load
address from every address. This is somewhat inconvenient, especially as
the output of --print-address will result in the adjusted address being
listed, rather than the address coming from the stack trace, making it
harder to map results between the two.

This change adds a new switch to llvm-symbolizer --adjust-vma which
takes an offset, which is then used to automatically do this
calculation. The printed address remains the input address (allowing for
easy mapping), whilst the specified offset is applied to the addresses
when performing the lookup.

The switch is conceptually similar to llvm-objdump's new switch of the
same name (see D57051), which in turn mirrors a GNU switch. There is no
equivalent switch in addr2line.

Reviewed by: grimar

Differential Revision: https://reviews.llvm.org/D57151

llvm-svn: 352195
This commit is contained in:
James Henderson 2019-01-25 11:49:21 +00:00
parent 7de83f3ceb
commit 011ee92bbc
3 changed files with 51 additions and 0 deletions

View File

@ -123,6 +123,12 @@ OPTIONS
Strip directories when printing the file path.
.. option:: -adjust-vma=<offset>
Add the specified offset to object file addresses when performing lookups. This
can be used to simplify lookups when the object is not loaded at a dynamically
relocated address.
EXIT STATUS
-----------

View File

@ -0,0 +1,39 @@
# REQUIRES: x86-registered-target
.type foo,@function
.size foo,12
foo:
.space 10
nop
nop
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -g
# RUN: llvm-symbolizer 0xa 0xb --print-address --obj=%t.o \
# RUN: | FileCheck %s --check-prefix=NORMAL
# RUN: llvm-symbolizer 0x10a 0x10b --print-address --adjust-vma 0x100 --obj=%t.o \
# RUN: | FileCheck %s --check-prefix=ADJUST
# Show that we can handle addresses less than the offset.
# RUN: llvm-symbolizer 0xa 0xb --print-address --adjust-vma 0xc --obj=%t.o \
# RUN: | FileCheck %s --check-prefix=OVERFLOW
# NORMAL: 0xa
# NORMAL-NEXT: foo
# NORMAL-NEXT: adjust-vma.s:7:0
# NORMAL-EMPTY:
# NORMAL-NEXT: 0xb
# NORMAL-NEXT: foo
# NORMAL-NEXT: adjust-vma.s:8:0
# ADJUST: 0x10a
# ADJUST-NEXT: foo
# ADJUST-NEXT: adjust-vma.s:7:0
# ADJUST-EMPTY:
# ADJUST-NEXT: 0x10b
# ADJUST-NEXT: foo
# ADJUST-NEXT: adjust-vma.s:8:0
# OVERFLOW: 0xa
# OVERFLOW-NEXT: ??
# OVERFLOW-NEXT: ??

View File

@ -134,6 +134,11 @@ static cl::opt<int> ClPrintSourceContextLines(
static cl::opt<bool> ClVerbose("verbose", cl::init(false),
cl::desc("Print verbose line info"));
// -adjust-vma
static cl::opt<unsigned long long>
ClAdjustVMA("adjust-vma", cl::init(0), cl::value_desc("offset"),
cl::desc("Add specified offset to object file addresses"));
static cl::list<std::string> ClInputAddresses(cl::Positional,
cl::desc("<input addresses>..."),
cl::ZeroOrMore);
@ -201,6 +206,7 @@ static void symbolizeInput(StringRef InputString, LLVMSymbolizer &Symbolizer,
StringRef Delimiter = ClPrettyPrint ? ": " : "\n";
outs() << Delimiter;
}
ModuleOffset -= ClAdjustVMA;
if (IsData) {
auto ResOrErr = Symbolizer.symbolizeData(ModuleName, ModuleOffset);
Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get());