Skip to content

Commit d13d61f

Browse files
committedSep 15, 2017
ubsan: Unbreak ubsan_cxx runtime library on Windows.
This was originally broken by r258744 which introduced a weak reference from ubsan to ubsan_cxx. This reference does not work directly on Windows because COFF has no direct concept of weak symbols. The fix is to use /alternatename to create a weak external reference to ubsan_cxx. Also fix the definition (and the name, so that we drop cached values) of the cmake flag that controls whether to build ubsan_cxx. Now the user-controllable flag is always on, and we turn it off internally depending on whether we support building it. Differential Revision: https://reviews.llvm.org/D37882 llvm-svn: 313391
1 parent b5ab895 commit d13d61f

10 files changed

+46
-13
lines changed
 

‎compiler-rt/CMakeLists.txt

+8-5
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ include(config-ix)
9494
if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
9595
# Mac OS X prior to 10.9 had problems with exporting symbols from
9696
# libc++/libc++abi.
97-
set(use_cxxabi_default OFF)
98-
elseif(MSVC)
99-
set(use_cxxabi_default OFF)
97+
set(cxxabi_supported OFF)
10098
else()
101-
set(use_cxxabi_default ON)
99+
set(cxxabi_supported ON)
102100
endif()
103101

104-
option(SANITIZER_CAN_USE_CXXABI "Sanitizers can use cxxabi" ${use_cxxabi_default})
102+
option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
103+
104+
set(SANITIZE_CAN_USE_CXXABI OFF)
105+
if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
106+
set(SANITIZER_CAN_USE_CXXABI ON)
107+
endif()
105108
pythonize_bool(SANITIZER_CAN_USE_CXXABI)
106109

107110
set(SANITIZER_CXX_ABI "default" CACHE STRING

‎compiler-rt/lib/ubsan/ubsan_handlers.cc

+23-6
Original file line numberDiff line numberDiff line change
@@ -652,16 +652,33 @@ static void handleCFIBadIcall(CFICheckFailData *Data, ValueHandle Function,
652652
}
653653

654654
namespace __ubsan {
655+
655656
#ifdef UBSAN_CAN_USE_CXXABI
657+
658+
#ifdef _WIN32
659+
660+
extern "C" void __ubsan_handle_cfi_bad_type_default(CFICheckFailData *Data,
661+
ValueHandle Vtable,
662+
bool ValidVtable,
663+
ReportOptions Opts) {
664+
Die();
665+
}
666+
667+
WIN_WEAK_ALIAS(__ubsan_handle_cfi_bad_type, __ubsan_handle_cfi_bad_type_default)
668+
#else
656669
SANITIZER_WEAK_ATTRIBUTE
657-
void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable,
658-
bool ValidVtable, ReportOptions Opts);
670+
#endif
671+
void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
672+
bool ValidVtable, ReportOptions Opts);
673+
659674
#else
660-
static void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable,
661-
bool ValidVtable, ReportOptions Opts) {
675+
static void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data,
676+
ValueHandle Vtable,
677+
bool ValidVtable, ReportOptions Opts) {
662678
Die();
663679
}
664680
#endif
681+
665682
} // namespace __ubsan
666683

667684
void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
@@ -671,7 +688,7 @@ void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
671688
if (Data->CheckKind == CFITCK_ICall)
672689
handleCFIBadIcall(Data, Value, Opts);
673690
else
674-
HandleCFIBadType(Data, Value, ValidVtable, Opts);
691+
__ubsan_handle_cfi_bad_type(Data, Value, ValidVtable, Opts);
675692
}
676693

677694
void __ubsan::__ubsan_handle_cfi_check_fail_abort(CFICheckFailData *Data,
@@ -681,7 +698,7 @@ void __ubsan::__ubsan_handle_cfi_check_fail_abort(CFICheckFailData *Data,
681698
if (Data->CheckKind == CFITCK_ICall)
682699
handleCFIBadIcall(Data, Value, Opts);
683700
else
684-
HandleCFIBadType(Data, Value, ValidVtable, Opts);
701+
__ubsan_handle_cfi_bad_type(Data, Value, ValidVtable, Opts);
685702
Die();
686703
}
687704

‎compiler-rt/lib/ubsan/ubsan_handlers.h

+7
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ struct CFICheckFailData {
192192
/// \brief Handle control flow integrity failures.
193193
RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
194194
uptr VtableIsValid)
195+
196+
struct ReportOptions;
197+
198+
extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __ubsan_handle_cfi_bad_type(
199+
CFICheckFailData *Data, ValueHandle Vtable, bool ValidVtable,
200+
ReportOptions Opts);
201+
195202
}
196203

197204
#endif // UBSAN_HANDLERS_H

‎compiler-rt/lib/ubsan/ubsan_handlers_cxx.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void __ubsan::__ubsan_handle_dynamic_type_cache_miss_abort(
9595
}
9696

9797
namespace __ubsan {
98-
void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable,
99-
bool ValidVtable, ReportOptions Opts) {
98+
void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
99+
bool ValidVtable, ReportOptions Opts) {
100100
SourceLocation Loc = Data->Loc.acquire();
101101
ErrorType ET = ErrorType::CFIBadType;
102102

‎compiler-rt/test/cfi/target_uninstrumented.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %t 2>&1 | FileCheck %s
44

55
// REQUIRES: cxxabi
6+
// UNSUPPORTED: win32
67

78
#include <stdio.h>
89
#include <string.h>

‎compiler-rt/test/ubsan/TestCases/TypeCheck/PR33221.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %run %t 2>&1 | FileCheck %s
33

44
// REQUIRES: cxxabi
5+
// UNSUPPORTED: win32
56

67
#include <string.h>
78

‎compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %run %t
44
//
55
// REQUIRES: cxxabi
6+
// UNSUPPORTED: win32
67

78
struct X {
89
virtual ~X() {}

‎compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %run %t
33

44
// REQUIRES: cxxabi
5+
// UNSUPPORTED: win32
56

67
int volatile n;
78

‎compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: not %run %t 2>&1 | FileCheck %s
33

44
// REQUIRES: cxxabi
5+
// UNSUPPORTED: win32
56

67
struct S { virtual int f() { return 0; } };
78
struct T : virtual S {};

‎compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// RUN: %env_ubsan_opts=suppressions='"%t.loc-supp"' not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
2727

2828
// REQUIRES: stable-runtime, cxxabi
29+
// UNSUPPORTED: win32
2930
#include <new>
3031
#include <assert.h>
3132
#include <stdio.h>

0 commit comments

Comments
 (0)
Please sign in to comment.