[compiler-rt] r266494 - [sanitizers] Teach the internal demangler about Swift names
Anna Zaks via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 19:06:32 PDT 2016
Yes, this should work.
Sent a patch for review:
https://reviews.llvm.org/D22953 <https://reviews.llvm.org/D22953>
Depending on when it's approved I might not have time to commit it since I am going on vacation starting Saturday.
Cheers,
Anna.
> On Jul 28, 2016, at 1:26 PM, Dimitry Andric <dimitry at andric.com> wrote:
>
> Yes, it looks like DemangleCXXABI() unconditionally calls __cxa_demangle(), even if the symbol doesn't start with _Z. I think there should be a test in DemangleCXXABI() similar to the one in DemangleSwift(), e.g:
>
> // Check if we are dealing with a C++ mangled name first.
> if (name[0] != '_' || name[1] != 'Z') {
> return nullptr;
> }
>
> -Dimitry
>
>> On 28 Jul 2016, at 22:13, Reid Kleckner via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
>>
>> 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 <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
>>
>> On Fri, Apr 15, 2016 at 4:51 PM, Anna Zaks via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
>> Author: zaks
>> Date: Fri Apr 15 18:51:00 2016
>> New Revision: 266494
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=266494&view=rev <http://llvm.org/viewvc/llvm-project?rev=266494&view=rev>
>> Log:
>> [sanitizers] Teach the internal demangler about Swift names
>>
>> Add support for Swift names when symbolicating sanitizer traces. This is
>> now relevant since TSan and ASan support have been added to Swift on OS X.
>>
>> Differential Revision: http://reviews.llvm.org/D19135 <http://reviews.llvm.org/D19135>
>>
>> Modified:
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_internal.h
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
>> compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_internal.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_internal.h?rev=266494&r1=266493&r2=266494&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_internal.h?rev=266494&r1=266493&r2=266494&view=diff>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_internal.h (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_internal.h Fri Apr 15 18:51:00 2016
>> @@ -28,7 +28,7 @@ const char *ExtractUptr(const char *str,
>> const char *ExtractTokenUpToDelimiter(const char *str, const char *delimiter,
>> char **result);
>>
>> -const char *DemangleCXXABI(const char *name);
>> +const char *DemangleSwiftAndCXX(const char *name);
>>
>> // SymbolizerTool is an interface that is implemented by individual "tools"
>> // that can perform symbolication (external llvm-symbolizer, libbacktrace,
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc?rev=266494&r1=266493&r2=266494&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc?rev=266494&r1=266493&r2=266494&view=diff>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc Fri Apr 15 18:51:00 2016
>> @@ -32,7 +32,7 @@ bool DlAddrSymbolizer::SymbolizePC(uptr
>> Dl_info info;
>> int result = dladdr((const void *)addr, &info);
>> if (!result) return false;
>> - const char *demangled = DemangleCXXABI(info.dli_sname);
>> + const char *demangled = DemangleSwiftAndCXX(info.dli_sname);
>> stack->info.function = demangled ? internal_strdup(demangled) : nullptr;
>> return true;
>> }
>> @@ -41,7 +41,7 @@ bool DlAddrSymbolizer::SymbolizeData(upt
>> Dl_info info;
>> int result = dladdr((const void *)addr, &info);
>> if (!result) return false;
>> - const char *demangled = DemangleCXXABI(info.dli_sname);
>> + const char *demangled = DemangleSwiftAndCXX(info.dli_sname);
>> datainfo->name = internal_strdup(demangled);
>> datainfo->start = (uptr)info.dli_saddr;
>> return true;
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc?rev=266494&r1=266493&r2=266494&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc?rev=266494&r1=266493&r2=266494&view=diff>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc Fri Apr 15 18:51:00 2016
>> @@ -26,6 +26,7 @@
>> #include "sanitizer_symbolizer_libbacktrace.h"
>> #include "sanitizer_symbolizer_mac.h"
>>
>> +#include <dlfcn.h> // for dlsym()
>> #include <errno.h>
>> #include <stdlib.h>
>> #include <sys/wait.h>
>> @@ -61,6 +62,38 @@ const char *DemangleCXXABI(const char *n
>> return name;
>> }
>>
>> +// Attempts to demangle a Swift name. The demangler will return nullptr
>> +/// if a non-Swift name is passed in.
>> +const char *DemangleSwift(const char *name) {
>> + // Not to call dlsym every time we demangle, check if we are dealing with
>> + // Swift mangled name first.
>> + if (name[0] != '_' || name[1] != 'T') {
>> + return nullptr;
>> + }
>> +
>> + // As of now, there are no headers for the Swift runtime. Once they are
>> + // present, we will weakly link since we do not require Swift runtime to be
>> + // linked.
>> + typedef char *(*swift_demangle_ft)(const char *mangledName,
>> + size_t mangledNameLength,
>> + char *outputBuffer,
>> + size_t *outputBufferSize,
>> + uint32_t flags);
>> + swift_demangle_ft swift_demangle_f =
>> + (swift_demangle_ft) dlsym(RTLD_DEFAULT, "swift_demangle");
>> + if (swift_demangle_f)
>> + return swift_demangle_f(name, internal_strlen(name), 0, 0, 0);
>> +
>> + return nullptr;
>> +}
>> +
>> +const char *DemangleSwiftAndCXX(const char *name) {
>> + CHECK(name);
>> + if (const char *swift_demangled_name = DemangleSwift(name))
>> + return swift_demangled_name;
>> + return DemangleCXXABI(name);
>> +}
>> +
>> bool SymbolizerProcess::StartSymbolizerSubprocess() {
>> if (!FileExists(path_)) {
>> if (!reported_invalid_path_) {
>> @@ -364,7 +397,7 @@ class InternalSymbolizer : public Symbol
>> #endif // SANITIZER_SUPPORTS_WEAK_HOOKS
>>
>> const char *Symbolizer::PlatformDemangle(const char *name) {
>> - return DemangleCXXABI(name);
>> + return DemangleSwiftAndCXX(name);
>> }
>>
>> void Symbolizer::PlatformPrepareForSandboxing() {}
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc?rev=266494&r1=266493&r2=266494&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc?rev=266494&r1=266493&r2=266494&view=diff>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc Fri Apr 15 18:51:00 2016
>> @@ -55,4 +55,14 @@ TEST(Symbolizer, ExtractTokenUpToDelimit
>> InternalFree(token);
>> }
>>
>> +TEST(Symbolizer, DemangleSwiftAndCXX) {
>> + // Swift names are not demangled in default llvm build because Swift
>> + // runtime is not linked in.
>> + EXPECT_STREQ("_TtSd", DemangleSwiftAndCXX("_TtSd"));
>> + // Check that the rest demangles properly.
>> + EXPECT_STREQ("f1(char*, int)", DemangleSwiftAndCXX("_Z2f1Pci"));
>> + EXPECT_STREQ("foo", DemangleSwiftAndCXX("foo"));
>> + EXPECT_STREQ("", DemangleSwiftAndCXX(""));
>> +}
>> +
>> } // namespace __sanitizer
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/ae83cb38/attachment.html>
More information about the llvm-commits
mailing list