Skip to content

LTO optimises out Hardware_init pointers #926

@ser-plu

Description

@ser-plu

Building a project for STM32G431 with arm-none-eabi 11.3.

When enabling LTO optimisation, the pointers to hardware_init functions get optimised out: the .hardware_init section is empty (__hardware_init_start equals __hardware_init_end).

To preserve the pointers, __attribute__((used)) is required for the pointers.

This file should be corrected: https://github.com/modm-io/modm/blob/develop/src/modm/platform/core/cortex/hardware_init.hpp
like this:

#define MODM_HARDWARE_INIT(function) \
	modm_section(".hardware_init") \
	void* const MODM_CONCAT(__modm_hardware_init_ptr_, function) __attribute__((used) = (void*)&function

/// Call `function` during boot process with a unique name.
/// @hideinitializer
#define MODM_HARDWARE_INIT_NAME(name, function) \
	modm_section(".hardware_init") \
	void* const MODM_CONCAT(__modm_hardware_init_ptr_, name) __attribute__((used) = (void*)&function

/// Call `function` during boot process in a global order.
/// @hideinitializer
#define MODM_HARDWARE_INIT_ORDER(function, order) \
	modm_section(".hardware_init.order_" MODM_STRINGIFY(order)) \
	void* const MODM_CONCAT(__modm_hardware_init_ptr_, function) __attribute__((used) = (void*)&function

/// Call `function` during boot process in a global order with a unique name.
/// @hideinitializer
#define MODM_HARDWARE_INIT_NAME_ORDER(name, function, order) \
	modm_section(".hardware_init.order_" MODM_STRINGIFY(order)) \
	void* const MODM_CONCAT(__modm_hardware_init_ptr_, name) __attribute__((used) = (void*)&function

Or, probably, modm_used macro should be defined beforehand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions