Skip to content

Commit 53de398

Browse files
authored
Add downstream compiler-rt changes from emscripten (#5)
1 parent 76eb0a3 commit 53de398

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

compiler-rt/lib/asan/asan_flags.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "ubsan/ubsan_platform.h"
2424

2525
#if SANITIZER_EMSCRIPTEN
26-
extern "C" void emscripten_builtin_free(void *);
27-
#include <emscripten/em_asm.h>
26+
#include <emscripten/heap.h>
27+
#include "emscripten_internal.h"
2828
#endif
2929

3030

@@ -130,20 +130,16 @@ void InitializeFlags() {
130130
// Override from Emscripten Module.
131131
// TODO: add EM_ASM_I64 and avoid using a double for a 64-bit pointer.
132132
#define MAKE_OPTION_LOAD(parser, name) \
133-
options = (char*)(long)EM_ASM_DOUBLE({ \
134-
return withBuiltinMalloc(function () { \
135-
return stringToNewUTF8(Module[name] || ""); \
136-
}); \
137-
}); \
133+
options = _emscripten_sanitizer_get_option(name); \
138134
parser.ParseString(options); \
139135
emscripten_builtin_free(options);
140136

141-
MAKE_OPTION_LOAD(asan_parser, 'ASAN_OPTIONS');
137+
MAKE_OPTION_LOAD(asan_parser, "ASAN_OPTIONS");
142138
#if CAN_SANITIZE_LEAKS
143-
MAKE_OPTION_LOAD(lsan_parser, 'LSAN_OPTIONS');
139+
MAKE_OPTION_LOAD(lsan_parser, "LSAN_OPTIONS");
144140
#endif
145141
#if CAN_SANITIZE_UB
146-
MAKE_OPTION_LOAD(ubsan_parser, 'UBSAN_OPTIONS');
142+
MAKE_OPTION_LOAD(ubsan_parser, "UBSAN_OPTIONS");
147143
#endif
148144
#else
149145
// Override from command line.

compiler-rt/lib/asan/asan_thread.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ void FinishThreadLocked(u32 tid) {
583583

584584
} // namespace __lsan
585585

586+
namespace __sanitizer {
587+
ThreadRegistry *GetThreadRegistryLocked() {
588+
return __lsan::GetAsanThreadRegistryLocked();
589+
}
590+
} // namespace __sanitizer
591+
586592
// ---------------------- Interface ---------------- {{{1
587593
using namespace __asan;
588594

compiler-rt/lib/lsan/lsan.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include "sanitizer_common/sanitizer_interface_internal.h"
2222

2323
#if SANITIZER_EMSCRIPTEN
24-
extern "C" void emscripten_builtin_free(void *);
25-
#include <emscripten/em_asm.h>
24+
#include "emscripten_internal.h"
25+
#include <emscripten/heap.h>
2626
#endif
2727

2828
bool lsan_inited;
@@ -82,11 +82,7 @@ static void InitializeFlags() {
8282
const char *lsan_default_options = __lsan_default_options();
8383
parser.ParseString(lsan_default_options);
8484
#if SANITIZER_EMSCRIPTEN
85-
char *options = (char*) EM_ASM_PTR({
86-
return withBuiltinMalloc(function () {
87-
return stringToNewUTF8(Module['LSAN_OPTIONS'] || "");
88-
});
89-
});
85+
char *options = _emscripten_sanitizer_get_option("LSAN_OPTIONS");
9086
parser.ParseString(options);
9187
emscripten_builtin_free(options);
9288
#else

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_iterate_dynamic_tls(
405405
pid_t, void (*cb)(void *, void *, uptr, void *), void *);
406406
# endif
407407

408-
#if !SANITIZER_EMSCRIPTEN
408+
#if SANITIZER_EMSCRIPTEN
409+
void ProcessThreads(SuspendedThreadsList const &, Frontier *, tid_t, uptr);
410+
#else
409411
static void ProcessThreadRegistry(Frontier *frontier) {
410412
InternalMmapVector<uptr> ptrs;
411413
GetAdditionalThreadContextPtrsLocked(&ptrs);

compiler-rt/lib/lsan/lsan_thread.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads) {
100100
}
101101

102102
} // namespace __lsan
103+
104+
namespace __sanitizer {
105+
ThreadRegistry *GetThreadRegistryLocked() {
106+
return __lsan::GetLsanThreadRegistryLocked();
107+
}
108+
} // namespace __sanitizer

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
# include <sys/mman.h>
2626
#endif
2727

28+
#if SANITIZER_EMSCRIPTEN
29+
#include "emscripten_internal.h"
30+
#endif
31+
2832
namespace __sanitizer {
2933

3034
#if !SANITIZER_GO
@@ -41,17 +45,9 @@ void ReportErrorSummary(const char *error_type, const AddressInfo &info,
4145
#endif
4246

4347
#if SANITIZER_EMSCRIPTEN
44-
#include <emscripten/em_asm.h>
4548

4649
static inline bool ReportSupportsColors() {
47-
return !!EM_ASM_INT({
48-
var setting = Module['printWithColors'];
49-
if (setting != null) {
50-
return setting;
51-
} else {
52-
return ENVIRONMENT_IS_NODE && process.stderr.isTTY;
53-
}
54-
});
50+
return _emscripten_sanitizer_use_colors();
5551
}
5652

5753
#elif !SANITIZER_FUCHSIA

compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class SANITIZER_MUTEX ThreadRegistry {
163163

164164
typedef GenericScopedLock<ThreadRegistry> ThreadRegistryLock;
165165

166+
ThreadRegistry *GetThreadRegistryLocked();
167+
166168
} // namespace __sanitizer
167169

168170
#endif // SANITIZER_THREAD_REGISTRY_H

compiler-rt/lib/ubsan/ubsan_flags.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <stdlib.h>
2121

2222
#if SANITIZER_EMSCRIPTEN
23-
extern "C" void emscripten_builtin_free(void *);
24-
#include <emscripten/em_asm.h>
23+
#include <emscripten/heap.h>
24+
#include "emscripten_internal.h"
2525
#endif
2626

2727
namespace __ubsan {
@@ -77,11 +77,7 @@ void InitializeFlags() {
7777
parser.ParseString(__ubsan_default_options());
7878
// Override from environment variable.
7979
#if SANITIZER_EMSCRIPTEN
80-
char *options = (char*) EM_ASM_PTR({
81-
return withBuiltinMalloc(function () {
82-
return stringToNewUTF8(Module['UBSAN_OPTIONS'] || "");
83-
});
84-
});
80+
char* options = _emscripten_sanitizer_get_option("UBSAN_OPTIONS");
8581
parser.ParseString(options);
8682
emscripten_builtin_free(options);
8783
#else

0 commit comments

Comments
 (0)