Skip to content

Commit 98f792f

Browse files
committed
libsanitizer: merge from master.
1 parent a514934 commit 98f792f

File tree

92 files changed

+580
-1315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+580
-1315
lines changed

libsanitizer/MERGE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
51ff04567b2f8d06b2062bd3ed72eab2e93e4466
1+
a28a466210199559d38251c11f30515cc83eadd6
22

33
The first line of this file holds the git revision number of the
44
last merge done from the master library sources.

libsanitizer/asan/asan_fuchsia.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ struct AsanThread::InitOptions {
9191
// Shared setup between thread creation and startup for the initial thread.
9292
static AsanThread *CreateAsanThread(StackTrace *stack, u32 parent_tid,
9393
uptr user_id, bool detached,
94-
const char *name, uptr stack_bottom,
95-
uptr stack_size) {
94+
const char *name) {
9695
// In lieu of AsanThread::Create.
9796
AsanThread *thread = (AsanThread *)MmapOrDie(AsanThreadMmapSize(), __func__);
9897

@@ -101,12 +100,6 @@ static AsanThread *CreateAsanThread(StackTrace *stack, u32 parent_tid,
101100
asanThreadRegistry().CreateThread(user_id, detached, parent_tid, &args);
102101
asanThreadRegistry().SetThreadName(tid, name);
103102

104-
// On other systems, AsanThread::Init() is called from the new
105-
// thread itself. But on Fuchsia we already know the stack address
106-
// range beforehand, so we can do most of the setup right now.
107-
const AsanThread::InitOptions options = {stack_bottom, stack_size};
108-
thread->Init(&options);
109-
110103
return thread;
111104
}
112105

@@ -135,9 +128,16 @@ AsanThread *CreateMainThread() {
135128
_zx_object_get_property(thrd_get_zx_handle(self), ZX_PROP_NAME, name,
136129
sizeof(name)) == ZX_OK
137130
? name
138-
: nullptr,
139-
__sanitizer::MainThreadStackBase, __sanitizer::MainThreadStackSize);
131+
: nullptr);
132+
// We need to set the current thread before calling AsanThread::Init() below,
133+
// since it reads the thread ID.
140134
SetCurrentThread(t);
135+
DCHECK_EQ(t->tid(), 0);
136+
137+
const AsanThread::InitOptions options = {__sanitizer::MainThreadStackBase,
138+
__sanitizer::MainThreadStackSize};
139+
t->Init(&options);
140+
141141
return t;
142142
}
143143

@@ -153,8 +153,15 @@ static void *BeforeThreadCreateHook(uptr user_id, bool detached,
153153
GET_STACK_TRACE_THREAD;
154154
u32 parent_tid = GetCurrentTidOrInvalid();
155155

156-
return CreateAsanThread(&stack, parent_tid, user_id, detached, name,
157-
stack_bottom, stack_size);
156+
AsanThread *thread =
157+
CreateAsanThread(&stack, parent_tid, user_id, detached, name);
158+
159+
// On other systems, AsanThread::Init() is called from the new
160+
// thread itself. But on Fuchsia we already know the stack address
161+
// range beforehand, so we can do most of the setup right now.
162+
const AsanThread::InitOptions options = {stack_bottom, stack_size};
163+
thread->Init(&options);
164+
return thread;
158165
}
159166

160167
// This is called after creating a new thread (in the creating thread),

libsanitizer/asan/asan_globals.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ 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+
157174
// Clang provides two different ways for global variables protection:
158175
// it can poison the global itself or its private alias. In former
159176
// case we may poison same symbol multiple times, that can help us to
@@ -199,6 +216,8 @@ static void RegisterGlobal(const Global *g) {
199216
// where two globals with the same name are defined in different modules.
200217
if (UseODRIndicator(g))
201218
CheckODRViolationViaIndicator(g);
219+
else
220+
CheckODRViolationViaPoisoning(g);
202221
}
203222
if (CanPoisonMemory())
204223
PoisonRedZones(*g);

libsanitizer/asan/asan_interceptors.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ void InitializePlatformInterceptors();
8181
#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
8282
!SANITIZER_NETBSD
8383
# define ASAN_INTERCEPT___CXA_THROW 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
84+
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
9085
# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
9186
# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
9287
# 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 << 41;
181+
static const u64 kPPC64_ShadowOffset64 = 1ULL << 44;
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/asan/asan_report.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ class ScopedInErrorReport {
151151
if (common_flags()->print_cmdline)
152152
PrintCmdline();
153153

154-
if (common_flags()->print_module_map == 2) PrintModuleMap();
154+
if (common_flags()->print_module_map == 2)
155+
DumpProcessMap();
155156

156157
// Copy the message buffer so that we could start logging without holding a
157158
// lock that gets aquired during printing.

libsanitizer/asan/asan_rtl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static void AsanDie() {
4545
// Don't die twice - run a busy loop.
4646
while (1) { }
4747
}
48-
if (common_flags()->print_module_map >= 1) PrintModuleMap();
48+
if (common_flags()->print_module_map >= 1)
49+
DumpProcessMap();
4950
if (flags()->sleep_before_dying) {
5051
Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying);
5152
SleepForSeconds(flags()->sleep_before_dying);

libsanitizer/asan/asan_thread.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ uptr AsanThread::stack_size() {
188188
return bounds.top - bounds.bottom;
189189
}
190190

191-
// We want to create the FakeStack lazyly on the first use, but not eralier
191+
// We want to create the FakeStack lazily on the first use, but not earlier
192192
// than the stack size is known and the procedure has to be async-signal safe.
193193
FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
194194
uptr stack_size = this->stack_size();
@@ -211,13 +211,15 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
211211
stack_size_log =
212212
Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
213213
fake_stack_ = FakeStack::Create(stack_size_log);
214+
DCHECK_EQ(GetCurrentThread(), this);
214215
SetTLSFakeStack(fake_stack_);
215216
return fake_stack_;
216217
}
217218
return nullptr;
218219
}
219220

220221
void AsanThread::Init(const InitOptions *options) {
222+
DCHECK_NE(tid(), ThreadRegistry::kUnknownTid);
221223
next_stack_top_ = next_stack_bottom_ = 0;
222224
atomic_store(&stack_switching_, false, memory_order_release);
223225
CHECK_EQ(this->stack_size(), 0U);
@@ -229,8 +231,17 @@ void AsanThread::Init(const InitOptions *options) {
229231
}
230232
ClearShadowForThreadStackAndTLS();
231233
fake_stack_ = nullptr;
232-
if (__asan_option_detect_stack_use_after_return)
234+
if (__asan_option_detect_stack_use_after_return &&
235+
tid() == GetCurrentTidOrInvalid()) {
236+
// AsyncSignalSafeLazyInitFakeStack makes use of threadlocals and must be
237+
// called from the context of the thread it is initializing, not its parent.
238+
// Most platforms call AsanThread::Init on the newly-spawned thread, but
239+
// Fuchsia calls this function from the parent thread. To support that
240+
// approach, we avoid calling AsyncSignalSafeLazyInitFakeStack here; it will
241+
// be called by the new thread when it first attempts to access the fake
242+
// stack.
233243
AsyncSignalSafeLazyInitFakeStack();
244+
}
234245
int local = 0;
235246
VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(),
236247
(void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_,

libsanitizer/asan/asan_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AsanThread;
3535

3636
// These objects are created for every thread and are never deleted,
3737
// so we can find them by tid even if the thread is long dead.
38-
class AsanThreadContext : public ThreadContextBase {
38+
class AsanThreadContext final : public ThreadContextBase {
3939
public:
4040
explicit AsanThreadContext(int tid)
4141
: ThreadContextBase(tid), announced(false),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//===-- sanitizer/memprof_interface.h --------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file is a part of MemProfiler (MemProf).
10+
//
11+
// Public interface header.
12+
//===----------------------------------------------------------------------===//
13+
#ifndef SANITIZER_MEMPROF_INTERFACE_H
14+
#define SANITIZER_MEMPROF_INTERFACE_H
15+
16+
#include <sanitizer/common_interface_defs.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
/// Records access to a memory region (<c>[addr, addr+size)</c>).
22+
///
23+
/// This memory must be previously allocated by your program.
24+
///
25+
/// \param addr Start of memory region.
26+
/// \param size Size of memory region.
27+
void __memprof_record_access_range(void const volatile *addr, size_t size);
28+
29+
/// Records access to a memory address <c><i>addr</i></c>.
30+
///
31+
/// This memory must be previously allocated by your program.
32+
///
33+
/// \param addr Accessed memory address
34+
void __memprof_record_access(void const volatile *addr);
35+
36+
/// User-provided callback on MemProf errors.
37+
///
38+
/// You can provide a function that would be called immediately when MemProf
39+
/// detects an error. This is useful in cases when MemProf detects an error but
40+
/// your program crashes before the MemProf report is printed.
41+
void __memprof_on_error(void);
42+
43+
/// Prints accumulated statistics to <c>stderr</c> (useful for calling from the
44+
/// debugger).
45+
void __memprof_print_accumulated_stats(void);
46+
47+
/// User-provided default option settings.
48+
///
49+
/// You can provide your own implementation of this function to return a string
50+
/// containing MemProf runtime options (for example,
51+
/// <c>verbosity=1:print_stats=1</c>).
52+
///
53+
/// \returns Default options string.
54+
const char *__memprof_default_options(void);
55+
56+
#ifdef __cplusplus
57+
} // extern "C"
58+
#endif
59+
60+
#endif // SANITIZER_MEMPROF_INTERFACE_H

0 commit comments

Comments
 (0)