AsanOptions.cpp (8288B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "mozilla/Attributes.h" 7 #include "mozilla/Types.h" 8 9 // When running with AddressSanitizer, we need to explicitly set some 10 // options specific to our codebase to prevent errors during runtime. 11 // To override these, set the ASAN_OPTIONS environment variable. 12 // 13 // Currently, these are: 14 // 15 // allow_user_segv_handler=1 - Tell ASan to allow our code to use its 16 // own SIGSEGV handlers. This is required by ASM.js internally. 17 // 18 // alloc_dealloc_mismatch=0 - Disable alloc-dealloc mismatch checking 19 // in ASan. This is required because we define our own new/delete 20 // operators that are backed by malloc/free. If one of them gets inlined 21 // while the other doesn't, ASan will report false positives. 22 // 23 // detect_leaks=0 - Disable LeakSanitizer. This is required because 24 // otherwise leak checking will be enabled for various building and 25 // testing executables where we don't care much about leaks. 26 // 27 // allocator_may_return_null=1 - Tell ASan to return NULL when an allocation 28 // fails instead of aborting the program. This allows us to handle failing 29 // allocations the same way we would handle them with a regular allocator and 30 // also uncovers potential bugs that might occur in these situations. 31 // 32 // max_malloc_fill_size - Tell ASan to initialize memory to a certain value 33 // when it is allocated. This option specifies the maximum allocation size 34 // for which ASan should still initialize the memory. The value we specify 35 // here is exactly 256MiB. 36 // 37 // max_free_fill_size - Similar to max_malloc_fill_size, tell ASan to 38 // overwrite memory with a certain value when it is freed. Again, the value 39 // here specifies the maximum allocation size, larger allocations will 40 // skipped. 41 // 42 // malloc_fill_byte / free_fill_byte - These values specify the byte values 43 // used to initialize/overwrite memory in conjunction with the previous 44 // options max_malloc_fill_size and max_free_fill_size. The values used here 45 // are 0xe4 and 0xe5 to match the kAllocPoison and kAllocJunk constants used 46 // by mozjemalloc. 47 // 48 // malloc_context_size - This value specifies how many stack frames are 49 // stored for each malloc and free call. Since Firefox can have lots of deep 50 // stacks with allocations, we limit the default size here further to save 51 // some memory. 52 // 53 // fast_unwind_on_check - Use the fast (frame-pointer-based) stack unwinder 54 // for internal CHECK failures. The slow unwinder doesn't work on Android. 55 // 56 // fast_unwind_on_fatal - Use the fast (frame-pointer-based) stack unwinder 57 // to print fatal error reports. The slow unwinder doesn't work on Android. 58 // 59 // intercept_tls_get_addr=0 - Work around 60 // https://github.com/google/sanitizers/issues/1322 (bug 1635327). 61 // 62 // !! Note: __asan_default_options is not used on Android! (bug 1576213) 63 // These should be updated in: 64 // mobile/android/geckoview/src/asan/resources/lib/*/wrap.sh 65 // 66 extern "C" MOZ_ASAN_IGNORE MOZ_EXPORT const char* __asan_default_options() { 67 return "allow_user_segv_handler=1:alloc_dealloc_mismatch=0:detect_leaks=0" 68 #ifdef MOZ_ASAN_REPORTER 69 ":malloc_context_size=20" 70 #endif 71 #ifdef __ANDROID__ 72 ":fast_unwind_on_check=1:fast_unwind_on_fatal=1" 73 #endif 74 ":max_free_fill_size=268435456:max_malloc_fill_size=268435456" 75 ":malloc_fill_byte=228:free_fill_byte=229" 76 ":handle_sigill=1:handle_abort=1:handle_sigtrap=1" 77 ":allocator_may_return_null=1" 78 ":intercept_tls_get_addr=0"; 79 } 80 81 // !!! Please do not add suppressions for new leaks in Gecko code, unless they 82 // are intentional !!! 83 extern "C" MOZ_EXPORT const char* __lsan_default_suppressions() { 84 return "# Add your suppressions below\n" 85 86 // LSan runs with a shallow stack depth and no debug symbols, so some 87 // small intentional leaks in system libraries show up with this. You 88 // do not want this enabled when running locally with a deep stack, as 89 // it can catch too much. 90 "leak:libc.so\n" 91 92 // nsComponentManagerImpl intentionally leaks factory entries, and 93 // probably some other stuff. 94 "leak:nsComponentManagerImpl\n" 95 96 // Bug 981220 - Pixman fails to free TLS memory. 97 "leak:pixman_implementation_lookup_composite\n" 98 99 // Bug 987918 - Font shutdown leaks when CLEANUP_MEMORY is not enabled. 100 "leak:libfontconfig.so\n" 101 "leak:libfreetype.so\n" 102 "leak:GI___strdup\n" 103 // The symbol is really __GI___strdup, but if you have the leading _, 104 // it doesn't suppress it. 105 106 // xdg_mime_init() is leaked by Gtk3 library 107 "leak:xdg_mime_init\n" 108 109 // Bug 1078015 - If the process terminates during a PR_Sleep, LSAN 110 // detects a leak 111 "leak:PR_Sleep\n" 112 113 // Bug 1363976 - Stylo holds some global data alive forever. 114 "leak:style::global_style_data\n" 115 "leak:style::sharing::SHARING_CACHE_KEY\n" 116 "leak:style::bloom::BLOOM_KEY\n" 117 118 // 119 // Many leaks only affect some test suites. The suite annotations are 120 // not checked. 121 // 122 123 // Bug 979928 - WebRTC leaks in different mochitest suites. 124 "leak:NR_reg_init\n" 125 // nr_reg_local_init should be redundant with NR_reg_init, but on 126 // Aurora we get fewer stack frames for some reason. 127 "leak:nr_reg_local_init\n" 128 "leak:r_log_register\n" 129 "leak:nr_reg_set\n" 130 131 // This is a one-time leak in mochitest-bc, so it is probably okay to 132 // ignore. 133 "leak:GlobalPrinters::InitializeGlobalPrinters\n" 134 "leak:nsPSPrinterList::GetPrinterList\n" 135 136 // Bug 1028456 - Various NSPR fd-related leaks in different mochitest 137 // suites. 138 "leak:_PR_Getfd\n" 139 140 // Bug 1028483 - The XML parser sometimes leaks an object. Mostly 141 // happens in toolkit/components/thumbnails. 142 "leak:processInternalEntity\n" 143 144 // Bug 1187421 - NSS does not always free the error stack in different 145 // mochitest suites. 146 "leak:nss_ClearErrorStack\n" 147 148 // Bug 1602689 - leak at mozilla::NotNull, RacyRegisteredThread, 149 // RegisteredThread::RegisteredThread, mozilla::detail::UniqueSelector 150 "leak:RegisteredThread::RegisteredThread\n" 151 152 // Bug 1967251 - leak at ralloc_size, ralloc_context, 153 // mesa_cache_db_open, mesa_cache_db_multipart_init_part_locked 154 "leak:mesa_cache_db_open\n" 155 156 // 157 // Leaks with system libraries in their stacks. These show up across a 158 // number of tests. Better symbols and disabling fast stackwalking may 159 // help diagnose these. 160 // 161 "leak:libcairo.so\n" 162 // https://github.com/OpenPrinting/cups/pull/317 163 "leak:libcups.so\n" 164 "leak:libdl.so\n" 165 "leak:libdricore.so\n" 166 "leak:libdricore9.2.1.so\n" 167 "leak:libGL.so\n" 168 "leak:libEGL_mesa.so\n" 169 "leak:libglib-2.0.so\n" 170 "leak:libglsl.so\n" 171 "leak:libp11-kit.so\n" 172 "leak:libpixman-1.so\n" 173 "leak:libpulse.so\n" 174 // lubpulsecommon 1.1 is Ubuntu 12.04 175 "leak:libpulsecommon-1.1.so\n" 176 // lubpulsecommon 1.1 is Ubuntu 16.04 177 "leak:libpulsecommon-8.0.so\n" 178 "leak:libresolv.so\n" 179 "leak:libstdc++.so\n" 180 "leak:libXrandr.so\n" 181 "leak:libX11.so\n" 182 "leak:pthread_setspecific_internal\n" 183 "leak:swrast_dri.so\n" 184 "leak:i965_drv_video.so\n" 185 "leak:i965_dri.so\n" 186 "leak:libdrm_intel.so\n" 187 188 "leak:js::frontend::BytecodeEmitter:\n" 189 "leak:js::frontend::GeneralParser\n" 190 "leak:js::frontend::Parse\n" 191 "leak:xpc::CIGSHelper\n" 192 "leak:mozJSModuleLoader\n" 193 "leak:mozilla::xpcom::ConstructJSMComponent\n" 194 "leak:XPCWrappedNativeJSOps\n" 195 196 // End of suppressions. 197 ; // Please keep this semicolon. 198 }