22
22
#include " ubsan/ubsan_flags.h"
23
23
#include " ubsan/ubsan_platform.h"
24
24
25
+ #if SANITIZER_EMSCRIPTEN
26
+ #include < emscripten/heap.h>
27
+ #include " emscripten_internal.h"
28
+ #endif
29
+
30
+
25
31
namespace __asan {
26
32
27
33
Flags asan_flags_dont_use_directly; // use via flags().
@@ -54,7 +60,11 @@ void InitializeFlags() {
54
60
CommonFlags cf;
55
61
cf.CopyFrom (*common_flags ());
56
62
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.
57
66
cf.external_symbolizer_path = GetEnv (" ASAN_SYMBOLIZER_PATH" );
67
+ #endif
58
68
cf.malloc_context_size = kDefaultMallocContextSize ;
59
69
cf.intercept_tls_get_addr = true ;
60
70
cf.exitcode = 1 ;
@@ -115,6 +125,23 @@ void InitializeFlags() {
115
125
lsan_parser.ParseString (lsan_default_options);
116
126
#endif
117
127
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
118
145
// Override from command line.
119
146
asan_parser.ParseStringFromEnv (" ASAN_OPTIONS" );
120
147
#if CAN_SANITIZE_LEAKS
@@ -123,12 +150,18 @@ void InitializeFlags() {
123
150
#if CAN_SANITIZE_UB
124
151
ubsan_parser.ParseStringFromEnv (" UBSAN_OPTIONS" );
125
152
#endif
153
+ #endif // SANITIZER_EMSCRIPTEN
126
154
127
155
InitializeCommonFlags ();
128
156
129
157
// TODO(eugenis): dump all flags at verbosity>=2?
130
158
if (Verbosity ()) ReportUnrecognizedFlags ();
131
159
160
+ #if SANITIZER_EMSCRIPTEN
161
+ if (common_flags ()->malloc_context_size <= 1 )
162
+ StackTrace::snapshot_stack = false ;
163
+ #endif // SANITIZER_EMSCRIPTEN
164
+
132
165
if (common_flags ()->help ) {
133
166
// TODO(samsonov): print all of the flags (ASan, LSan, common).
134
167
asan_parser.PrintFlagDescriptions ();
0 commit comments