Skip to content

Commit

Permalink
AddressSanitizer support (#3560)
Browse files Browse the repository at this point in the history
  • Loading branch information
Svetlitski authored Feb 14, 2025
1 parent 75d35ab commit 2518c11
Show file tree
Hide file tree
Showing 49 changed files with 1,580 additions and 114 deletions.
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.
(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

0 comments on commit 2518c11

Please sign in to comment.