Skip to content
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

AddressSanitizer support #3560

Merged
merged 26 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
11173a0
Add new configuration option `--enable-address-sanitizer` for Address…
Svetlitski Sep 11, 2024
1ae4edd
Implement AddressSanitizer integration
Svetlitski Feb 6, 2025
91cde3d
Add tests for AddressSanitizer
Svetlitski Feb 6, 2025
9629d91
AddressSanitizer optimization: prefer using `mov` over `lea` when pos…
Svetlitski Feb 7, 2025
7638b04
AddressSanitizer optimization: save an instruction for large memory a…
Svetlitski Feb 7, 2025
8f7270e
AddressSanitizer optimization: `inc` r10 when the memory access size …
Svetlitski Feb 7, 2025
e31a12c
AddressSanitizer: fix some subtle bugs and optimize by spilling only …
Svetlitski Feb 7, 2025
f9bf0f9
AddressSanitizer: fix bug where address provided to ASAN report stubs…
Svetlitski Feb 7, 2025
5a0ccb2
AddressSanitizer: reformatting
Svetlitski Feb 10, 2025
a25192b
AddressSanitizer: add additional comments on the non-standard calling…
Svetlitski Feb 10, 2025
e568438
AddressSanitizer: use a labelled argument for [address] in [emit_sani…
Svetlitski Feb 10, 2025
cd5ef11
AddressSanitizer: ensure SIMD operations with memory operands are san…
Svetlitski Feb 10, 2025
9b2a672
AddressSanitizer: sanitize `cldemote` and prefetches
Svetlitski Feb 10, 2025
66d4765
Add no-op `-fno-asan` flag for ARM backend
Svetlitski Feb 10, 2025
e89a1e1
Update help text for configure option `--enable-address-sanitizer`
Svetlitski Feb 12, 2025
e60c49c
AddressSanitizer: fix destroyed registers for `Icldemote` and `Iprefe…
Svetlitski Feb 12, 2025
bbc2d59
AddressSanitizer: add tests for `cldemote` and `prefetch`
Svetlitski Feb 12, 2025
0555a81
AddressSanitizer: make `dest` argument to `load` non-optional
Svetlitski Feb 12, 2025
1887e5d
AddressSanitizer: unify logic around eliding sanitization of record f…
Svetlitski Feb 12, 2025
a949214
AddressSanitizer: move command line flag from `Emit` to `Arch`
Svetlitski Feb 12, 2025
eff4915
AddressSanitizer: update comment on ASAN stub calling convention
Svetlitski Feb 12, 2025
4d6570f
AddressSanitizer: sanitize atomic memory accesses and add a test-case…
Svetlitski Feb 13, 2025
32aac6b
Use polymorphic equality in `Address_sanitizer.uses_register`
Svetlitski Feb 13, 2025
f95391a
AddressSanitizer: address remaining code review comments
Svetlitski Feb 13, 2025
1371b65
AddressSanitizer: put all C preprocessor directives in column 0
Svetlitski Feb 14, 2025
1c0100a
AddressSanitizer: fix build for runtime5
Svetlitski Feb 14, 2025
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
2 changes: 2 additions & 0 deletions Makefile.common-jst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ define dune_main_context
(OCAMLLIB ("$(CURDIR)/_build/runtime_stdlib_install/lib/ocaml_runtime_stdlib")))
(env (_
(flags (:standard -warn-error +A -alert -unsafe_multidomain))
; We never want to build the compiler itself with AddressSanitizer enabled.
gretay-js marked this conversation as resolved.
Show resolved Hide resolved
(ocamlopt_flags (:standard -fno-asan))
(env-vars ("OCAMLPARAM" "$(BUILD_OCAMLPARAM)"))))))
endef

Expand Down
1 change: 1 addition & 0 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ INSTRUMENTED_RUNTIME_LIBS=@instrumented_runtime_libs@
WITH_DEBUGGER=@with_debugger@
ASM_CFI_SUPPORTED=@asm_cfi_supported@
WITH_FRAME_POINTERS=@frame_pointers@
WITH_ADDRESS_SANITIZER=@address_sanitizer@
WITH_CPP_MANGLING=@cpp_mangling@
WITH_PROFINFO=@profinfo@
PROFINFO_WIDTH=@profinfo_width@
Expand Down
2 changes: 1 addition & 1 deletion Makefile.upstream
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ SAK_CFLAGS ?= $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS)
SAK_LINK ?= $(MKEXE_VIA_CC)

$(SAK): $(RUNTIME_DIR)/sak.$(O)
$(V_MKEXE)$(call SAK_LINK,$@,$^)
$(V_MKEXE)$(call SAK_LINK,$@,$^ $(if $(filter true,$(WITH_ADDRESS_SANITIZER)),-fsanitize=address -fsanitize-recover=address))

$(RUNTIME_DIR)/sak.$(O): $(RUNTIME_DIR)/sak.c $(RUNTIME_DIR)/caml/misc.h $(RUNTIME_DIR)/caml/config.h
$(V_CC)$(SAK_CC) -c $(SAK_CFLAGS) $(OUTPUTOBJ)$@ $<
Expand Down
8 changes: 7 additions & 1 deletion backend/amd64/arch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ let trap_notes = ref true
(* Emit extension symbols for CPUID startup check *)
let arch_check_symbols = ref true

let is_asan_enabled = ref Config.with_address_sanitizer

(* Machine-specific command-line options *)

let command_line_options =
Expand All @@ -104,7 +106,11 @@ let command_line_options =
"-ftrap-notes", Arg.Set trap_notes,
" Emit .note.ocaml_eh section with trap handling information (default)";
"-fno-trap-notes", Arg.Clear trap_notes,
" Do not emit .note.ocaml_eh section with trap handling information"
" Do not emit .note.ocaml_eh section with trap handling information";
"-fno-asan",
Arg.Clear is_asan_enabled,
" Disable AddressSanitizer. This is only meaningful if the compiler was \
built with AddressSanitizer support enabled."
] @ Extension.args

(* Specific operations for the AMD64 processor *)
Expand Down
1 change: 1 addition & 0 deletions backend/amd64/arch.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ end

val trap_notes : bool ref
val arch_check_symbols : bool ref
val is_asan_enabled : bool ref
val command_line_options : (string * Arg.spec * string) list

(* Specific operations for the AMD64 processor *)
Expand Down
Loading