refactor(platform): out-line ModuleParams setParent and destructor to save flash (#28321)

Both were defined inline in the header, so the List add/remove bodies
were duplicated into the constructor and destructor of every one of the
150+ ModuleParams-derived classes. Construction and destruction are cold
paths; a call is smaller at each site.

Two consumers reach ModuleParams without px4_platform on the link line
and now need the definitions explicitly: health_and_arming_checks (the
functional-ModeManagement test only pulls it in transitively through
modules__commander, after px4_platform) and the failsafe_web emscripten
build, which compiles module_params.cpp directly.

The smaller constructors let the compiler fully inline the defaulted
FlightTaskDescend constructor on the ITCM boards, so its entry is
dropped from their linker scripts.

Saves 3968 B of .text on px4_fmu-v6x_default.


Assisted-by: Claude:claude-fable-5

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
Co-authored-by: Balduin <balduin@auterion.com>
This commit is contained in:
Jacob Dahl
2026-08-21 10:34:09 -06:00
committed by GitHub
co-authored by Balduin
parent 047f91167d
commit 6c53460f2e
8 changed files with 53 additions and 16 deletions
@@ -625,7 +625,6 @@
*(.text._ZN36do_not_explicitly_use_this_namespace5ParamIfLN3px46paramsE919EEC1Ev) /* itcm-check-ignore */
*(.text._ZN22MavlinkStreamHeartbeat8get_sizeEv)
*(.text._ZN6matrix6MatrixIfLj3ELj1EEdVEf)
*(.text._ZN17FlightTaskDescendC1Ev)
*(.text._ZN26MavlinkStreamCameraTrigger8get_sizeEv)
*(.text.iob_navail)
*(.text._ZN12FailsafeBase25removeNonActivatedActionsEv)
@@ -625,7 +625,6 @@
*(.text._ZN36do_not_explicitly_use_this_namespace5ParamIfLN3px46paramsE919EEC1Ev) /* itcm-check-ignore */
*(.text._ZN22MavlinkStreamHeartbeat8get_sizeEv)
*(.text._ZN6matrix6MatrixIfLj3ELj1EEdVEf)
*(.text._ZN17FlightTaskDescendC1Ev)
*(.text._ZN26MavlinkStreamCameraTrigger8get_sizeEv)
*(.text.iob_navail)
*(.text._ZN12FailsafeBase25removeNonActivatedActionsEv)
@@ -639,7 +639,6 @@
*(.text._ZN36do_not_explicitly_use_this_namespace5ParamIfLN3px46paramsE919EEC1Ev) /* itcm-check-ignore */
*(.text._ZN22MavlinkStreamHeartbeat8get_sizeEv)
*(.text._ZN6matrix6MatrixIfLj3ELj1EEdVEf)
*(.text._ZN17FlightTaskDescendC1Ev)
*(.text._ZN26MavlinkStreamCameraTrigger8get_sizeEv)
*(.text.iob_navail)
*(.text._ZN12FailsafeBase25removeNonActivatedActionsEv)
+1
View File
@@ -47,6 +47,7 @@ add_library(px4_platform STATIC
i2c.cpp
i2c_spi_buses.cpp
module.cpp
module_params.cpp
px4_getopt.c
px4_cli.cpp
shutdown.cpp
@@ -56,19 +56,9 @@ public:
* @brief Sets the parent module. This is typically not required,
* only in cases where the parent cannot be set via constructor.
*/
void setParent(ModuleParams *parent)
{
if (parent) {
parent->_children.add(this);
}
void setParent(ModuleParams *parent);
_parent = parent;
}
virtual ~ModuleParams()
{
if (_parent) { _parent->_children.remove(this); }
}
virtual ~ModuleParams();
// Disallow copy construction and move assignment.
ModuleParams(const ModuleParams &) = delete;
+48
View File
@@ -0,0 +1,48 @@
/****************************************************************************
*
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_platform_common/module_params.h>
void ModuleParams::setParent(ModuleParams *parent)
{
if (parent) {
parent->_children.add(this);
}
_parent = parent;
}
ModuleParams::~ModuleParams()
{
if (_parent) { _parent->_children.remove(this); }
}
@@ -83,7 +83,7 @@ px4_add_library(health_and_arming_checks ${health_and_arming_checks_srcs})
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/esc_check_params.yaml)
add_dependencies(health_and_arming_checks mode_util)
target_link_libraries(health_and_arming_checks PRIVATE geo hysteresis)
target_link_libraries(health_and_arming_checks PRIVATE geo hysteresis px4_platform)
px4_add_functional_gtest(SRC HealthAndArmingChecksTest.cpp
LINKLIBS health_and_arming_checks mode_util
@@ -53,6 +53,7 @@ add_executable(failsafe_test EXCLUDE_FROM_ALL
emscripten.cpp
failsafe.cpp
framework.cpp
${PX4_SOURCE_DIR}/platforms/common/module_params.cpp
)
set_property(TARGET failsafe_test PROPERTY UNITY_BUILD ON) # avoids some method calls to e.g. param_name or param_type
set_property(TARGET failsafe_test PROPERTY LINK_DEPENDS ${html_output_file})