[compiler-rt] r233036 - [UBSan] Use shared library for UBSan on OS X (compiler-rt part).

Kuba Brecka kuba.brecka at gmail.com
Tue Mar 24 06:23:02 PDT 2015


Hm, interesting.  Apparently, it’s a side-effect of adding the unconditional “-lc++abi” into the ASan+UBSan dylibs linking command.  This causes the interceptors of C++ `new` and `delete` operators to stop working, because the dylib interposers are then linked against the libc++abi symbol:

$ nm -m .../libclang_rt.asan_osx_dynamic.dylib | grep libc++abi
                 (undefined) weak external __ZdaPv (from libc++abi)
                 (undefined) weak external __ZdaPvRKSt9nothrow_t (from libc++abi)
                 (undefined) weak external __ZdlPv (from libc++abi)
                 (undefined) weak external __ZdlPvRKSt9nothrow_t (from libc++abi)
                 (undefined) weak external __Znam (from libc++abi)
                 (undefined) weak external __ZnamRKSt9nothrow_t (from libc++abi)
                 (undefined) weak external __Znwm (from libc++abi)
                 (undefined) weak external __ZnwmRKSt9nothrow_t (from libc++abi)
                 (undefined) weak external ___cxa_demangle (from libc++abi)
                 (undefined) external ___cxa_throw (from libc++abi)

but the test binary imports `__Znam` & friends from libc++, not libc++abi.

Kuba

> On Mar 24, 2015, at 1:59 PM, Alexander Potapenko <glider at google.com> wrote:
> 
> FYI this broke the Jenkins build:
> http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA_check/2427/
> I've confirmed locally that reverting your patch fixes at least
> large_func_test.cc.
> 
> On Tue, Mar 24, 2015 at 2:14 AM, Alexey Samsonov <vonosmas at gmail.com> wrote:
>> Author: samsonov
>> Date: Mon Mar 23 18:14:16 2015
>> New Revision: 233036
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=233036&view=rev
>> Log:
>> [UBSan] Use shared library for UBSan on OS X (compiler-rt part).
>> 
>> Summary:
>> Switch to shared library for UBSan. Add support for building
>> UBSan on OSX and iossim by cargo-culting ASan build rules.
>> 
>> Test Plan: regression test suite
>> 
>> Reviewers: zaks.anna, kubabrecka
>> 
>> Subscribers: llvm-commits
>> 
>> Differential Revision: http://reviews.llvm.org/D8473
>> 
>> Modified:
>>    compiler-rt/trunk/CMakeLists.txt
>>    compiler-rt/trunk/lib/ubsan/CMakeLists.txt
>>    compiler-rt/trunk/make/platform/clang_darwin.mk
>>    compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
>> 
>> Modified: compiler-rt/trunk/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=233036&r1=233035&r2=233036&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/CMakeLists.txt (original)
>> +++ compiler-rt/trunk/CMakeLists.txt Mon Mar 23 18:14:16 2015
>> @@ -304,7 +304,8 @@ if(APPLE)
>>   set(DARWIN_iossim_CFLAGS
>>     -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR})
>>   set(DARWIN_osx_LINKFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}
>> -     -stdlib=libc++)
>> +     -stdlib=libc++
>> +     -lc++abi)
>>   set(DARWIN_iossim_LINKFLAGS
>>     -Wl,-ios_simulator_version_min,7.0.0
>>     -mios-simulator-version-min=7.0
>> 
>> Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=233036&r1=233035&r2=233036&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
>> +++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Mon Mar 23 18:14:16 2015
>> @@ -22,13 +22,19 @@ set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CF
>> add_custom_target(ubsan)
>> 
>> if(APPLE)
>> -  # Build universal binary on APPLE.
>> -  add_compiler_rt_osx_static_runtime(clang_rt.ubsan_osx
>> -    ARCH ${UBSAN_SUPPORTED_ARCH}
>> -    SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES}
>> -            $<TARGET_OBJECTS:RTSanitizerCommon.osx>
>> -    CFLAGS ${UBSAN_CXXFLAGS})
>> -  add_dependencies(ubsan clang_rt.ubsan_osx)
>> +  foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
>> +    add_compiler_rt_darwin_object_library(RTUbsan ${os}
>> +      ARCH ${UBSAN_SUPPORTED_ARCH}
>> +      SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES}
>> +      CFLAGS ${UBSAN_CXXFLAGS})
>> +
>> +    add_compiler_rt_darwin_dynamic_runtime(clang_rt.ubsan_${os}_dynamic ${os}
>> +      ARCH ${UBSAN_SUPPORTED_ARCH}
>> +      SOURCES $<TARGET_OBJECTS:RTUbsan.${os}>
>> +              $<TARGET_OBJECTS:RTSanitizerCommon.${os}>)
>> +
>> +    add_dependencies(ubsan clang_rt.ubsan_${os}_dynamic)
>> +  endforeach()
>> else()
>>   # Build separate libraries for each target.
>>   foreach(arch ${UBSAN_SUPPORTED_ARCH})
>> 
>> Modified: compiler-rt/trunk/make/platform/clang_darwin.mk
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_darwin.mk?rev=233036&r1=233035&r2=233036&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
>> +++ compiler-rt/trunk/make/platform/clang_darwin.mk Mon Mar 23 18:14:16 2015
>> @@ -119,8 +119,11 @@ UniversalArchs.asan_osx_dynamic := $(cal
>> Configs += asan_iossim_dynamic
>> UniversalArchs.asan_iossim_dynamic := $(call CheckArches,i386 x86_64,asan_iossim_dynamic,$(IOSSIM_SDK))
>> 
>> -Configs += ubsan_osx
>> -UniversalArchs.ubsan_osx := $(call CheckArches,i386 x86_64 x86_64h,ubsan_osx,$(OSX_SDK))
>> +Configs += ubsan_osx_dynamic
>> +UniversalArchs.ubsan_osx_dynamic := $(call CheckArches,i386 x86_64 x86_64h,ubsan_osx_dynamic,$(OSX_SDK))
>> +
>> +Configs += ubsan_iossim_dynamic
>> +UniversalArchs.ubsan_iossim_dynamic := $(call CheckArches,i386 x86_64,ubsan_iossim_dynamic,$(IOSSIM_SDK))
>> 
>> # Darwin 10.6 has a bug in cctools that makes it unable to use ranlib on our ARM
>> # object files. If we are on that platform, strip out all ARM archs. We still
>> @@ -172,24 +175,33 @@ IOSSIM_DEPLOYMENT_ARGS += -isysroot $(IO
>> CFLAGS.eprintf         := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
>> CFLAGS.10.4            := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
>> 
>> +SANITIZER_MACOSX_DEPLOYMENT_ARGS := -mmacosx-version-min=10.7
>> +SANITIZER_IOSSIM_DEPLOYMENT_ARGS := -mios-simulator-version-min=7.0 \
>> +  -isysroot $(IOSSIM_SDK)
>> +SANITIZER_CFLAGS := -fno-builtin -gline-tables-only
>> +
>> CFLAGS.asan_osx_dynamic := \
>> -       $(CFLAGS) -mmacosx-version-min=10.7 \
>> +       $(CFLAGS) $(SANITIZER_MACOSX_DEPLOYMENT_ARGS) \
>> +       $(SANITIZER_CFLAGS) \
>>        -stdlib=libc++ \
>> -       -fno-builtin \
>> -       -gline-tables-only \
>>        -DMAC_INTERPOSE_FUNCTIONS=1 \
>>        -DASAN_DYNAMIC=1
>> 
>> CFLAGS.asan_iossim_dynamic := \
>> -       $(CFLAGS) -mios-simulator-version-min=7.0 \
>> -        -isysroot $(IOSSIM_SDK) \
>> -        -fno-builtin \
>> -       -gline-tables-only \
>> +       $(CFLAGS) $(SANITIZER_IOSSIM_DEPLOYMENT_ARGS) \
>> +  $(SANITIZER_CFLAGS) \
>>        -DMAC_INTERPOSE_FUNCTIONS=1 \
>>        -DASAN_DYNAMIC=1
>> 
>> -CFLAGS.ubsan_osx := $(CFLAGS) -mmacosx-version-min=10.6 \
>> -       -fno-builtin
>> +CFLAGS.ubsan_osx_dynamic := \
>> +       $(CFLAGS) $(SANITIZER_MACOSX_DEPLOYMENT_ARGS) \
>> +       $(SANITIZER_CFLAGS) \
>> +       -stdlib=libc++
>> +
>> +CFLAGS.ubsan_iossim_dynamic := \
>> +       $(CFLAGS) $(SANITIZER_IOSSIM_DEPLOYMENT_ARGS) \
>> +  $(SANITIZER_CFLAGS)
>> +
>> 
>> CFLAGS.ios.i386                := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
>> CFLAGS.ios.x86_64      := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
>> @@ -220,24 +232,29 @@ CFLAGS.profile_ios.armv7k := $(CFLAGS) $
>> CFLAGS.profile_ios.armv7s := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
>> CFLAGS.profile_ios.arm64  := $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
>> 
>> -# Configure the asan_osx_dynamic library to be built shared.
>> +SANITIZER_LDFLAGS := -undefined dynamic_lookup
>> +
>> SHARED_LIBRARY.asan_osx_dynamic := 1
>> -LDFLAGS.asan_osx_dynamic := -lc++ -undefined dynamic_lookup -install_name @rpath/libclang_rt.asan_osx_dynamic.dylib \
>> -  -mmacosx-version-min=10.7
>> +LDFLAGS.asan_osx_dynamic := -lc++ $(SANITIZER_LDFLAGS) -install_name @rpath/libclang_rt.asan_osx_dynamic.dylib \
>> +  $(SANITIZER_MACOSX_DEPLOYMENT_ARGS)
>> 
>> -# Configure the asan_iossim_dynamic library to be built shared.
>> SHARED_LIBRARY.asan_iossim_dynamic := 1
>> -# configure+make uses Clang, so we're using isysroot instead of --sysroot
>> -# or -Wl,-syslibroot.
>> -LDFLAGS.asan_iossim_dynamic := -undefined dynamic_lookup -install_name @rpath/libclang_rt.asan_iossim_dynamic.dylib \
>> -  -Wl,-ios_simulator_version_min,7.0.0 \
>> -  -mios-simulator-version-min=7.0 -isysroot $(IOSSIM_SDK)
>> +LDFLAGS.asan_iossim_dynamic := $(SANITIZER_LDFLAGS) -install_name @rpath/libclang_rt.asan_iossim_dynamic.dylib \
>> +  -Wl,-ios_simulator_version_min,7.0.0 $(SANITIZER_IOSSIM_DEPLOYMENT_ARGS)
>> +
>> +SHARED_LIBRARY.ubsan_osx_dynamic := 1
>> +LDFLAGS.ubsan_osx_dynamic := -lc++ $(SANITIZER_LDFLAGS) -install_name @rpath/libclang_rt.ubsan_osx_dynamic.dylib \
>> +  $(SANITIZER_MACOSX_DEPLOYMENT_ARGS)
>> +
>> +SHARED_LIBRARY.ubsan_iossim_dynamic := 1
>> +LDFLAGS.ubsan_iossim_dynamic := $(SANITIZER_LDFLAGS) -install_name @rpath/libclang_rt.ubsan_iossim_dynamic.dylib \
>> +  -Wl,-ios_simulator_version_min,7.0.0 $(SANITIZER_IOSSIM_DEPLOYMENT_ARGS)
>> 
>> ifneq ($(OSX_SDK),)
>> CFLAGS.asan_osx_dynamic += -isysroot $(OSX_SDK)
>> LDFLAGS.asan_osx_dynamic += -isysroot $(OSX_SDK)
>> -CFLAGS.ubsan_osx += -isysroot $(OSX_SDK)
>> -LDFLAGS.ubsan_osx += -isysroot $(OSX_SDK)
>> +CFLAGS.ubsan_osx_dynamic += -isysroot $(OSX_SDK)
>> +LDFLAGS.ubsan_osx_dynamic += -isysroot $(OSX_SDK)
>> endif
>> 
>> FUNCTIONS.eprintf := eprintf
>> @@ -260,15 +277,18 @@ FUNCTIONS.profile_ios := $(FUNCTIONS.pro
>> FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(AsanCXXFunctions) \
>>                               $(InterceptionFunctions) \
>>                               $(SanitizerCommonFunctions) \
>> -                             $(AsanDynamicFunctions)
>> +                              $(AsanDynamicFunctions)
>> 
>> FUNCTIONS.asan_iossim_dynamic := $(AsanFunctions) $(AsanCXXFunctions) \
>>                                  $(InterceptionFunctions) \
>>                                  $(SanitizerCommonFunctions) \
>> -                                $(AsanDynamicFunctions)
>> +                                 $(AsanDynamicFunctions)
>> +
>> +FUNCTIONS.ubsan_osx_dynamic := $(UbsanFunctions) $(UbsanCXXFunctions) \
>> +                               $(SanitizerCommonFunctions)
>> 
>> -FUNCTIONS.ubsan_osx := $(UbsanFunctions) $(UbsanCXXFunctions) \
>> -                       $(SanitizerCommonFunctions)
>> +FUNCTIONS.ubsan_iossim_dynamic := $(UbsanFunctions) $(UbsanCXXFunctions) \
>> +                                  $(SanitizerCommonFunctions)
>> 
>> CCKEXT_PROFILE_FUNCTIONS := \
>>        InstrProfiling \
>> 
>> Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp?rev=233036&r1=233035&r2=233036&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp (original)
>> +++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp Mon Mar 23 18:14:16 2015
>> @@ -1,9 +1,6 @@
>> // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t
>> // RUN: not %run %t 2>&1 | FileCheck %s
>> 
>> -// FIXME: This test produces linker errors on Darwin.
>> -// XFAIL: darwin
>> -
>> struct S { virtual int f() { return 0; } };
>> struct T : virtual S {};
>> 
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> 
> 
> -- 
> Alexander Potapenko
> Software Engineer
> Google Moscow

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150324/8561c635/attachment.html>


More information about the llvm-commits mailing list