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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

da-viper
Copy link
Contributor

this is also the same behaviour in gnu addr2line.

depends on #135856

@llvmbot
Copy link
Member

llvmbot commented Apr 15, 2025

@llvm/pr-subscribers-llvm-binary-utilities

Author: Ebuka Ezike (da-viper)

Changes

this is also the same behaviour in gnu addr2line.

depends on #135856


Full diff: https://github.com/llvm/llvm-project/pull/135857.diff

2 Files Affected:

  • (modified) llvm/test/tools/llvm-symbolizer/symbol-search.test (+3-2)
  • (modified) llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp (+6-3)
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 da-viper closed this May 13, 2025
@jh7370
Copy link
Collaborator

jh7370 commented May 14, 2025

@da-viper, why was this PR closed?

@da-viper
Copy link
Contributor Author

@jh7370 I could not tell if the existing behaviour was intended since I did not see any response,
I assumed it was not that is why I closed it.

If it is not the case I can reopen it.

@jh7370
Copy link
Collaborator

jh7370 commented May 14, 2025

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).

@spavloff
Copy link
Collaborator

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.

@da-viper
Copy link
Contributor Author

@spavloff

Could you please provide more context? What problem does this change solve?

When you pass and adress prefixed with + e.g.

$ 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.

@da-viper da-viper force-pushed the update-test-for-symbolizer branch from 4eec5d8 to 6b65f98 Compare May 20, 2025 17:48
da-viper added 2 commits May 22, 2025 20:07
this is also the same behaviour in gnu addr2line.

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
@da-viper da-viper force-pushed the update-test-for-symbolizer branch from 6b65f98 to cf3fbef Compare May 22, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants