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
This commit is contained in:
Peter Collingbourne 2017-09-15 20:24:12 +00:00
parent b5ab895e2a
commit d13d61fdb4
10 changed files with 47 additions and 14 deletions

View File

@ -94,14 +94,17 @@ include(config-ix)
if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
# Mac OS X prior to 10.9 had problems with exporting symbols from
# libc++/libc++abi.
set(use_cxxabi_default OFF)
elseif(MSVC)
set(use_cxxabi_default OFF)
set(cxxabi_supported OFF)
else()
set(use_cxxabi_default ON)
set(cxxabi_supported ON)
endif()
option(SANITIZER_CAN_USE_CXXABI "Sanitizers can use cxxabi" ${use_cxxabi_default})
option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
set(SANITIZE_CAN_USE_CXXABI OFF)
if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
set(SANITIZER_CAN_USE_CXXABI ON)
endif()
pythonize_bool(SANITIZER_CAN_USE_CXXABI)
set(SANITIZER_CXX_ABI "default" CACHE STRING

View File

@ -652,16 +652,33 @@ static void handleCFIBadIcall(CFICheckFailData *Data, ValueHandle Function,
}
namespace __ubsan {
#ifdef UBSAN_CAN_USE_CXXABI
SANITIZER_WEAK_ATTRIBUTE
void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable,
bool ValidVtable, ReportOptions Opts);
#ifdef _WIN32
extern "C" void __ubsan_handle_cfi_bad_type_default(CFICheckFailData *Data,
ValueHandle Vtable,
bool ValidVtable,
ReportOptions Opts) {
Die();
}
WIN_WEAK_ALIAS(__ubsan_handle_cfi_bad_type, __ubsan_handle_cfi_bad_type_default)
#else
static void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable,
bool ValidVtable, ReportOptions Opts) {
SANITIZER_WEAK_ATTRIBUTE
#endif
void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
bool ValidVtable, ReportOptions Opts);
#else
static void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data,
ValueHandle Vtable,
bool ValidVtable, ReportOptions Opts) {
Die();
}
#endif
} // namespace __ubsan
void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
@ -671,7 +688,7 @@ void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
if (Data->CheckKind == CFITCK_ICall)
handleCFIBadIcall(Data, Value, Opts);
else
HandleCFIBadType(Data, Value, ValidVtable, Opts);
__ubsan_handle_cfi_bad_type(Data, Value, ValidVtable, Opts);
}
void __ubsan::__ubsan_handle_cfi_check_fail_abort(CFICheckFailData *Data,
@ -681,7 +698,7 @@ void __ubsan::__ubsan_handle_cfi_check_fail_abort(CFICheckFailData *Data,
if (Data->CheckKind == CFITCK_ICall)
handleCFIBadIcall(Data, Value, Opts);
else
HandleCFIBadType(Data, Value, ValidVtable, Opts);
__ubsan_handle_cfi_bad_type(Data, Value, ValidVtable, Opts);
Die();
}

View File

@ -192,6 +192,13 @@ struct CFICheckFailData {
/// \brief Handle control flow integrity failures.
RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
uptr VtableIsValid)
struct ReportOptions;
extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __ubsan_handle_cfi_bad_type(
CFICheckFailData *Data, ValueHandle Vtable, bool ValidVtable,
ReportOptions Opts);
}
#endif // UBSAN_HANDLERS_H

View File

@ -95,8 +95,8 @@ void __ubsan::__ubsan_handle_dynamic_type_cache_miss_abort(
}
namespace __ubsan {
void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable,
bool ValidVtable, ReportOptions Opts) {
void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
bool ValidVtable, ReportOptions Opts) {
SourceLocation Loc = Data->Loc.acquire();
ErrorType ET = ErrorType::CFIBadType;

View File

@ -3,6 +3,7 @@
// RUN: %t 2>&1 | FileCheck %s
// REQUIRES: cxxabi
// UNSUPPORTED: win32
#include <stdio.h>
#include <string.h>

View File

@ -2,6 +2,7 @@
// RUN: %run %t 2>&1 | FileCheck %s
// REQUIRES: cxxabi
// UNSUPPORTED: win32
#include <string.h>

View File

@ -3,6 +3,7 @@
// RUN: %run %t
//
// REQUIRES: cxxabi
// UNSUPPORTED: win32
struct X {
virtual ~X() {}

View File

@ -2,6 +2,7 @@
// RUN: %run %t
// REQUIRES: cxxabi
// UNSUPPORTED: win32
int volatile n;

View File

@ -2,6 +2,7 @@
// RUN: not %run %t 2>&1 | FileCheck %s
// REQUIRES: cxxabi
// UNSUPPORTED: win32
struct S { virtual int f() { return 0; } };
struct T : virtual S {};

View File

@ -26,6 +26,7 @@
// RUN: %env_ubsan_opts=suppressions='"%t.loc-supp"' not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
// REQUIRES: stable-runtime, cxxabi
// UNSUPPORTED: win32
#include <new>
#include <assert.h>
#include <stdio.h>