Skip to content

Commit dedad08

Browse files
committed
[llvm-symbolizer] Support reading options from environment
llvm-symbolizer is used by sanitizers to symbolize errors discovered by sanitizer, but there's no way to pass options to llvm-symbolizer since the tool is invoked directly by the sanitizer runtime. Therefore, we don't have a way to pass options needed to find debug symbols such as -dsym-hint or -debug-file-directory. This change enables reading options from the LLVM_SYMBOLIZER_OPTS in addition to command line which can be used to pass those additional options to llvm-symbolizer invocations made by sanitizer runtime. Differential Revision: https://reviews.llvm.org/D71668
1 parent ddf897f commit dedad08

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

llvm/docs/CommandGuide/llvm-addr2line.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Here are some of those differences:
2727

2828
- Uses `--output-style=GNU`_ by default.
2929

30+
- Parses options from the environment variable ``LLVM_ADDR2LINE_OPTS``.
31+
3032
SEE ALSO
3133
--------
3234

llvm/docs/CommandGuide/llvm-symbolizer.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Object files can be specified together with the addresses either on standard
2828
input or as positional arguments on the command-line, following any "DATA" or
2929
"CODE" prefix.
3030

31+
:program:`llvm-symbolizer` parses options from the environment variable
32+
``LLVM_SYMBOLIZER_OPTS`` after parsing options from the command line.
33+
``LLVM_SYMBOLIZER_OPTS`` is primarily useful for supplementing the command-line
34+
options when :program:`llvm-symbolizer` is invoked by another program or
35+
runtime.
36+
3137
EXAMPLES
3238
--------
3339

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RUN: LLVM_SYMBOLIZER_OPTS=--print-address llvm-symbolizer 0x20112f | FileCheck %s
2+
RUN: LLVM_ADDR2LINE_OPTS=--print-address llvm-addr2line 0x20112f | FileCheck %s
3+
4+
CHECK: 0x20112f

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ int main(int argc, char **argv) {
289289
}
290290

291291
llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
292-
cl::ParseCommandLineOptions(argc, argv, IsAddr2Line ? "llvm-addr2line\n"
293-
: "llvm-symbolizer\n");
292+
cl::ParseCommandLineOptions(
293+
argc, argv, IsAddr2Line ? "llvm-addr2line\n" : "llvm-symbolizer\n",
294+
/*Errs=*/nullptr,
295+
IsAddr2Line ? "LLVM_ADDR2LINE_OPTS" : "LLVM_SYMBOLIZER_OPTS");
294296

295297
// If both --demangle and --no-demangle are specified then pick the last one.
296298
if (ClNoDemangle.getPosition() > ClDemangle.getPosition())

0 commit comments

Comments
 (0)