summaryrefslogtreecommitdiffstats
path: root/libsanitizer
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-07-20 10:46:51 -0700
committerH.J. Lu <hjl.tools@gmail.com>2021-10-06 13:08:47 -0700
commitbb8adf080ef03288bccd9f1316ae2a1122ebcd85 (patch)
tree08a787e804a56d2630c6d2bcee8249e6e3ad106a /libsanitizer
parentlibsanitizer: Merge with upstream (diff)
downloadgcc-bb8adf080ef03288bccd9f1316ae2a1122ebcd85.tar.gz
gcc-bb8adf080ef03288bccd9f1316ae2a1122ebcd85.tar.bz2
gcc-bb8adf080ef03288bccd9f1316ae2a1122ebcd85.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 9bf378f6207..763d3c6d2c0 100644
--- a/libsanitizer/asan/asan_globals.cpp
+++ b/libsanitizer/asan/asan_globals.cpp
@@ -154,23 +154,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
154 } 154 }
155} 155}
156 156
157// Check ODR violation for given global G by checking if it's already poisoned.
158// We use this method in case compiler doesn't use private aliases for global
159// variables.
160static void CheckODRViolationViaPoisoning(const Global *g) {
161 if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
162 // This check may not be enough: if the first global is much larger
163 // the entire redzone of the second global may be within the first global.
164 for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
165 if (g->beg == l->g->beg &&
166 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
167 !IsODRViolationSuppressed(g->name))
168 ReportODRViolation(g, FindRegistrationSite(g),
169 l->g, FindRegistrationSite(l->g));
170 }
171 }
172}
173
174// Clang provides two different ways for global variables protection: 157// Clang provides two different ways for global variables protection:
175// it can poison the global itself or its private alias. In former 158// it can poison the global itself or its private alias. In former
176// case we may poison same symbol multiple times, that can help us to 159// case we may poison same symbol multiple times, that can help us to
@@ -216,8 +199,6 @@ static void RegisterGlobal(const Global *g) {
216 // where two globals with the same name are defined in different modules. 199 // where two globals with the same name are defined in different modules.
217 if (UseODRIndicator(g)) 200 if (UseODRIndicator(g))
218 CheckODRViolationViaIndicator(g); 201 CheckODRViolationViaIndicator(g);
219 else
220 CheckODRViolationViaPoisoning(g);
221 } 202 }
222 if (CanPoisonMemory()) 203 if (CanPoisonMemory())
223 PoisonRedZones(*g); 204 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 e5a7f2007ae..4b0037fced3 100644
--- a/libsanitizer/asan/asan_mapping.h
+++ b/libsanitizer/asan/asan_mapping.h
@@ -165,7 +165,7 @@ static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
165static const u64 kRiscv64_ShadowOffset64 = 0xd55550000; 165static const u64 kRiscv64_ShadowOffset64 = 0xd55550000;
166static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000; 166static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000;
167static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37; 167static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
168static const u64 kPPC64_ShadowOffset64 = 1ULL << 44; 168static const u64 kPPC64_ShadowOffset64 = 1ULL << 41;
169static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52; 169static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52;
170static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000 170static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000
171static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000 171static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
index 7ce9e25da34..fc5619e4b37 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -759,9 +759,13 @@ u32 GetNumberOfCPUs() {
759#elif SANITIZER_SOLARIS 759#elif SANITIZER_SOLARIS
760 return sysconf(_SC_NPROCESSORS_ONLN); 760 return sysconf(_SC_NPROCESSORS_ONLN);
761#else 761#else
762#if defined(CPU_COUNT)
762 cpu_set_t CPUs; 763 cpu_set_t CPUs;
763 CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); 764 CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
764 return CPU_COUNT(&CPUs); 765 return CPU_COUNT(&CPUs);
766#else
767 return 1;
768#endif
765#endif 769#endif
766} 770}
767 771
diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
index b8839f197d2..fa077a129c2 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
@@ -37,7 +37,7 @@
37extern char **environ; 37extern char **environ;
38#endif 38#endif
39 39
40#if defined(__has_include) && __has_include(<os/trace.h>) 40#if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__)
41#define SANITIZER_OS_TRACE 1 41#define SANITIZER_OS_TRACE 1
42#include <os/trace.h> 42#include <os/trace.h>
43#else 43#else
@@ -70,7 +70,15 @@ extern "C" {
70#include <mach/mach_time.h> 70#include <mach/mach_time.h>
71#include <mach/vm_statistics.h> 71#include <mach/vm_statistics.h>
72#include <malloc/malloc.h> 72#include <malloc/malloc.h>
73#include <os/log.h> 73#if defined(__has_builtin) && __has_builtin(__builtin_os_log_format)
74# include <os/log.h>
75#else
76 /* Without support for __builtin_os_log_format, fall back to the older
77 method. */
78# define OS_LOG_DEFAULT 0
79# define os_log_error(A,B,C) \
80 asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", (C));
81#endif
74#include <pthread.h> 82#include <pthread.h>
75#include <sched.h> 83#include <sched.h>
76#include <signal.h> 84#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 d69b344dd61..da53b5abef2 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 4707c6c5d00..15ea4954aa4 100644
--- a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
@@ -86,8 +86,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
86 // Nope, this does not look right either. This means the frame after next does 86 // Nope, this does not look right either. This means the frame after next does
87 // not have a valid frame pointer, but we can still extract the caller PC. 87 // not have a valid frame pointer, but we can still extract the caller PC.
88 // Unfortunately, there is no way to decide between GCC and LLVM frame 88 // Unfortunately, there is no way to decide between GCC and LLVM frame
89 // layouts. Assume LLVM. 89 // layouts. Assume GCC.
90 return bp_prev; 90 return bp_prev - 1;
91#else 91#else
92 return (uhwptr*)bp; 92 return (uhwptr*)bp;
93#endif 93#endif
@@ -110,14 +110,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
110 IsAligned((uptr)frame, sizeof(*frame)) && 110 IsAligned((uptr)frame, sizeof(*frame)) &&
111 size < max_depth) { 111 size < max_depth) {
112#ifdef __powerpc__ 112#ifdef __powerpc__
113 // PowerPC ABIs specify that the return address is saved at offset 113 // PowerPC ABIs specify that the return address is saved on the
114 // 16 of the *caller's* stack frame. Thus we must dereference the 114 // *caller's* stack frame. Thus we must dereference the back chain
115 // back chain to find the caller frame before extracting it. 115 // to find the caller frame before extracting it.
116 uhwptr *caller_frame = (uhwptr*)frame[0]; 116 uhwptr *caller_frame = (uhwptr*)frame[0];
117 if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) || 117 if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
118 !IsAligned((uptr)caller_frame, sizeof(uhwptr))) 118 !IsAligned((uptr)caller_frame, sizeof(uhwptr)))
119 break; 119 break;
120 // For most ABIs the offset where the return address is saved is two
121 // register sizes. The exception is the SVR4 ABI, which uses an
122 // offset of only one register size.
123#ifdef _CALL_SYSV
124 uhwptr pc1 = caller_frame[1];
125#else
120 uhwptr pc1 = caller_frame[2]; 126 uhwptr pc1 = caller_frame[2];
127#endif
121#elif defined(__s390__) 128#elif defined(__s390__)
122 uhwptr pc1 = frame[14]; 129 uhwptr pc1 = frame[14];
123#elif defined(__riscv) 130#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