[llvm] dedad08 - [llvm-symbolizer] Support reading options from environment
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 20 12:48:10 PST 2019
Author: Petr Hosek
Date: 2019-12-20T12:47:27-08:00
New Revision: dedad08ee8e69129a1f6ac104e34960b50c94d94
URL: https://github.com/llvm/llvm-project/commit/dedad08ee8e69129a1f6ac104e34960b50c94d94
DIFF: https://github.com/llvm/llvm-project/commit/dedad08ee8e69129a1f6ac104e34960b50c94d94.diff
LOG: [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
Added:
llvm/test/tools/llvm-symbolizer/options-from-env.test
Modified:
llvm/docs/CommandGuide/llvm-addr2line.rst
llvm/docs/CommandGuide/llvm-symbolizer.rst
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-addr2line.rst b/llvm/docs/CommandGuide/llvm-addr2line.rst
index 08f1b69675dd..4f5881dc8e89 100644
--- a/llvm/docs/CommandGuide/llvm-addr2line.rst
+++ b/llvm/docs/CommandGuide/llvm-addr2line.rst
@@ -27,6 +27,8 @@ Here are some of those
diff erences:
- Uses `--output-style=GNU`_ by default.
+- Parses options from the environment variable ``LLVM_ADDR2LINE_OPTS``.
+
SEE ALSO
--------
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index b157f94ef226..bb60246c8352 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -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
--------
diff --git a/llvm/test/tools/llvm-symbolizer/options-from-env.test b/llvm/test/tools/llvm-symbolizer/options-from-env.test
new file mode 100644
index 000000000000..92fcbcda683f
--- /dev/null
+++ b/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
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index c9bc0309a654..45c845ac26ea 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -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())
More information about the llvm-commits
mailing list