File tree Expand file tree Collapse file tree 6 files changed +50
-5
lines changed Expand file tree Collapse file tree 6 files changed +50
-5
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,18 @@ if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT)
344
344
zephyr_compile_options ($< $< COMPILE_LANGUAGE:C> :$< TARGET_PROPERTY:compiler,no_printf_return_value> > )
345
345
endif ()
346
346
347
+ if (CONFIG_UBSAN )
348
+ zephyr_compile_options ($< $< COMPILE_LANGUAGE:C> :$< TARGET_PROPERTY:compiler,sanitizer_undefined> > )
349
+ zephyr_link_libraries ($< TARGET_PROPERTY:linker,sanitizer_undefined> )
350
+ if (CONFIG_UBSAN_LIBRARY )
351
+ zephyr_compile_options ($< $< COMPILE_LANGUAGE:C> :$< TARGET_PROPERTY:compiler,sanitizer_undefined_library> > )
352
+ zephyr_link_libraries ($< TARGET_PROPERTY:linker,sanitizer_undefined_library> )
353
+ elseif (CONFIG_UBSAN_TRAP )
354
+ zephyr_compile_options ($< $< COMPILE_LANGUAGE:C> :$< TARGET_PROPERTY:compiler,sanitizer_undefined_trap> > )
355
+ zephyr_link_libraries ($< TARGET_PROPERTY:linker,sanitizer_undefined_trap> )
356
+ endif ()
357
+ endif ()
358
+
347
359
# @Intent: Set compiler specific flag for tentative definitions, no-common
348
360
zephyr_compile_options ($< TARGET_PROPERTY:compiler,no_common> )
349
361
Original file line number Diff line number Diff line change @@ -328,6 +328,7 @@ config PRIVILEGED_STACK_SIZE
328
328
329
329
config KOBJECT_TEXT_AREA
330
330
int "Size of kobject text area"
331
+ default 1024 if UBSAN
331
332
default 512 if COVERAGE_GCOV
332
333
default 512 if NO_OPTIMIZATIONS
333
334
default 512 if STACK_CANARIES && RISCV
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ config PRIVILEGED_STACK_SIZE
126
126
default 4096
127
127
128
128
config KOBJECT_TEXT_AREA
129
+ default 1024 if UBSAN
129
130
default 512 if TEST
130
131
131
132
config WAIT_AT_RESET_VECTOR
Original file line number Diff line number Diff line change @@ -197,6 +197,10 @@ if(NOT CONFIG_NO_OPTIMIZATIONS)
197
197
set_compiler_property (PROPERTY security_fortify_run_time _FORTIFY_SOURCE=2 )
198
198
endif ()
199
199
200
+ check_set_compiler_property (PROPERTY sanitizer_undefined -fsanitize=undefined )
201
+ check_set_compiler_property (PROPERTY sanitizer_undefined_trap -fsanitize-undefined-trap-on-error )
202
+ check_set_compiler_property (PROPERTY sanitizer_undefined_library )
203
+
200
204
# gcc flag for a hosted (no-freestanding) application
201
205
check_set_compiler_property (APPEND PROPERTY hosted -fno-freestanding )
202
206
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ check_set_linker_property(TARGET linker PROPERTY orphan_error
24
24
25
25
check_set_linker_property (TARGET linker PROPERTY memusage "${LINKERFLAGPREFIX} ,--print-memory-usage" )
26
26
27
+ check_set_linker_property (TARGET linker PROPERTY sanitizer_undefined -fsanitize=undefined )
28
+ check_set_linker_property (TARGET linker PROPERTY sanitizer_undefined_trap -fsanitize-undefined-trap-on-error )
29
+ check_set_linker_property (TARGET linker PROPERTY sanitizer_undefined_library )
30
+
27
31
# -no-pie is not supported until binutils 2.37.
28
32
# If -no-pie is passed to old binutils <= 2.36, it is parsed
29
33
# as separate arguments -n and -o, which results in output file
Original file line number Diff line number Diff line change @@ -67,12 +67,35 @@ config ASAN_NOP_DLCLOSE
67
67
68
68
config UBSAN
69
69
bool "Build with undefined behavior sanitizer"
70
- depends on ARCH_POSIX
71
70
help
72
- Builds Zephyr with Undefined Behavior Sanitizer enabled.
73
- This is currently only supported by boards based on the posix
74
- architecture, and requires a recent-ish compiler with the
75
- ``-fsanitize=undefined`` command line option.
71
+ Builds Zephyr with Undefined Behavior Sanitizer enabled. This
72
+ requires a recent-ish compiler with the ``-fsanitize=undefined``
73
+ command line option.
74
+
75
+ choice UBSAN_MODE
76
+ prompt "Undefined behavior sanitizer mode"
77
+ depends on UBSAN
78
+ default UBSAN_LIBRARY
79
+
80
+ config UBSAN_LIBRARY
81
+ bool "Call ubsan routines"
82
+ depends on ARCH_POSIX || PICOLIBC
83
+ help
84
+ Call ubsan library routines when undefined behavior is detected
85
+ at runtime. This provides information about the faulting
86
+ condition along with the source filename, line number, types and
87
+ values involved. This is currently only supported by boards
88
+ based on the posix architecture or when building with picolibc.
89
+
90
+ config UBSAN_TRAP
91
+ bool "Call __builtin_trap"
92
+ help
93
+ When undefined behavior is detected, invoke __builtin_trap to
94
+ cause an exception to be raised. This can be used on any target,
95
+ but the lack of information makes figuring out the triggering
96
+ code difficult.
97
+
98
+ endchoice
76
99
77
100
config MSAN
78
101
bool "Build with memory sanitizer"
You can’t perform that action at this time.
0 commit comments