Skip to content

Commit d72227e

Browse files
committed
libsanitizer: Apply local patches.
1 parent 98f792f commit d72227e

14 files changed

+77
-30
lines changed

libsanitizer/asan/asan_globals.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
154154
}
155155
}
156156

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.
160-
static 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-
174157
// Clang provides two different ways for global variables protection:
175158
// it can poison the global itself or its private alias. In former
176159
// case we may poison same symbol multiple times, that can help us to
@@ -216,8 +199,6 @@ static void RegisterGlobal(const Global *g) {
216199
// where two globals with the same name are defined in different modules.
217200
if (UseODRIndicator(g))
218201
CheckODRViolationViaIndicator(g);
219-
else
220-
CheckODRViolationViaPoisoning(g);
221202
}
222203
if (CanPoisonMemory())
223204
PoisonRedZones(*g);

libsanitizer/asan/asan_interceptors.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ void InitializePlatformInterceptors();
8181
#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
8282
!SANITIZER_NETBSD
8383
# 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
8590
# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
8691
# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
8792
# else

libsanitizer/asan/asan_mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
178178
static const u64 kRiscv64_ShadowOffset64 = 0x20000000;
179179
static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000;
180180
static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
181-
static const u64 kPPC64_ShadowOffset64 = 1ULL << 44;
181+
static const u64 kPPC64_ShadowOffset64 = 1ULL << 41;
182182
static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52;
183183
static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000
184184
static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000

libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,13 @@ u32 GetNumberOfCPUs() {
729729
#elif SANITIZER_SOLARIS
730730
return sysconf(_SC_NPROCESSORS_ONLN);
731731
#else
732+
#if defined(CPU_COUNT)
732733
cpu_set_t CPUs;
733734
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
734735
return CPU_COUNT(&CPUs);
736+
#else
737+
return 1;
738+
#endif
735739
#endif
736740
}
737741

libsanitizer/sanitizer_common/sanitizer_mac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
extern char **environ;
3838
#endif
3939

40-
#if defined(__has_include) && __has_include(<os/trace.h>)
40+
#if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__)
4141
#define SANITIZER_OS_TRACE 1
4242
#include <os/trace.h>
4343
#else

libsanitizer/sanitizer_common/sanitizer_mac.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414

1515
#include "sanitizer_common.h"
1616
#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+
1737
#if SANITIZER_MAC
1838
#include "sanitizer_posix.h"
1939

libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
// With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
2828
// 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.
3033
#include <linux/posix_types.h>
31-
#if defined(__x86_64__) || defined(__mips__)
34+
#if defined(__x86_64__)
3235
#include <sys/stat.h>
3336
#else
3437
#define ino_t __kernel_ino_t

libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const unsigned struct_kernel_stat64_sz = 104;
8383
#elif defined(__mips__)
8484
const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
8585
? FIRST_32_SECOND_64(104, 128)
86-
: FIRST_32_SECOND_64(160, 216);
86+
: FIRST_32_SECOND_64(144, 216);
8787
const unsigned struct_kernel_stat64_sz = 104;
8888
#elif defined(__s390__) && !defined(__s390x__)
8989
const unsigned struct_kernel_stat_sz = 64;

libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
8484
// Nope, this does not look right either. This means the frame after next does
8585
// not have a valid frame pointer, but we can still extract the caller PC.
8686
// Unfortunately, there is no way to decide between GCC and LLVM frame
87-
// layouts. Assume LLVM.
88-
return bp_prev;
87+
// layouts. Assume GCC.
88+
return bp_prev - 1;
8989
#else
9090
return (uhwptr*)bp;
9191
#endif
@@ -108,14 +108,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
108108
IsAligned((uptr)frame, sizeof(*frame)) &&
109109
size < max_depth) {
110110
#ifdef __powerpc__
111-
// PowerPC ABIs specify that the return address is saved at offset
112-
// 16 of the *caller's* stack frame. Thus we must dereference the
113-
// back chain to find the caller frame before extracting it.
111+
// PowerPC ABIs specify that the return address is saved on the
112+
// *caller's* stack frame. Thus we must dereference the back chain
113+
// to find the caller frame before extracting it.
114114
uhwptr *caller_frame = (uhwptr*)frame[0];
115115
if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
116116
!IsAligned((uptr)caller_frame, sizeof(uhwptr)))
117117
break;
118+
// For most ABIs the offset where the return address is saved is two
119+
// register sizes. The exception is the SVR4 ABI, which uses an
120+
// offset of only one register size.
121+
#ifdef _CALL_SYSV
122+
uhwptr pc1 = caller_frame[1];
123+
#else
118124
uhwptr pc1 = caller_frame[2];
125+
#endif
119126
#elif defined(__s390__)
120127
uhwptr pc1 = frame[14];
121128
#elif defined(__riscv)

libsanitizer/tsan/tsan_rtl_ppc64.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "tsan_ppc_regs.h"
22

3+
.machine altivec
34
.section .text
45
.hidden __tsan_setjmp
56
.globl _setjmp

0 commit comments

Comments
 (0)