Skip to content

Commit 8b3944c

Browse files
author
Andres Villegas
authored
[sanitizer_symbolizer] Add initial symbolizer markup support for linux.
This is part of a stack of PRs to add support for symbolizer markup in linux. You can check the symbolizer markup specification at: https://llvm.org/docs/SymbolizerMarkupFormat.html Reviewers: vitalybuka, PiJoules Reviewed By: vitalybuka Pull Request: #73193
1 parent d3143a0 commit 8b3944c

5 files changed

+57
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_flags.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,7 @@ COMMON_FLAG(bool, test_only_emulate_no_memorymap, false,
275275
// program.
276276
COMMON_FLAG(bool, test_only_replace_dlopen_main_program, false,
277277
"TEST ONLY replace dlopen(<main program>,...) with dlopen(NULL)")
278+
279+
COMMON_FLAG(bool, enable_symbolizer_markup, SANITIZER_FUCHSIA,
280+
"Use sanitizer symbolizer markup, available on Linux "
281+
"and always set true for Fuchsia.")

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "sanitizer_file.h"
1717
#include "sanitizer_flags.h"
1818
#include "sanitizer_fuchsia.h"
19+
#include "sanitizer_symbolizer_markup.h"
1920

2021
namespace __sanitizer {
2122

@@ -62,6 +63,9 @@ const char *StackTracePrinter::StripFunctionName(const char *function) {
6263
#if !SANITIZER_SYMBOLIZER_MARKUP
6364

6465
StackTracePrinter *StackTracePrinter::NewStackTracePrinter() {
66+
if (common_flags()->enable_symbolizer_markup)
67+
return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
68+
6569
return new (GetGlobalLowLevelAllocator()) FormattedStackTracePrinter();
6670
}
6771

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,23 @@ void MarkupStackTracePrinter::RenderFrame(InternalScopedString *buffer,
4545
buffer->AppendF(kFormatFrame, frame_no, address);
4646
}
4747

48+
bool MarkupSymbolizerTool::SymbolizePC(uptr addr, SymbolizedStack *stack) {
49+
char buffer[kFormatFunctionMax];
50+
internal_snprintf(buffer, sizeof(buffer), kFormatFunction, addr);
51+
stack->info.function = internal_strdup(buffer);
52+
return true;
53+
}
54+
55+
bool MarkupSymbolizerTool::SymbolizeData(uptr addr, DataInfo *info) {
56+
info->Clear();
57+
info->start = addr;
58+
return true;
59+
}
60+
61+
const char *MarkupSymbolizerTool::Demangle(const char *name) {
62+
static char buffer[kFormatDemangleMax];
63+
internal_snprintf(buffer, sizeof(buffer), kFormatDemangle, name);
64+
return buffer;
65+
}
66+
4867
} // namespace __sanitizer

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "sanitizer_common.h"
1717
#include "sanitizer_stacktrace_printer.h"
1818
#include "sanitizer_symbolizer.h"
19+
#include "sanitizer_symbolizer_internal.h"
1920

2021
namespace __sanitizer {
2122

@@ -40,6 +41,28 @@ class MarkupStackTracePrinter : public StackTracePrinter {
4041
~MarkupStackTracePrinter() {}
4142
};
4243

44+
class MarkupSymbolizerTool final : public SymbolizerTool {
45+
public:
46+
// This is used in some places for suppression checking, which we
47+
// don't really support for Fuchsia. It's also used in UBSan to
48+
// identify a PC location to a function name, so we always fill in
49+
// the function member with a string containing markup around the PC
50+
// value.
51+
// TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
52+
// to render stack frames, but that should be changed to use
53+
// RenderStackFrame.
54+
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override;
55+
56+
// Always claim we succeeded, so that RenderDataInfo will be called.
57+
bool SymbolizeData(uptr addr, DataInfo *info) override;
58+
59+
// May return NULL if demangling failed.
60+
// This is used by UBSan for type names, and by ASan for global variable
61+
// names. It's expected to return a static buffer that will be reused on each
62+
// call.
63+
const char *Demangle(const char *name) override;
64+
};
65+
4366
} // namespace __sanitizer
4467

4568
#endif // SANITIZER_SYMBOLIZER_MARKUP_H

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "sanitizer_platform.h"
15+
#include "sanitizer_symbolizer_markup.h"
1516
#if SANITIZER_POSIX
1617
# include <dlfcn.h> // for dlsym()
1718
# include <errno.h>
@@ -475,6 +476,12 @@ static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list,
475476
VReport(2, "Symbolizer is disabled.\n");
476477
return;
477478
}
479+
if (common_flags()->enable_symbolizer_markup) {
480+
VReport(2, "Using symbolizer markup");
481+
SymbolizerTool *tool = new (*allocator) MarkupSymbolizerTool();
482+
CHECK(tool);
483+
list->push_back(tool);
484+
}
478485
if (IsAllocatorOutOfMemory()) {
479486
VReport(2, "Cannot use internal symbolizer: out of memory\n");
480487
} else if (SymbolizerTool *tool = InternalSymbolizer::get(allocator)) {

0 commit comments

Comments
 (0)