[compiler-rt] f103ee2 - [sanitizer] Move internal_symbolizer "inline" option
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 23 11:28:07 PST 2021
Author: Vitaly Buka
Date: 2021-12-23T11:28:03-08:00
New Revision: f103ee2e9e3fc530fbada7cf3db6ca6913a502c1
URL: https://github.com/llvm/llvm-project/commit/f103ee2e9e3fc530fbada7cf3db6ca6913a502c1
DIFF: https://github.com/llvm/llvm-project/commit/f103ee2e9e3fc530fbada7cf3db6ca6913a502c1.diff
LOG: [sanitizer] Move internal_symbolizer "inline" option
This option is per process anyway. I'd like to add more options, but
having them as parameters of __sanitizer_symbolize_code looks
inconvenient.
Reviewed By: browneee
Differential Revision: https://reviews.llvm.org/D116201
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common_interface_posix.inc
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp
compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
compiler-rt/lib/sanitizer_common/weak_symbols.txt
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interface_posix.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interface_posix.inc
index 38f9531148d4b..11b894132994e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interface_posix.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interface_posix.inc
@@ -11,3 +11,4 @@ INTERFACE_WEAK_FUNCTION(__sanitizer_symbolize_code)
INTERFACE_WEAK_FUNCTION(__sanitizer_symbolize_data)
INTERFACE_WEAK_FUNCTION(__sanitizer_symbolize_demangle)
INTERFACE_WEAK_FUNCTION(__sanitizer_symbolize_flush)
+INTERFACE_WEAK_FUNCTION(__sanitizer_symbolize_set_inline_frames)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
index 8167db42a7abc..3166c0013f467 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
@@ -319,8 +319,7 @@ class Addr2LinePool final : public SymbolizerTool {
extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE bool
__sanitizer_symbolize_code(const char *ModuleName, u64 ModuleOffset,
- char *Buffer, int MaxLength,
- bool SymbolizeInlineFrames);
+ char *Buffer, int MaxLength);
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE bool
__sanitizer_symbolize_data(const char *ModuleName, u64 ModuleOffset,
char *Buffer, int MaxLength);
@@ -328,11 +327,16 @@ SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void
__sanitizer_symbolize_flush();
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE int
__sanitizer_symbolize_demangle(const char *Name, char *Buffer, int MaxLength);
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE bool
+__sanitizer_symbolize_set_inline_frames(bool InlineFrames);
} // extern "C"
class InternalSymbolizer final : public SymbolizerTool {
public:
static InternalSymbolizer *get(LowLevelAllocator *alloc) {
+ if (__sanitizer_symbolize_set_inline_frames)
+ CHECK(__sanitizer_symbolize_set_inline_frames(
+ common_flags()->symbolize_inline_frames));
if (__sanitizer_symbolize_code && __sanitizer_symbolize_data)
return new (*alloc) InternalSymbolizer();
return 0;
@@ -340,8 +344,7 @@ class InternalSymbolizer final : public SymbolizerTool {
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override {
bool result = __sanitizer_symbolize_code(
- stack->info.module, stack->info.module_offset, buffer_, kBufferSize,
- common_flags()->symbolize_inline_frames);
+ stack->info.module, stack->info.module_offset, buffer_, kBufferSize);
if (result)
ParseSymbolizePCOutput(buffer_, stack);
return result;
diff --git a/compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp b/compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp
index 3809880d50b4a..9b1d81765087f 100644
--- a/compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp
+++ b/compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp
@@ -17,10 +17,15 @@
#include "llvm/DebugInfo/Symbolize/DIPrinter.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
+static llvm::symbolize::LLVMSymbolizer *Symbolizer = nullptr;
+static bool InlineFrames = true;
+
static llvm::symbolize::LLVMSymbolizer *getDefaultSymbolizer() {
- static llvm::symbolize::LLVMSymbolizer *DefaultSymbolizer =
- new llvm::symbolize::LLVMSymbolizer();
- return DefaultSymbolizer;
+ if (Symbolizer)
+ return Symbolizer;
+ llvm::symbolize::LLVMSymbolizer::Options Opts;
+ Symbolizer = new llvm::symbolize::LLVMSymbolizer(Opts);
+ return Symbolizer;
}
static llvm::symbolize::PrinterConfig getDefaultPrinterConfig() {
@@ -43,8 +48,7 @@ extern "C" {
typedef uint64_t u64;
bool __sanitizer_symbolize_code(const char *ModuleName, uint64_t ModuleOffset,
- char *Buffer, int MaxLength,
- bool SymbolizeInlineFrames) {
+ char *Buffer, int MaxLength) {
std::string Result;
{
llvm::raw_string_ostream OS(Result);
@@ -55,7 +59,7 @@ bool __sanitizer_symbolize_code(const char *ModuleName, uint64_t ModuleOffset,
// TODO: it is neccessary to set proper SectionIndex here.
// object::SectionedAddress::UndefSection works for only absolute addresses.
- if (SymbolizeInlineFrames) {
+ if (InlineFrames) {
auto ResOrErr = getDefaultSymbolizer()->symbolizeInlinedCode(
ModuleName,
{ModuleOffset, llvm::object::SectionedAddress::UndefSection});
@@ -93,7 +97,10 @@ bool __sanitizer_symbolize_data(const char *ModuleName, uint64_t ModuleOffset,
Result.c_str()) < MaxLength;
}
-void __sanitizer_symbolize_flush() { getDefaultSymbolizer()->flush(); }
+void __sanitizer_symbolize_flush() {
+ if (Symbolizer)
+ Symbolizer->flush();
+}
int __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
int MaxLength) {
@@ -105,6 +112,11 @@ int __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
: 0;
}
+bool __sanitizer_symbolize_set_inline_frames(bool Value) {
+ InlineFrames = Value;
+ return true;
+}
+
// Override __cxa_atexit and ignore callbacks.
// This prevents crashes in a configuration when the symbolizer
// is built into sanitizer runtime and consequently into the test process.
diff --git a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
index 29925ccf30a17..7f301709c62b1 100755
--- a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
+++ b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
@@ -159,6 +159,7 @@ SYMBOLIZER_API_LIST=__sanitizer_symbolize_code
SYMBOLIZER_API_LIST+=,__sanitizer_symbolize_data
SYMBOLIZER_API_LIST+=,__sanitizer_symbolize_flush
SYMBOLIZER_API_LIST+=,__sanitizer_symbolize_demangle
+SYMBOLIZER_API_LIST+=,__sanitizer_symbolize_set_inline_frames
LIBCXX_ARCHIVE_DIR=$(dirname $(find $LIBCXX_BUILD -name libc++.a | head -n1))
diff --git a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
index cb4494f10b85e..18f74e7741eff 100644
--- a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
+++ b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
@@ -38,6 +38,7 @@ __sanitizer_symbolize_code T
__sanitizer_symbolize_data T
__sanitizer_symbolize_demangle T
__sanitizer_symbolize_flush T
+__sanitizer_symbolize_set_inline_frames T
__strdup U
__udivdi3 U
__umoddi3 U
diff --git a/compiler-rt/lib/sanitizer_common/weak_symbols.txt b/compiler-rt/lib/sanitizer_common/weak_symbols.txt
index 5a2b275184f49..8575bf610102b 100644
--- a/compiler-rt/lib/sanitizer_common/weak_symbols.txt
+++ b/compiler-rt/lib/sanitizer_common/weak_symbols.txt
@@ -6,3 +6,4 @@ ___sanitizer_symbolize_code
___sanitizer_symbolize_data
___sanitizer_symbolize_demangle
___sanitizer_symbolize_flush
+___sanitizer_symbolize_set_inline_frames
More information about the llvm-commits
mailing list