r233860 - [UBSan] Embed UBSan into ASan runtime (Clang part).
Alexey Samsonov
vonosmas at gmail.com
Thu Apr 2 16:53:32 PDT 2015
UBSan+MSan and UBSan+TSan combinations are currently not supported. We
print a diagnostic in this case.
On Thu, Apr 2, 2015 at 3:24 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> How does this affect UBSan + MSan and UBSan + TSan builds?
>
> On Wed, Apr 1, 2015 at 3:42 PM, Alexey Samsonov <vonosmas at gmail.com>
> wrote:
>
>> Author: samsonov
>> Date: Wed Apr 1 17:42:25 2015
>> New Revision: 233860
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=233860&view=rev
>> Log:
>> [UBSan] Embed UBSan into ASan runtime (Clang part).
>>
>> Summary:
>> Change the way we use ASan and UBSan together. Instead of keeping two
>> separate runtimes (libclang_rt.asan and libclang_rt.ubsan), embed UBSan
>> into ASan and get rid of libclang_rt.ubsan. If UBSan is not supported on
>> a platform, all UBSan sources are just compiled into dummy empty object
>> files. UBSan initialization code (e.g. flag parsing) is directly called
>> from ASan initialization, so we are able to enforce correct
>> initialization order.
>>
>> This mirrors the approach we already use for ASan+LSan. This change
>> doesn't
>> modify the way we use standalone UBSan.
>>
>> Test Plan: regression test suite
>>
>> Reviewers: kubabrecka, zaks.anna, kcc, rsmith
>>
>> Subscribers: cfe-commits
>>
>> Differential Revision: http://reviews.llvm.org/D8645
>>
>> Modified:
>> cfe/trunk/lib/Driver/SanitizerArgs.cpp
>> cfe/trunk/lib/Driver/ToolChains.cpp
>> cfe/trunk/lib/Driver/Tools.cpp
>> cfe/trunk/test/Driver/sanitizer-ld.c
>>
>> Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=233860&r1=233859&r2=233860&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
>> +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Wed Apr 1 17:42:25 2015
>> @@ -159,7 +159,8 @@ static bool getDefaultBlacklist(const Dr
>> }
>>
>> bool SanitizerArgs::needsUbsanRt() const {
>> - return !UbsanTrapOnError && hasOneOf(Sanitizers, NeedsUbsanRt);
>> + return !UbsanTrapOnError && hasOneOf(Sanitizers, NeedsUbsanRt) &&
>> + !Sanitizers.has(SanitizerKind::Address);
>> }
>>
>> bool SanitizerArgs::requiresPIE() const {
>>
>> Modified: cfe/trunk/lib/Driver/ToolChains.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=233860&r1=233859&r2=233860&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/ToolChains.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Apr 1 17:42:25 2015
>> @@ -338,6 +338,9 @@ void DarwinClang::AddLinkSanitizerLibArg
>> OS + "_dynamic.dylib").str(),
>> /*AlwaysLink*/ true, /*IsEmbedded*/ false,
>> /*AddRPath*/ true);
>> + // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export
>> + // all RTTI-related symbols that UBSan uses.
>> + CmdArgs.push_back("-lc++abi");
>> }
>>
>> void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
>> @@ -401,9 +404,6 @@ void DarwinClang::AddLinkRuntimeLibArgs(
>> << "-fsanitize=undefined";
>> } else {
>> AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan");
>> - // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export
>> - // all RTTI-related symbols that UBSan uses.
>> - CmdArgs.push_back("-lc++abi");
>> }
>> }
>>
>>
>> Modified: cfe/trunk/lib/Driver/Tools.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=233860&r1=233859&r2=233860&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/Tools.cpp (original)
>> +++ cfe/trunk/lib/Driver/Tools.cpp Wed Apr 1 17:42:25 2015
>> @@ -2307,18 +2307,10 @@ collectSanitizerRuntimes(const ToolChain
>> StaticRuntimes.push_back("msan");
>> if (SanArgs.needsTsanRt())
>> StaticRuntimes.push_back("tsan");
>> - // WARNING: UBSan should always go last.
>> if (SanArgs.needsUbsanRt()) {
>> - // Check if UBSan is combined with another sanitizers.
>> - if (StaticRuntimes.empty()) {
>> - StaticRuntimes.push_back("ubsan_standalone");
>> - if (SanArgs.linkCXXRuntimes())
>> - StaticRuntimes.push_back("ubsan_standalone_cxx");
>> - } else {
>> - StaticRuntimes.push_back("ubsan");
>> - if (SanArgs.linkCXXRuntimes())
>> - StaticRuntimes.push_back("ubsan_cxx");
>> - }
>> + StaticRuntimes.push_back("ubsan_standalone");
>> + if (SanArgs.linkCXXRuntimes())
>> + StaticRuntimes.push_back("ubsan_standalone_cxx");
>> }
>> }
>>
>>
>> Modified: cfe/trunk/test/Driver/sanitizer-ld.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=233860&r1=233859&r2=233860&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/Driver/sanitizer-ld.c (original)
>> +++ cfe/trunk/test/Driver/sanitizer-ld.c Wed Apr 1 17:42:25 2015
>> @@ -227,8 +227,7 @@
>> // RUN: | FileCheck --check-prefix=CHECK-ASAN-UBSAN-LINUX %s
>> // CHECK-ASAN-UBSAN-LINUX: "{{.*}}ld{{(.exe)?}}"
>> // CHECK-ASAN-UBSAN-LINUX: "-whole-archive"
>> "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
>> -// CHECK-ASAN-UBSAN-LINUX: "-whole-archive"
>> "{{.*}}libclang_rt.ubsan-i386.a" "-no-whole-archive"
>> -// CHECK-ASAN-UBSAN-LINUX-NOT: libclang_rt.ubsan_cxx
>> +// CHECK-ASAN-UBSAN-LINUX-NOT: libclang_rt.ubsan
>> // CHECK-ASAN-UBSAN-LINUX-NOT: "-lstdc++"
>> // CHECK-ASAN-UBSAN-LINUX: "-lpthread"
>>
>> @@ -238,8 +237,8 @@
>> // RUN: | FileCheck --check-prefix=CHECK-ASAN-UBSAN-LINUX-CXX %s
>> // CHECK-ASAN-UBSAN-LINUX-CXX: "{{.*}}ld{{(.exe)?}}"
>> // CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive"
>> "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
>> -// CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive"
>> "{{.*}}libclang_rt.ubsan-i386.a" "-no-whole-archive"
>> -// CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive"
>> "{{.*}}libclang_rt.ubsan_cxx-i386.a" "-no-whole-archive"
>> +// CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive"
>> "{{.*}}libclang_rt.asan_cxx-i386.a" "-no-whole-archive"
>> +// CHECK-ASAN-UBSAN-LINUX-CXX-NOT: libclang_rt.ubsan
>> // CHECK-ASAN-UBSAN-LINUX-CXX: "-lstdc++"
>> // CHECK-ASAN-UBSAN-LINUX-CXX: "-lpthread"
>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
--
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150402/1d564d2f/attachment.html>
More information about the cfe-commits
mailing list