Skip to content

[symbolizer] Address starting with a plus sign is valid. #135857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/test/tools/llvm-symbolizer/symbol-search.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-pr

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: comments should use a capital letter and trailing full stop.

RUN: llvm-addr2line --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=CODE-CMD %s

# Show that C++ mangled names may be specified.
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so _ZL14static_func_01i | FileCheck --check-prefix=MULTI-CXX %s
Expand Down
9 changes: 6 additions & 3 deletions llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,12 @@ static Error parseCommand(StringRef BinaryName, bool IsAddr2Line,
bool StartsWithDigit = std::isdigit(AddrSpec.front());

// GNU addr2line assumes the address is hexadecimal and allows a redundant
// "0x" or "0X" prefix; do the same for compatibility.
if (IsAddr2Line)
AddrSpec.consume_front("0x") || AddrSpec.consume_front("0X");
// "0x" or "0X" prefix or with an optional `+` sign; do the same for
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete "with" from this comment.

// compatibility.
if (IsAddr2Line) {
AddrSpec.consume_front_insensitive("0x") ||
AddrSpec.consume_front_insensitive("+0x");
}

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