Skip to content

Commit 71ba852

Browse files
authored
[symbolizer] Address starting with a plus sign is valid. (#135857)
this is also the same behaviour in `gnu addr2line`. The change only applies if the binary is llvm-addr2line --------- Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
1 parent 3745e05 commit 71ba852

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/test/tools/llvm-symbolizer/symbol-search.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-pr
6666

6767
# If '+' is not preceded by a symbol, it is part of a symbol name, not an offset separator.
6868
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=NONEXISTENT %s
69-
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=NONEXISTENT %s
69+
# in addr2line address starting with a `+` sign is a valid address
70+
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=CODE-CMD %s
7071

7172
# Show that C++ mangled names may be specified.
7273
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so _ZL14static_func_01i | FileCheck --check-prefix=MULTI-CXX %s

llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,12 @@ static Error parseCommand(StringRef BinaryName, bool IsAddr2Line,
238238
bool StartsWithDigit = std::isdigit(AddrSpec.front());
239239

240240
// GNU addr2line assumes the address is hexadecimal and allows a redundant
241-
// "0x" or "0X" prefix; do the same for compatibility.
242-
if (IsAddr2Line)
243-
AddrSpec.consume_front("0x") || AddrSpec.consume_front("0X");
241+
// "0x" or "0X" prefix or with an optional `+` sign; do the same for
242+
// compatibility.
243+
if (IsAddr2Line) {
244+
AddrSpec.consume_front_insensitive("0x") ||
245+
AddrSpec.consume_front_insensitive("+0x");
246+
}
244247

245248
// If address specification is a number, treat it as a module offset.
246249
if (!AddrSpec.getAsInteger(IsAddr2Line ? 16 : 0, Offset)) {

0 commit comments

Comments
 (0)