Skip to content

Commit

Permalink
Add sanitizer build options for host
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Jun 26, 2024
1 parent 8d1a9db commit dc1c84f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
37 changes: 33 additions & 4 deletions Sming/Arch/Host/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,26 @@ To find out what options are in force, use ``make list-config``.
Configuration
-------------

.. note::

The following settings are for debugging purposes and are not 'sticky'.
Where used, they should generally be defined globally using ``export``.


.. envvar:: CLI_TARGET_OPTIONS

Use this to add any custom options to the emulator command line. e.g.:

make run CLI_TARGET_OPTIONS=--help
make run CLI_TARGET_OPTIONS="--debug=0 --cpulimit=2"

Note: These settings are not 'sticky'


.. envvar:: CLANG_BUILD

0: Use GCC (default)
1: Use standard ``clang``
N: Use specific installed version, ``clang-N``

Note: This setting is not 'sticky'


.. envvar:: BUILD64

Expand All @@ -79,6 +81,33 @@ Configuration
On MacOS builds are 64-bit only. Default for other systems is 32-bit.


.. envvar:: ENABLE_SANITIZERS

default: 0 (off)

Enable this option to build with lots of runtime checking.

This provides some of the capabilities of valgrind but by instrumenting
the code when it is compiled, rather than patching at runtime.

It also links in some additional runtime support libraries.

Run a full rebuild after changing this setting (or :envvar:`SANITIZERS`)::

make clean components-clean
make

.. note::

If using :envvar:`CLANG_BUILD` then all runtime libraries should already be available.
For GCC you will also need to install ``libasan`` and ``libubsan``.


.. envvar:: SANITIZERS

Selects which sanitizers are used. See :envvar:`ENABLE_SANITIZERS`.


Components
----------

Expand Down
4 changes: 4 additions & 0 deletions Sming/Arch/Host/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ ifneq ($(BUILD64),1)
LDFLAGS += -m32
endif

ifeq ($(ENABLE_SANITIZERS),1)
LDFLAGS += $(foreach s,$(SANITIZERS),-fsanitize=$s)
endif

# Executable
TARGET_OUT_0 := $(FW_BASE)/$(APP_NAME)$(TOOL_EXT)

Expand Down
16 changes: 16 additions & 0 deletions Sming/Arch/Host/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ CPPFLAGS += \
-D_FILE_OFFSET_BITS=64 \
-D_TIME_BITS=64

# Sanitizers
DEBUG_VARS += ENABLE_SANITIZERS SANITIZERS
ENABLE_SANITIZERS ?= 0
SANITIZERS ?= \
address \
pointer-compare \
pointer-subtract \
leak \
undefined
ifeq ($(ENABLE_SANITIZERS),1)
CPPFLAGS += \
-fstack-protector-all \
-fsanitize-address-use-after-scope \
$(foreach s,$(SANITIZERS),-fsanitize=$s)
endif

# => Tools
MEMANALYZER = size

Expand Down
6 changes: 5 additions & 1 deletion Sming/Wiring/FakePgmSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
void* memcpy_aligned(void* dst, const void* src, unsigned len)
{
assert(IS_ALIGNED(dst) && IS_ALIGNED(src));
memcpy(dst, src, ALIGNUP4(len));
#ifndef ARCH_HOST
// Address sanitisers get tripped if we do this in Host builds
len = ALIGNUP4(len);
#endif
memcpy(dst, src, len);
return dst;
}

Expand Down

0 comments on commit dc1c84f

Please sign in to comment.