From b47ecfbbac0e62b7a97fce6e42ff0e1ccbd4a8c8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Jun 2024 16:28:12 +1000 Subject: [PATCH] waf: added --enable-new-checking option this allows CI to check for violations of new, calling without NEW_NOTHROW --- Tools/ardupilotwaf/boards.py | 30 +++++++++++++++++++++++------- wscript | 5 +++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index c32de12e3f995..5f5ce5434b121 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -4,6 +4,7 @@ import re import sys, os import fnmatch +import platform import waflib from waflib import Utils @@ -45,8 +46,8 @@ def configure(self, cfg): cfg.load('toolchain') cfg.load('cxx_checks') - # check elf symbols by default - cfg.env.CHECK_SYMBOLS = True + # don't check elf symbols by default + cfg.env.CHECK_SYMBOLS = False env = waflib.ConfigSet.ConfigSet() def srcpath(path): @@ -751,6 +752,11 @@ def configure_env(self, cfg, env): 'SITL', ] + # wrap malloc to ensure memory is zeroed + # don't do this on MacOS as ld doesn't support --wrap + if platform.system() != 'Darwin': + env.LINKFLAGS += ['-Wl,--wrap,malloc'] + if cfg.options.enable_sfml: if not cfg.check_SFML(env): cfg.fatal("Failed to find SFML libraries") @@ -794,8 +800,6 @@ def configure_env(self, cfg, env): if Utils.unversioned_sys_platform() == 'cygwin': env.CXXFLAGS += ['-DCYGWIN_BUILD'] - # can't do symbol checking on cygwin due to exception usage in system libraries - env.CHECK_SYMBOLS = False if 'clang++' in cfg.env.COMPILER_CXX: print("Disabling SLP for clang++") @@ -1007,6 +1011,8 @@ def expand_path(p): env.CXXFLAGS.remove('-Werror=undef') env.CXXFLAGS.remove('-Werror=shadow') + # wrap malloc to ensure memory is zeroed + env.LINKFLAGS += ['-Wl,--wrap,malloc'] env.INCLUDES += [ cfg.srcnode.find_dir('libraries/AP_HAL_ESP32/boards').abspath(), @@ -1260,6 +1266,16 @@ def configure_env(self, cfg, env): cfg.msg("Checking for intelhex module:", 'disabled', color='YELLOW') env.HAVE_INTEL_HEX = False + if cfg.options.enable_new_checking: + env.CHECK_SYMBOLS = True + else: + # disable new checking on ChibiOS by default to save flash + # we enable it in a CI test to catch incorrect usage + env.CXXFLAGS += [ + "-DNEW_NOTHROW=new", + "-fcheck-new", # rely on -fcheck-new ensuring nullptr checks + ] + def build(self, bld): super(chibios, self).build(bld) bld.ap_version_append_str('CHIBIOS_GIT_VERSION', bld.git_submodule_head_hash('ChibiOS', short=True)) @@ -1289,9 +1305,6 @@ def configure_env(self, cfg, env): self.with_can = True super(linux, self).configure_env(cfg, env) - # can't do symbol checking on Linux due to exception usage in libc++ - env.CHECK_SYMBOLS = False - env.BOARD_CLASS = "LINUX" env.DEFINES.update( @@ -1319,6 +1332,9 @@ def configure_env(self, cfg, env): 'AP_HAL_Linux', ] + # wrap malloc to ensure memory is zeroed + env.LINKFLAGS += ['-Wl,--wrap,malloc'] + if cfg.options.force_32bit: env.DEFINES.update( HAL_FORCE_32BIT = 1, diff --git a/wscript b/wscript index 0517655459219..a6a18a3954102 100644 --- a/wscript +++ b/wscript @@ -441,6 +441,11 @@ configuration in order to save typing. type='int', default=0, help='zero time on boot in microseconds') + + g.add_option('--enable-new-checking', + action='store_true', + default=False, + help='enables checking of new to ensure NEW_NOTHROW is used') def _collect_autoconfig_files(cfg): for m in sys.modules.values():