[compiler-rt] [ASan][Windows] Honor asan config flags on windows when set through the user function (PR #122990)
David Justo via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 15:58:47 PST 2025
================
@@ -390,17 +390,57 @@ void PrintAddressSpaceLayout() {
kHighShadowBeg > kMidMemEnd);
}
+// Apply most options specified either through the ASAN_OPTIONS
+// environment variable, or through the `__asan_default_options` user function.
+//
+// This function may be called multiple times, once per weak reference callback
+// on Windows, so it needs to be idempotent.
+//
+// Context:
+// For maximum compatibility on Windows, it is necessary for ASan options to be
+// configured/registered/applied inside this method (instead of in
+// ASanInitInternal, for example). That's because, on Windows, the user-provided
+// definition for `__asan_default_opts` may not be bound when `ASanInitInternal`
+// is invoked (it is bound later).
+//
+// To work around the late binding on windows, `ApplyOptions` will be called,
+// again, after binding to the user-provided `__asan_default_opts` function.
+// Therefore, any flags not configured here are not guaranteed to be
+// configurable through `__asan_default_opts` on Windows.
+//
+//
+// For more details on this issue, see:
+// https://github.com/llvm/llvm-project/issues/117925
+void ApplyFlags() {
+ SetCanPoisonMemory(flags()->poison_heap);
+ SetMallocContextSize(common_flags()->malloc_context_size);
+
+ __sanitizer_set_report_path(common_flags()->log_path);
+
+ __asan_option_detect_stack_use_after_return =
+ flags()->detect_stack_use_after_return;
+
+ AllocatorOptions allocator_options;
+ allocator_options.SetFrom(flags(), common_flags());
+ ApplyAllocatorOptions(allocator_options);
+}
+
static bool AsanInitInternal() {
if (LIKELY(AsanInited()))
return true;
SanitizerToolName = "AddressSanitizer";
CacheBinaryName();
- // Initialize flags. This must be done early, because most of the
- // initialization steps look at flags().
+ // Initialize flags and register weak function callbacks for windows.
+ // This must be done early, because most of the initialization steps look at
+ // flags().
InitializeFlags();
+ // NOTE: The sleep before/after init` flags will not work on Windows when set
----------------
davidmrdavid wrote:
Removed: https://github.com/llvm/llvm-project/pull/122990/commits/ba740aa73d052e7e68ccdea1d9531bc71eaad53c
https://github.com/llvm/llvm-project/pull/122990
More information about the llvm-commits
mailing list