2222#include " ubsan/ubsan_flags.h"
2323#include " ubsan/ubsan_platform.h"
2424
25+ #if SANITIZER_EMSCRIPTEN
26+ #include < emscripten/heap.h>
27+ #include " emscripten_internal.h"
28+ #endif
29+
30+
2531namespace __asan {
2632
2733Flags asan_flags_dont_use_directly; // use via flags().
@@ -54,7 +60,11 @@ void InitializeFlags() {
5460 CommonFlags cf;
5561 cf.CopyFrom (*common_flags ());
5662 cf.detect_leaks = cf.detect_leaks && CAN_SANITIZE_LEAKS;
63+ #if !SANITIZER_EMSCRIPTEN
64+ // getenv on emscripten uses malloc, which we can't when using LSan.
65+ // You can't run external symbolizer executables anyway.
5766 cf.external_symbolizer_path = GetEnv (" ASAN_SYMBOLIZER_PATH" );
67+ #endif
5868 cf.malloc_context_size = kDefaultMallocContextSize ;
5969 cf.intercept_tls_get_addr = true ;
6070 cf.exitcode = 1 ;
@@ -115,6 +125,23 @@ void InitializeFlags() {
115125 lsan_parser.ParseString (lsan_default_options);
116126#endif
117127
128+ #if SANITIZER_EMSCRIPTEN
129+ char *options;
130+ // Override from Emscripten Module.
131+ // TODO: add EM_ASM_I64 and avoid using a double for a 64-bit pointer.
132+ #define MAKE_OPTION_LOAD (parser, name ) \
133+ options = _emscripten_sanitizer_get_option (name); \
134+ parser.ParseString (options); \
135+ emscripten_builtin_free (options);
136+
137+ MAKE_OPTION_LOAD (asan_parser, " ASAN_OPTIONS" );
138+ #if CAN_SANITIZE_LEAKS
139+ MAKE_OPTION_LOAD (lsan_parser, " LSAN_OPTIONS" );
140+ #endif
141+ #if CAN_SANITIZE_UB
142+ MAKE_OPTION_LOAD (ubsan_parser, " UBSAN_OPTIONS" );
143+ #endif
144+ #else
118145 // Override from command line.
119146 asan_parser.ParseStringFromEnv (" ASAN_OPTIONS" );
120147#if CAN_SANITIZE_LEAKS
@@ -123,12 +150,18 @@ void InitializeFlags() {
123150#if CAN_SANITIZE_UB
124151 ubsan_parser.ParseStringFromEnv (" UBSAN_OPTIONS" );
125152#endif
153+ #endif // SANITIZER_EMSCRIPTEN
126154
127155 InitializeCommonFlags ();
128156
129157 // TODO(eugenis): dump all flags at verbosity>=2?
130158 if (Verbosity ()) ReportUnrecognizedFlags ();
131159
160+ #if SANITIZER_EMSCRIPTEN
161+ if (common_flags ()->malloc_context_size <= 1 )
162+ StackTrace::snapshot_stack = false ;
163+ #endif // SANITIZER_EMSCRIPTEN
164+
132165 if (common_flags ()->help ) {
133166 // TODO(samsonov): print all of the flags (ASan, LSan, common).
134167 asan_parser.PrintFlagDescriptions ();
0 commit comments