diff options
author | Martin Liska <mliska@suse.cz> | 2023-04-26 09:42:29 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2023-04-26 15:51:56 +0200 |
commit | d53b3d94aaf211ffb2159614f5aaaf03ceb861cc (patch) | |
tree | 4202fe134ccc618029a07e7d1913c608bd7fb77f /libsanitizer/ubsan | |
parent | a8e1551bdb372aa3cfe754429b5efd6229ae5fdb (diff) | |
download | gcc-d53b3d94aaf211ffb2159614f5aaaf03ceb861cc.zip gcc-d53b3d94aaf211ffb2159614f5aaaf03ceb861cc.tar.gz gcc-d53b3d94aaf211ffb2159614f5aaaf03ceb861cc.tar.bz2 |
libsanitizer: merge from upstream (3185e47b5a8444e9fd).
Diffstat (limited to 'libsanitizer/ubsan')
-rw-r--r-- | libsanitizer/ubsan/ubsan_diag.cpp | 7 | ||||
-rw-r--r-- | libsanitizer/ubsan/ubsan_flags.cpp | 1 | ||||
-rw-r--r-- | libsanitizer/ubsan/ubsan_handlers.cpp | 15 | ||||
-rw-r--r-- | libsanitizer/ubsan/ubsan_handlers.h | 8 | ||||
-rw-r--r-- | libsanitizer/ubsan/ubsan_platform.h | 2 | ||||
-rw-r--r-- | libsanitizer/ubsan/ubsan_type_hash_itanium.cpp | 23 |
6 files changed, 23 insertions, 33 deletions
diff --git a/libsanitizer/ubsan/ubsan_diag.cpp b/libsanitizer/ubsan/ubsan_diag.cpp index 3673e66..dd99613 100644 --- a/libsanitizer/ubsan/ubsan_diag.cpp +++ b/libsanitizer/ubsan/ubsan_diag.cpp @@ -214,7 +214,12 @@ static void RenderText(InternalScopedString *Buffer, const char *Message, // printf, and stop using snprintf here. char FloatBuffer[32]; #if SANITIZER_WINDOWS - sprintf_s(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float); + // On MSVC platforms, long doubles are equal to regular doubles. + // In MinGW environments on x86, long doubles are 80 bit, but here, + // we're calling an MS CRT provided printf function which considers + // long doubles to be 64 bit. Just cast the float value to a regular + // double to avoid the potential ambiguity in MinGW mode. + sprintf_s(FloatBuffer, sizeof(FloatBuffer), "%g", (double)A.Float); #else snprintf(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float); #endif diff --git a/libsanitizer/ubsan/ubsan_flags.cpp b/libsanitizer/ubsan/ubsan_flags.cpp index 9a66bd3..25cefd4 100644 --- a/libsanitizer/ubsan/ubsan_flags.cpp +++ b/libsanitizer/ubsan/ubsan_flags.cpp @@ -50,7 +50,6 @@ void InitializeFlags() { { CommonFlags cf; cf.CopyFrom(*common_flags()); - cf.print_summary = false; cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH"); OverrideCommonFlags(cf); } diff --git a/libsanitizer/ubsan/ubsan_handlers.cpp b/libsanitizer/ubsan/ubsan_handlers.cpp index 970075e..410292a 100644 --- a/libsanitizer/ubsan/ubsan_handlers.cpp +++ b/libsanitizer/ubsan/ubsan_handlers.cpp @@ -894,21 +894,6 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable, } // namespace __ubsan -void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData, - ValueHandle Function) { - GET_REPORT_OPTIONS(false); - CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; - handleCFIBadIcall(&Data, Function, Opts); -} - -void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData, - ValueHandle Function) { - GET_REPORT_OPTIONS(true); - CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; - handleCFIBadIcall(&Data, Function, Opts); - Die(); -} - void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data, ValueHandle Value, uptr ValidVtable) { diff --git a/libsanitizer/ubsan/ubsan_handlers.h b/libsanitizer/ubsan/ubsan_handlers.h index 9f41235..219fb15 100644 --- a/libsanitizer/ubsan/ubsan_handlers.h +++ b/libsanitizer/ubsan/ubsan_handlers.h @@ -215,20 +215,12 @@ enum CFITypeCheckKind : unsigned char { CFITCK_VMFCall, }; -struct CFIBadIcallData { - SourceLocation Loc; - const TypeDescriptor &Type; -}; - struct CFICheckFailData { CFITypeCheckKind CheckKind; SourceLocation Loc; const TypeDescriptor &Type; }; -/// \brief Handle control flow integrity failure for indirect function calls. -RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function) - /// \brief Handle control flow integrity failures. RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function, uptr VtableIsValid) diff --git a/libsanitizer/ubsan/ubsan_platform.h b/libsanitizer/ubsan/ubsan_platform.h index ad3e883..d2cc2e1 100644 --- a/libsanitizer/ubsan/ubsan_platform.h +++ b/libsanitizer/ubsan/ubsan_platform.h @@ -12,7 +12,6 @@ #ifndef UBSAN_PLATFORM_H #define UBSAN_PLATFORM_H -#ifndef CAN_SANITIZE_UB // Other platforms should be easy to add, and probably work as-is. #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ defined(__NetBSD__) || defined(__DragonFly__) || \ @@ -22,6 +21,5 @@ #else # define CAN_SANITIZE_UB 0 #endif -#endif //CAN_SANITIZE_UB #endif diff --git a/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp b/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp index d82b542..468a8fc 100644 --- a/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp +++ b/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp @@ -17,6 +17,7 @@ #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_ptrauth.h" +#include <stdint.h> // The following are intended to be binary compatible with the definitions // given in the Itanium ABI. We make no attempt to be ODR-compatible with @@ -25,9 +26,20 @@ namespace std { class type_info { public: + typedef const char *__type_name_t; virtual ~type_info(); const char *__type_name; + + __type_name_t name() const { +#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__) + uintptr_t __non_unique_rtti_bit = + (1ULL << ((__CHAR_BIT__ * sizeof(__type_name_t)) - 1)); + return (__type_name_t)((uintptr_t)__type_name & ~__non_unique_rtti_bit); +#else + return __type_name; +#endif + } }; } @@ -117,7 +129,7 @@ static __ubsan::HashValue *getTypeCacheHashTableBucket(__ubsan::HashValue V) { static bool isDerivedFromAtOffset(const abi::__class_type_info *Derived, const abi::__class_type_info *Base, sptr Offset) { - if (Derived->__type_name == Base->__type_name || + if (Derived->name() == Base->name() || __ubsan::checkTypeInfoEquality(Derived, Base)) return Offset == 0; @@ -254,17 +266,16 @@ __ubsan::getDynamicTypeInfoFromVtable(void *VtablePtr) { const abi::__class_type_info *ObjectType = findBaseAtOffset( static_cast<const abi::__class_type_info*>(Vtable->TypeInfo), -Vtable->Offset); - return DynamicTypeInfo(Vtable->TypeInfo->__type_name, -Vtable->Offset, - ObjectType ? ObjectType->__type_name : "<unknown>"); + return DynamicTypeInfo(Vtable->TypeInfo->name(), -Vtable->Offset, + ObjectType ? ObjectType->name() : "<unknown>"); } bool __ubsan::checkTypeInfoEquality(const void *TypeInfo1, const void *TypeInfo2) { auto TI1 = static_cast<const std::type_info *>(TypeInfo1); auto TI2 = static_cast<const std::type_info *>(TypeInfo2); - return SANITIZER_NON_UNIQUE_TYPEINFO && TI1->__type_name[0] != '*' && - TI2->__type_name[0] != '*' && - !internal_strcmp(TI1->__type_name, TI2->__type_name); + return SANITIZER_NON_UNIQUE_TYPEINFO && TI1->name()[0] != '*' && + TI2->name()[0] != '*' && !internal_strcmp(TI1->name(), TI2->name()); } #endif // CAN_SANITIZE_UB && !SANITIZER_WINDOWS |