Skip to content

Add downstream compiler-rt changes from emscripten #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions compiler-rt/lib/asan/asan_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "ubsan/ubsan_platform.h"

#if SANITIZER_EMSCRIPTEN
extern "C" void emscripten_builtin_free(void *);
#include <emscripten/em_asm.h>
#include <emscripten/heap.h>
#include "emscripten_internal.h"
#endif


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

MAKE_OPTION_LOAD(asan_parser, 'ASAN_OPTIONS');
MAKE_OPTION_LOAD(asan_parser, "ASAN_OPTIONS");
#if CAN_SANITIZE_LEAKS
MAKE_OPTION_LOAD(lsan_parser, 'LSAN_OPTIONS');
MAKE_OPTION_LOAD(lsan_parser, "LSAN_OPTIONS");
#endif
#if CAN_SANITIZE_UB
MAKE_OPTION_LOAD(ubsan_parser, 'UBSAN_OPTIONS');
MAKE_OPTION_LOAD(ubsan_parser, "UBSAN_OPTIONS");
#endif
#else
// Override from command line.
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/lib/asan/asan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ void FinishThreadLocked(u32 tid) {

} // namespace __lsan

namespace __sanitizer {
ThreadRegistry *GetThreadRegistryLocked() {
return __lsan::GetAsanThreadRegistryLocked();
}
} // namespace __sanitizer

// ---------------------- Interface ---------------- {{{1
using namespace __asan;

Expand Down
10 changes: 3 additions & 7 deletions compiler-rt/lib/lsan/lsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "sanitizer_common/sanitizer_interface_internal.h"

#if SANITIZER_EMSCRIPTEN
extern "C" void emscripten_builtin_free(void *);
#include <emscripten/em_asm.h>
#include "emscripten_internal.h"
#include <emscripten/heap.h>
#endif

bool lsan_inited;
Expand Down Expand Up @@ -82,11 +82,7 @@ static void InitializeFlags() {
const char *lsan_default_options = __lsan_default_options();
parser.ParseString(lsan_default_options);
#if SANITIZER_EMSCRIPTEN
char *options = (char*) EM_ASM_PTR({
return withBuiltinMalloc(function () {
return stringToNewUTF8(Module['LSAN_OPTIONS'] || "");
});
});
char *options = _emscripten_sanitizer_get_option("LSAN_OPTIONS");
parser.ParseString(options);
emscripten_builtin_free(options);
#else
Expand Down
4 changes: 3 additions & 1 deletion compiler-rt/lib/lsan/lsan_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_iterate_dynamic_tls(
pid_t, void (*cb)(void *, void *, uptr, void *), void *);
# endif

#if !SANITIZER_EMSCRIPTEN
#if SANITIZER_EMSCRIPTEN
void ProcessThreads(SuspendedThreadsList const &, Frontier *, tid_t, uptr);
#else
static void ProcessThreadRegistry(Frontier *frontier) {
InternalMmapVector<uptr> ptrs;
GetAdditionalThreadContextPtrsLocked(&ptrs);
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/lib/lsan/lsan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,9 @@ void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads) {
}

} // namespace __lsan

namespace __sanitizer {
ThreadRegistry *GetThreadRegistryLocked() {
return __lsan::GetLsanThreadRegistryLocked();
}
} // namespace __sanitizer
14 changes: 5 additions & 9 deletions compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
# include <sys/mman.h>
#endif

#if SANITIZER_EMSCRIPTEN
#include "emscripten_internal.h"
#endif

namespace __sanitizer {

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

#if SANITIZER_EMSCRIPTEN
#include <emscripten/em_asm.h>

static inline bool ReportSupportsColors() {
return !!EM_ASM_INT({
var setting = Module['printWithColors'];
if (setting != null) {
return setting;
} else {
return ENVIRONMENT_IS_NODE && process.stderr.isTTY;
}
});
return _emscripten_sanitizer_use_colors();
}

#elif !SANITIZER_FUCHSIA
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class SANITIZER_MUTEX ThreadRegistry {

typedef GenericScopedLock<ThreadRegistry> ThreadRegistryLock;

ThreadRegistry *GetThreadRegistryLocked();

} // namespace __sanitizer

#endif // SANITIZER_THREAD_REGISTRY_H
10 changes: 3 additions & 7 deletions compiler-rt/lib/ubsan/ubsan_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <stdlib.h>

#if SANITIZER_EMSCRIPTEN
extern "C" void emscripten_builtin_free(void *);
#include <emscripten/em_asm.h>
#include <emscripten/heap.h>
#include "emscripten_internal.h"
#endif

namespace __ubsan {
Expand Down Expand Up @@ -77,11 +77,7 @@ void InitializeFlags() {
parser.ParseString(__ubsan_default_options());
// Override from environment variable.
#if SANITIZER_EMSCRIPTEN
char *options = (char*) EM_ASM_PTR({
return withBuiltinMalloc(function () {
return stringToNewUTF8(Module['UBSAN_OPTIONS'] || "");
});
});
char* options = _emscripten_sanitizer_get_option("UBSAN_OPTIONS");
parser.ParseString(options);
emscripten_builtin_free(options);
#else
Expand Down