-
Notifications
You must be signed in to change notification settings - Fork 14k
[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
Conversation
@llvm/pr-subscribers-llvm-binary-utilities Author: Ebuka Ezike (da-viper) Changesthis is also the same behaviour in depends on #135856 Full diff: https://github.com/llvm/llvm-project/pull/135857.diff 2 Files Affected:
diff --git a/llvm/test/tools/llvm-symbolizer/symbol-search.test b/llvm/test/tools/llvm-symbolizer/symbol-search.test
index 6729c4b01bfef..fe9a61bd8ef6c 100644
--- a/llvm/test/tools/llvm-symbolizer/symbol-search.test
+++ b/llvm/test/tools/llvm-symbolizer/symbol-search.test
@@ -65,8 +65,9 @@ RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-p
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-prefix=NONEXISTENT %s
# 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
+# address starting with a `+` sign is a valid address
+RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=CODE-CMD %s
+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
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 3ba7f59d5b847..c8abddbbab5dd 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -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
+ // 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)) {
|
@da-viper, why was this PR closed? |
@jh7370 I could not tell if the existing behaviour was intended since I did not see any response, If it is not the case I can reopen it. |
Normally people "ping" a PR if it hasn't had any review after a week. You should also add some reviewers, by (if you have commit access) modifying the reviewers list, or (if you don't) pinging them here. I'd typically have reviewed this myself by now, but I'm on a reviewing pause, due to non-LLVM workloads being high at the moment. I suggest you reopen and update (if needed). We aim for compatibility with the GNU tools wherever possible, so I'd guess this PR has merit (but I can't be sure without digging deeper, which I won't have time for for a couple more weeks probably). |
Could you please provide more context? What problem does this change solve? I checked the trunk version of addr2line, it seems it does not support such syntax. |
When you pass and adress prefixed with $ llvm-addr2line --exe=./llvm-project/llvm/test/tools/llvm-symbolizer/Inputs/symbols.so +0x1138
??:0 [0.08s]
$ addr2line --exe=./llvm-project/llvm/test/tools/llvm-symbolizer/Inputs/symbols.so +0x1138
/tmp/dbginfo/symbols.part1.cpp:12
$ addr2line --version
GNU addr2line version 2.44-3.fc42
Copyright (C) 2025 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty. |
4eec5d8
to
6b65f98
Compare
this is also the same behaviour in gnu addr2line. Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
6b65f98
to
cf3fbef
Compare
This change does not add any new capabilities; it is purely syntactic sugar. Syntactic sugar is OK when it provides additional convenience, such as shorter commands or improved readability. Typically, there is no intention to merely expand the set of allowed constructs without clear benefits. Addresses, by their nature, are unsigned. Using a plus sign in address specifications does not seem useful. Supporting unnecessary syntax may even introduce errors. For example, if a script invokes Before adopting this patch, we need understand how this change could be useful. |
@da-viper has already highlighted that GNU addr2line supports this syntax. As we broadly aim for binary tools to be compatible with GNU tools where possible, we should accept this syntax too. The usefulness is that it then allows LLVM tools to be used as drop-in replacements for GNU tools in more cases. I will start properly reviewing this in a couple of weeks, if I don't get to it sooner.
Aside: while I suspect this is true for all architectures LLVM supports, it's not an inherent requirement. Imagine an architecture where the address values are mapped one-to-one with physical elements in a memory array. There's nothing stopping the maker of that architecture labelling the "middle" one as value 0, therefore necessitating negative addresses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I looked at wrong place.
LGTM.
Thanks!
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some post-commit comments. Please create a follow-up PR to fix them.
In addition to the inline comments:
- Please update llvm/docs/CommandGuide/llvm-addr2line to mention the different behaviour.
- Please add a release note to highlight the change in behaviour, to the "Changes in LLVM Tools" section of llvm/docs/ReleaseNotes.md.
@@ -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 |
There was a problem hiding this comment.
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.
// "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 |
There was a problem hiding this comment.
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.
Also add post-commit changes from commit #71ba852 in PR #135857 --------- Co-authored-by: James Henderson <James.Henderson@sony.com>
Also add post-commit changes from commit #71ba852 in PR llvm#135857 --------- Co-authored-by: James Henderson <James.Henderson@sony.com>
Also add post-commit changes from commit #71ba852 in PR llvm#135857 --------- Co-authored-by: James Henderson <James.Henderson@sony.com>
Also add post-commit changes from commit #71ba852 in PR llvm#135857 --------- Co-authored-by: James Henderson <James.Henderson@sony.com>
this is also the same behaviour in
gnu addr2line
.depends on #135856