Skip to content

Commit

Permalink
[llvm-symbolizer] Support reading options from environment
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petrhosek committed Dec 20, 2019
1 parent ddf897f commit dedad08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llvm/docs/CommandGuide/llvm-addr2line.rst
Expand Up @@ -27,6 +27,8 @@ Here are some of those differences:

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

- Parses options from the environment variable ``LLVM_ADDR2LINE_OPTS``.

SEE ALSO
--------

Expand Down
6 changes: 6 additions & 0 deletions llvm/docs/CommandGuide/llvm-symbolizer.rst
Expand Up @@ -28,6 +28,12 @@ Object files can be specified together with the addresses either on standard
input or as positional arguments on the command-line, following any "DATA" or
"CODE" prefix.

:program:`llvm-symbolizer` parses options from the environment variable
``LLVM_SYMBOLIZER_OPTS`` after parsing options from the command line.
``LLVM_SYMBOLIZER_OPTS`` is primarily useful for supplementing the command-line
options when :program:`llvm-symbolizer` is invoked by another program or
runtime.

EXAMPLES
--------

Expand Down
4 changes: 4 additions & 0 deletions llvm/test/tools/llvm-symbolizer/options-from-env.test
@@ -0,0 +1,4 @@
RUN: LLVM_SYMBOLIZER_OPTS=--print-address llvm-symbolizer 0x20112f | FileCheck %s
RUN: LLVM_ADDR2LINE_OPTS=--print-address llvm-addr2line 0x20112f | FileCheck %s

CHECK: 0x20112f
6 changes: 4 additions & 2 deletions llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Expand Up @@ -289,8 +289,10 @@ int main(int argc, char **argv) {
}

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

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

0 comments on commit dedad08

Please sign in to comment.