summaryrefslogtreecommitdiffstats
path: root/libsanitizer
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2022-05-05 12:52:44 +0200
committerMartin Liska <mliska@suse.cz>2022-05-05 13:24:20 +0200
commit45e69f7f38cdc72e287ebf13bec7ba3eead32757 (patch)
tree7f6717e2cef8eafc5e1c77cd40c4d6274b1c2bdb /libsanitizer
parentlibsanitizer: merge from master (75f9e83ace52773af65dcebca543005ec8a2705d). (diff)
downloadgcc-45e69f7f38cdc72e287ebf13bec7ba3eead32757.tar.gz
gcc-45e69f7f38cdc72e287ebf13bec7ba3eead32757.tar.bz2
gcc-45e69f7f38cdc72e287ebf13bec7ba3eead32757.tar.xz
libsanitizer: Apply local patches
Diffstat (limited to 'libsanitizer')
-rw-r--r--libsanitizer/asan/asan_globals.cpp19
-rw-r--r--libsanitizer/asan/asan_interceptors.h7
-rw-r--r--libsanitizer/asan/asan_mapping.h2
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp4
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_mac.cpp12
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_mac.h20
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp5
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h2
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp17
-rw-r--r--libsanitizer/tsan/tsan_rtl_ppc64.S1
-rw-r--r--libsanitizer/ubsan/ubsan_flags.cpp1
-rw-r--r--libsanitizer/ubsan/ubsan_handlers.cpp15
-rw-r--r--libsanitizer/ubsan/ubsan_handlers.h8
-rw-r--r--libsanitizer/ubsan/ubsan_platform.h2
14 files changed, 85 insertions, 30 deletions
diff --git a/libsanitizer/asan/asan_globals.cpp b/libsanitizer/asan/asan_globals.cpp
index ecc2600f039..326a49798f0 100644
--- a/libsanitizer/asan/asan_globals.cpp
+++ b/libsanitizer/asan/asan_globals.cpp
@@ -153,23 +153,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
153 } 153 }
154} 154}
155 155
156// Check ODR violation for given global G by checking if it's already poisoned.
157// We use this method in case compiler doesn't use private aliases for global
158// variables.
159static void CheckODRViolationViaPoisoning(const Global *g) {
160 if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
161 // This check may not be enough: if the first global is much larger
162 // the entire redzone of the second global may be within the first global.
163 for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
164 if (g->beg == l->g->beg &&
165 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
166 !IsODRViolationSuppressed(g->name))
167 ReportODRViolation(g, FindRegistrationSite(g),
168 l->g, FindRegistrationSite(l->g));
169 }
170 }
171}
172
173// Clang provides two different ways for global variables protection: 156// Clang provides two different ways for global variables protection:
174// it can poison the global itself or its private alias. In former 157// it can poison the global itself or its private alias. In former
175// case we may poison same symbol multiple times, that can help us to 158// case we may poison same symbol multiple times, that can help us to
@@ -215,8 +198,6 @@ static void RegisterGlobal(const Global *g) {
215 // where two globals with the same name are defined in different modules. 198 // where two globals with the same name are defined in different modules.
216 if (UseODRIndicator(g)) 199 if (UseODRIndicator(g))
217 CheckODRViolationViaIndicator(g); 200 CheckODRViolationViaIndicator(g);
218 else
219 CheckODRViolationViaPoisoning(g);
220 } 201 }
221 if (CanPoisonMemory()) 202 if (CanPoisonMemory())
222 PoisonRedZones(*g); 203 PoisonRedZones(*g);
diff --git a/libsanitizer/asan/asan_interceptors.h b/libsanitizer/asan/asan_interceptors.h
index 047b044c8bf..105c672cc24 100644
--- a/libsanitizer/asan/asan_interceptors.h
+++ b/libsanitizer/asan/asan_interceptors.h
@@ -81,7 +81,12 @@ void InitializePlatformInterceptors();
81#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \ 81#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
82 !SANITIZER_NETBSD 82 !SANITIZER_NETBSD
83# define ASAN_INTERCEPT___CXA_THROW 1 83# define ASAN_INTERCEPT___CXA_THROW 1
84# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 84# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \
85 || ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION
86# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
87# else
88# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
89# endif
85# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__)) 90# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
86# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1 91# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
87# else 92# else
diff --git a/libsanitizer/asan/asan_mapping.h b/libsanitizer/asan/asan_mapping.h
index 4ff09b103d5..1b6669e1270 100644
--- a/libsanitizer/asan/asan_mapping.h
+++ b/libsanitizer/asan/asan_mapping.h
@@ -181,7 +181,7 @@
181# elif defined(__aarch64__) 181# elif defined(__aarch64__)
182# define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000 182# define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000
183# elif defined(__powerpc64__) 183# elif defined(__powerpc64__)
184# define ASAN_SHADOW_OFFSET_CONST 0x0000100000000000 184# define ASAN_SHADOW_OFFSET_CONST 0x0000020000000000
185# elif defined(__s390x__) 185# elif defined(__s390x__)
186# define ASAN_SHADOW_OFFSET_CONST 0x0010000000000000 186# define ASAN_SHADOW_OFFSET_CONST 0x0010000000000000
187# elif SANITIZER_FREEBSD 187# elif SANITIZER_FREEBSD
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
index 25ad825f568..d966d857a76 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -792,9 +792,13 @@ u32 GetNumberOfCPUs() {
792#elif SANITIZER_SOLARIS 792#elif SANITIZER_SOLARIS
793 return sysconf(_SC_NPROCESSORS_ONLN); 793 return sysconf(_SC_NPROCESSORS_ONLN);
794#else 794#else
795#if defined(CPU_COUNT)
795 cpu_set_t CPUs; 796 cpu_set_t CPUs;
796 CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); 797 CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
797 return CPU_COUNT(&CPUs); 798 return CPU_COUNT(&CPUs);
799#else
800 return 1;
801#endif
798#endif 802#endif
799} 803}
800 804
diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
index 05512a576ad..7ce8d670ecc 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
@@ -38,7 +38,7 @@
38extern char **environ; 38extern char **environ;
39#endif 39#endif
40 40
41#if defined(__has_include) && __has_include(<os/trace.h>) 41#if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__)
42#define SANITIZER_OS_TRACE 1 42#define SANITIZER_OS_TRACE 1
43#include <os/trace.h> 43#include <os/trace.h>
44#else 44#else
@@ -71,7 +71,15 @@ extern "C" {
71#include <mach/mach_time.h> 71#include <mach/mach_time.h>
72#include <mach/vm_statistics.h> 72#include <mach/vm_statistics.h>
73#include <malloc/malloc.h> 73#include <malloc/malloc.h>
74#include <os/log.h> 74#if defined(__has_builtin) && __has_builtin(__builtin_os_log_format)
75# include <os/log.h>
76#else
77 /* Without support for __builtin_os_log_format, fall back to the older
78 method. */
79# define OS_LOG_DEFAULT 0
80# define os_log_error(A,B,C) \
81 asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", (C));
82#endif
75#include <pthread.h> 83#include <pthread.h>
76#include <sched.h> 84#include <sched.h>
77#include <signal.h> 85#include <signal.h>
diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.h b/libsanitizer/sanitizer_common/sanitizer_mac.h
index 0b6af5a3c0e..96a5986a47a 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.h
+++ b/libsanitizer/sanitizer_common/sanitizer_mac.h
@@ -14,6 +14,26 @@
14 14
15#include "sanitizer_common.h" 15#include "sanitizer_common.h"
16#include "sanitizer_platform.h" 16#include "sanitizer_platform.h"
17
18/* TARGET_OS_OSX is not present in SDKs before Darwin16 (macOS 10.12) use
19 TARGET_OS_MAC (we have no support for iOS in any form for these versions,
20 so there's no ambiguity). */
21#if !defined(TARGET_OS_OSX) && TARGET_OS_MAC
22# define TARGET_OS_OSX 1
23#endif
24
25/* Other TARGET_OS_xxx are not present on earlier versions, define them to
26 0 (we have no support for them; they are not valid targets anyway). */
27#ifndef TARGET_OS_IOS
28#define TARGET_OS_IOS 0
29#endif
30#ifndef TARGET_OS_TV
31#define TARGET_OS_TV 0
32#endif
33#ifndef TARGET_OS_WATCH
34#define TARGET_OS_WATCH 0
35#endif
36
17#if SANITIZER_MAC 37#if SANITIZER_MAC
18#include "sanitizer_posix.h" 38#include "sanitizer_posix.h"
19 39
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
index 9d577570ea1..2b1a2f7932c 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
@@ -26,7 +26,10 @@
26 26
27// With old kernels (and even new kernels on powerpc) asm/stat.h uses types that 27// With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
28// are not defined anywhere in userspace headers. Fake them. This seems to work 28// are not defined anywhere in userspace headers. Fake them. This seems to work
29// fine with newer headers, too. 29// fine with newer headers, too. Beware that with <sys/stat.h>, struct stat
30// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64.
31// Also, for some platforms (e.g. mips) there are additional members in the
32// <sys/stat.h> struct stat:s.
30#include <linux/posix_types.h> 33#include <linux/posix_types.h>
31# if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__) 34# if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__)
32# include <sys/stat.h> 35# include <sys/stat.h>
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index 62a99035db3..89772a7e5c0 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -83,7 +83,7 @@ const unsigned struct_kernel_stat64_sz = 104;
83#elif defined(__mips__) 83#elif defined(__mips__)
84const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID 84const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
85 ? FIRST_32_SECOND_64(104, 128) 85 ? FIRST_32_SECOND_64(104, 128)
86 : FIRST_32_SECOND_64(160, 216); 86 : FIRST_32_SECOND_64(144, 216);
87const unsigned struct_kernel_stat64_sz = 104; 87const unsigned struct_kernel_stat64_sz = 104;
88#elif defined(__s390__) && !defined(__s390x__) 88#elif defined(__s390__) && !defined(__s390x__)
89const unsigned struct_kernel_stat_sz = 64; 89const unsigned struct_kernel_stat_sz = 64;
diff --git a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
index 3013a0c4abd..7386285f34b 100644
--- a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
@@ -87,8 +87,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
87 // Nope, this does not look right either. This means the frame after next does 87 // Nope, this does not look right either. This means the frame after next does
88 // not have a valid frame pointer, but we can still extract the caller PC. 88 // not have a valid frame pointer, but we can still extract the caller PC.
89 // Unfortunately, there is no way to decide between GCC and LLVM frame 89 // Unfortunately, there is no way to decide between GCC and LLVM frame
90 // layouts. Assume LLVM. 90 // layouts. Assume GCC.
91 return bp_prev; 91 return bp_prev - 1;
92#else 92#else
93 return (uhwptr*)bp; 93 return (uhwptr*)bp;
94#endif 94#endif
@@ -111,14 +111,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
111 IsAligned((uptr)frame, sizeof(*frame)) && 111 IsAligned((uptr)frame, sizeof(*frame)) &&
112 size < max_depth) { 112 size < max_depth) {
113#ifdef __powerpc__ 113#ifdef __powerpc__
114 // PowerPC ABIs specify that the return address is saved at offset 114 // PowerPC ABIs specify that the return address is saved on the
115 // 16 of the *caller's* stack frame. Thus we must dereference the 115 // *caller's* stack frame. Thus we must dereference the back chain
116 // back chain to find the caller frame before extracting it. 116 // to find the caller frame before extracting it.
117 uhwptr *caller_frame = (uhwptr*)frame[0]; 117 uhwptr *caller_frame = (uhwptr*)frame[0];
118 if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) || 118 if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
119 !IsAligned((uptr)caller_frame, sizeof(uhwptr))) 119 !IsAligned((uptr)caller_frame, sizeof(uhwptr)))
120 break; 120 break;
121 // For most ABIs the offset where the return address is saved is two
122 // register sizes. The exception is the SVR4 ABI, which uses an
123 // offset of only one register size.
124#ifdef _CALL_SYSV
125 uhwptr pc1 = caller_frame[1];
126#else
121 uhwptr pc1 = caller_frame[2]; 127 uhwptr pc1 = caller_frame[2];
128#endif
122#elif defined(__s390__) 129#elif defined(__s390__)
123 uhwptr pc1 = frame[14]; 130 uhwptr pc1 = frame[14];
124#elif defined(__riscv) 131#elif defined(__riscv)
diff --git a/libsanitizer/tsan/tsan_rtl_ppc64.S b/libsanitizer/tsan/tsan_rtl_ppc64.S
index 8285e21aa1e..9e533a71a9c 100644
--- a/libsanitizer/tsan/tsan_rtl_ppc64.S
+++ b/libsanitizer/tsan/tsan_rtl_ppc64.S
@@ -1,5 +1,6 @@
1#include "tsan_ppc_regs.h" 1#include "tsan_ppc_regs.h"
2 2
3 .machine altivec
3 .section .text 4 .section .text
4 .hidden __tsan_setjmp 5 .hidden __tsan_setjmp
5 .globl _setjmp 6 .globl _setjmp
diff --git a/libsanitizer/ubsan/ubsan_flags.cpp b/libsanitizer/ubsan/ubsan_flags.cpp
index 25cefd46ce2..9a66bd37518 100644
--- a/libsanitizer/ubsan/ubsan_flags.cpp
+++ b/libsanitizer/ubsan/ubsan_flags.cpp
@@ -50,6 +50,7 @@ void InitializeFlags() {
50 { 50 {
51 CommonFlags cf; 51 CommonFlags cf;
52 cf.CopyFrom(*common_flags()); 52 cf.CopyFrom(*common_flags());
53 cf.print_summary = false;
53 cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH"); 54 cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
54 OverrideCommonFlags(cf); 55 OverrideCommonFlags(cf);
55 } 56 }
diff --git a/libsanitizer/ubsan/ubsan_handlers.cpp b/libsanitizer/ubsan/ubsan_handlers.cpp
index e201e6bba22..2184625aa6e 100644
--- a/libsanitizer/ubsan/ubsan_handlers.cpp
+++ b/libsanitizer/ubsan/ubsan_handlers.cpp
@@ -894,6 +894,21 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
894 894
895} // namespace __ubsan 895} // namespace __ubsan
896 896
897void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData,
898 ValueHandle Function) {
899 GET_REPORT_OPTIONS(false);
900 CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
901 handleCFIBadIcall(&Data, Function, Opts);
902}
903
904void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData,
905 ValueHandle Function) {
906 GET_REPORT_OPTIONS(true);
907 CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
908 handleCFIBadIcall(&Data, Function, Opts);
909 Die();
910}
911
897void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data, 912void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
898 ValueHandle Value, 913 ValueHandle Value,
899 uptr ValidVtable) { 914 uptr ValidVtable) {
diff --git a/libsanitizer/ubsan/ubsan_handlers.h b/libsanitizer/ubsan/ubsan_handlers.h
index 219fb15de55..9f412353fc0 100644
--- a/libsanitizer/ubsan/ubsan_handlers.h
+++ b/libsanitizer/ubsan/ubsan_handlers.h
@@ -215,12 +215,20 @@ enum CFITypeCheckKind : unsigned char {
215 CFITCK_VMFCall, 215 CFITCK_VMFCall,
216}; 216};
217 217
218struct CFIBadIcallData {
219 SourceLocation Loc;
220 const TypeDescriptor &Type;
221};
222
218struct CFICheckFailData { 223struct CFICheckFailData {
219 CFITypeCheckKind CheckKind; 224 CFITypeCheckKind CheckKind;
220 SourceLocation Loc; 225 SourceLocation Loc;
221 const TypeDescriptor &Type; 226 const TypeDescriptor &Type;
222}; 227};
223 228
229/// \brief Handle control flow integrity failure for indirect function calls.
230RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function)
231
224/// \brief Handle control flow integrity failures. 232/// \brief Handle control flow integrity failures.
225RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function, 233RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
226 uptr VtableIsValid) 234 uptr VtableIsValid)
diff --git a/libsanitizer/ubsan/ubsan_platform.h b/libsanitizer/ubsan/ubsan_platform.h
index d2cc2e10bd2..ad3e883f0f3 100644
--- a/libsanitizer/ubsan/ubsan_platform.h
+++ b/libsanitizer/ubsan/ubsan_platform.h
@@ -12,6 +12,7 @@
12#ifndef UBSAN_PLATFORM_H 12#ifndef UBSAN_PLATFORM_H
13#define UBSAN_PLATFORM_H 13#define UBSAN_PLATFORM_H
14 14
15#ifndef CAN_SANITIZE_UB
15// Other platforms should be easy to add, and probably work as-is. 16// Other platforms should be easy to add, and probably work as-is.
16#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ 17#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \
17 defined(__NetBSD__) || defined(__DragonFly__) || \ 18 defined(__NetBSD__) || defined(__DragonFly__) || \
@@ -21,5 +22,6 @@
21#else 22#else
22# define CAN_SANITIZE_UB 0 23# define CAN_SANITIZE_UB 0
23#endif 24#endif
25#endif //CAN_SANITIZE_UB
24 26
25#endif 27#endif