[llvm] [llvm-symbolizer] restore --[no-]use-symbol-table option (PR #71008)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 2 23:52:26 PDT 2023
https://github.com/quic-likaid updated https://github.com/llvm/llvm-project/pull/71008
>From 3e88cda967ace424f7f9c364b1447a477f287d01 Mon Sep 17 00:00:00 2001
From: Kevin Ding <quic_likaid at quicinc.com>
Date: Tue, 31 Oct 2023 14:59:14 +0800
Subject: [PATCH] [llvm-symbolizer] restore --[no-]use-symbol-table option
Sections in relocatable ELFs have their `sh_addr` set to 0. This can
confuse llvm-symbolizer when it tries to use symbol table to get
function name. It may end up with a global variable in the bss section.
This is observed when the symbolizer is used for Linux's dynamically
loadable kernel modules.
The option was unintentionally removed by 593e196, and remained as a
no-op since 3d54976. Adding back the option allows us to prevent the
undesired behaviour.
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 10 ++++++++++
.../tools/llvm-symbolizer/Inputs/relocatable.c | 6 ++++++
.../tools/llvm-symbolizer/Inputs/relocatable.o | Bin 0 -> 2944 bytes
.../llvm-symbolizer/no-use-symbol-table.test | 5 +++++
llvm/tools/llvm-symbolizer/Opts.td | 2 ++
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp | 3 ++-
6 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/tools/llvm-symbolizer/Inputs/relocatable.c
create mode 100644 llvm/test/tools/llvm-symbolizer/Inputs/relocatable.o
create mode 100644 llvm/test/tools/llvm-symbolizer/no-use-symbol-table.test
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 59c0ab6d196ace1..ae12a1471811190 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -314,6 +314,11 @@ OPTIONS
Don't print demangled function names.
+.. option:: --no-use-symbol-table
+
+ Don't prefer function names stored in symbol table to function names in debug
+ info sections.
+
.. option:: --obj <path>, --exe, -e
Path to object file to be symbolized. If ``-`` is specified, read the object
@@ -458,6 +463,11 @@ OPTIONS
of the absolute path. If the command-line to the compiler included
the full path, this will be the same as the default.
+.. option:: --use-symbol-table
+
+ Prefer function names stored in symbol table to function names in debug info
+ sections. This is the default.
+
.. option:: --verbose
Print verbose address, line and column information.
diff --git a/llvm/test/tools/llvm-symbolizer/Inputs/relocatable.c b/llvm/test/tools/llvm-symbolizer/Inputs/relocatable.c
new file mode 100644
index 000000000000000..89d507a75e60f2d
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/Inputs/relocatable.c
@@ -0,0 +1,6 @@
+// compile with: clang -g -c -o relocatable.o relocatable.c
+
+char a;
+char b;
+
+void foo() {}
diff --git a/llvm/test/tools/llvm-symbolizer/Inputs/relocatable.o b/llvm/test/tools/llvm-symbolizer/Inputs/relocatable.o
new file mode 100644
index 0000000000000000000000000000000000000000..f80becd3072005282c946f43e24ba6b7adc274f5
GIT binary patch
literal 2944
zcmbtWO>7fK6n?X7J3mf>6F><H5Ua%(P}U$tv?>x9%1=@uq*j7TZIM|!<6yG(n%yPP
zs46{Gs?<vK+6&@_R0-u+A#NP#krP7Pk$Oek+Dh==`n_Z_*>K5|)^Fx}-}{-_nYX at s
z?&5hzDG*U`5;kUn0 at Mn|I33ntFETIB|ML3kQ#GzCmEC!_5>1vSrz_*r6NPvZz?lQL
zvatKqzR!v$ip~^(dkBG(#bOa4=K;}bQ*MQ<r}kmcbNJ*z4N`msBO8S{j-+>7kF2iq
z0Nh+bIr(&&a~`N%%28JeP=GR0^2GaqoYjrC-z_%-zq?dk(NWwEyX9kZ-cj#3L^=qY
ze&RO*?KPo#JB*g&p5N4QH3(KZv%M(1p_ at rMsU|v3s!13IY>dC}G{T_0s-x;cw|6Uv
z!H4E`KY|9d!VvajNqI<@m|fh5>H^rqPHOclP<KjddSqbm9=<RNOAkr9SEt8HKRcg~
z7EU7pu`Bpc+D}j`rT!ZmB}H!<9~{ik5L`9m?8+ZZ$MEFsmj})~TE4qF{Qt8bk9_ at I
z4q(V37Rh9ObodL$LD!w`&gQ-DN8kGU7 at -`zdAHSqRl|B&o6IhHWQhv{Sun;K+6Euq
z1}|-cPi(=L5ScLQl=J)&@o~&7(%*W37mUkXv>Y6&Xv2$Q^o4L*wea>DxVh>X1E*Sq
zFPh?*H)zD*6E0^>c0l-tnJ4E|@EeR{6G%nyfaelV at SBX6SqmQXT<WBKA)AQQLpXMs
zb&<S;o2RAB48lzOBgQGV<RU0-H>d@#5r{J1S82;K<AArQ8 at HC~exniT74Q;$CjqY+
zb~?I?13dgbGvXwwhpkquv153R7=QYnh|4f&cXd6T8-D)cVw83kGg!OZ3c>4!iS{mB
zx;z^vesdW-YF>5X$L*y}xhXIM`g*+;`5kTbKo8SmKLiik8)=`{yHoWy1~AXD#Jk3a
z at 09?o>HV3q3nzrheG*%Z2R1I}LwLt=K=0SC;XD&Iy-URG{4}>QauxpzG%>{H_RwZy
zME{L_7Fdh2xyxvv`(6_Q>os1`HJ;Obq%D=REcfAK#O#>lLj8y2P+zV8+T4R^$;w|M
z5anTCrQa>;KX(2Th*8X=%oFu54{i&<TJnqj7I7Jy)SC>JO)!H?-^Hx@|Kj at R*`M}L
z?mR)Vf7D+om0kbuoc{ok4Ut+!|A00b8#H*71!i#9`dH6Cr)%v0sTmZ<vi}1AiG!^5
zOY at g?()z~?f5Gn~mR0IM41R-lQ*7=ZXw1q##rNOb{}OVge#uYwjAGjRe}*^Y6533W
q{GxwFqkHjPi0UVkC;dk-`JRcN;LmYj?>*V>F<52?QuOb_uKzuko8nRc
literal 0
HcmV?d00001
diff --git a/llvm/test/tools/llvm-symbolizer/no-use-symbol-table.test b/llvm/test/tools/llvm-symbolizer/no-use-symbol-table.test
new file mode 100644
index 000000000000000..6c6511ae3dfb7b3
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/no-use-symbol-table.test
@@ -0,0 +1,5 @@
+# The following command prints "b" if --use-symbol-table
+
+RUN: llvm-addr2line --no-use-symbol-table -fe %p/Inputs/relocatable.o 0x1 | FileCheck %s
+CHECK: foo
+CHECK: relocatable.c
diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index 6742e086d6ff954..29d376457a929b0 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -57,6 +57,8 @@ def relative_address : F<"relative-address", "Interpret addresses as addresses r
def relativenames : F<"relativenames", "Strip the compilation directory from paths">;
defm untag_addresses : B<"untag-addresses", "", "Remove memory tags from addresses before symbolization">;
def use_dia: F<"dia", "Use the DIA library to access symbols (Windows only)">;
+defm use_symbol_table : B<"use-symbol-table", "Prefer function names stored in symbol table",
+ "Don't prefer function names stored in symbol table">;
def verbose : F<"verbose", "Print verbose line info">;
def version : F<"version", "Display the version">;
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 447c18abadc1743..07bb896389c9bcd 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -477,7 +477,8 @@ int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
Opts.UseDIA = false;
}
#endif
- Opts.UseSymbolTable = true;
+ Opts.UseSymbolTable =
+ Args.hasFlag(OPT_use_symbol_table, OPT_no_use_symbol_table, true);
if (Args.hasArg(OPT_cache_size_EQ))
parseIntArg(Args, OPT_cache_size_EQ, Opts.MaxCacheSize);
Config.PrintAddress = Args.hasArg(OPT_addresses);
More information about the llvm-commits
mailing list