[PATCH] D22953: [compiler-rt] Make DemangleSwiftAndCXX robust against FreeBSD __cxa_demangle
Anna Zaks via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 19:05:03 PDT 2016
zaks.anna created this revision.
zaks.anna added reviewers: kcc, rnk.
zaks.anna added a subscriber: llvm-commits.
Herald added subscribers: kubabrecka, emaste.
The sanitizer unit tests fail on FreeBSD because __cxa_demangle returns invalid demanglings when dealing with non-C++ mangled names. It is not guaranteed to return the same string back. If the input string is not a C++ mangling, don't try to demangle it.
Reid Kleckner <rnk at google.com>:
"
This test is failing on FreeBSD, it appears because __cxa_demangle consumes the leading 'f' of foo and returns "float":
http://lab.llvm.org:8011/builders/sanitizer_x86_64-freebsd/builds/12709/steps/test%20sanitizer/logs/stdio
FAIL: SanitizerCommon-Unit :: Sanitizer-x86_64-Test/Symbolizer.DemangleSwiftAndCXX (292 of 309)
******************** TEST 'SanitizerCommon-Unit :: Sanitizer-x86_64-Test/Symbolizer.DemangleSwiftAndCXX' FAILED ********************
Note: Google Test filter = Symbolizer.DemangleSwiftAndCXX
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Symbolizer
[ RUN ] Symbolizer.DemangleSwiftAndCXX
/usr/home/buildslave/slave_as-bldslv5/sanitizer_x86_64-freebsd/llvm.src/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc:65: Failure
Value of: DemangleSwiftAndCXX("foo")
Actual: "float"
Expected: "foo"
[ FAILED ] Symbolizer.DemangleSwiftAndCXX (3 ms)
[----------] 1 test from Symbolizer (3 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (7 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Symbolizer.DemangleSwiftAndCXX
1 FAILED TEST
"
https://reviews.llvm.org/D22953
Files:
lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
Index: lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -50,6 +50,13 @@
// Attempts to demangle the name via __cxa_demangle from __cxxabiv1.
const char *DemangleCXXABI(const char *name) {
+ if (!name) return nullptr;
+
+ // Check if we are dealing with a C++ mangled name first.
+ if (name[0] != '_' || name[1] != 'Z') {
+ return nullptr;
+ }
+
// FIXME: __cxa_demangle aggressively insists on allocating memory.
// There's not much we can do about that, short of providing our
// own demangler (libc++abi's implementation could be adapted so that
@@ -60,7 +67,7 @@
__cxxabiv1::__cxa_demangle(name, 0, 0, 0))
return demangled_name;
- return name;
+ return nullptr;
}
// As of now, there are no headers for the Swift runtime. Once they are
@@ -98,7 +105,9 @@
if (!name) return nullptr;
if (const char *swift_demangled_name = DemangleSwift(name))
return swift_demangled_name;
- return DemangleCXXABI(name);
+ if (const char *cxx_demangled_name = DemangleCXXABI(name))
+ return cxx_demangled_name;
+ return name;
}
bool SymbolizerProcess::StartSymbolizerSubprocess() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22953.66073.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160729/826c36b8/attachment.bin>
More information about the llvm-commits
mailing list