Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref. #926. Fixes for LTO build. #928

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/modm/platform/clock/stm32/rcc.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ modm_weak void SystemCoreClockUpdate() { /* Nothing to update */ }

namespace modm::platform
{
constinit uint16_t modm_fastdata delay_fcpu_MHz(computeDelayMhz(Rcc::BootFrequency));
constinit uint16_t modm_fastdata delay_ns_per_loop(computeDelayNsPerLoop(Rcc::BootFrequency));
constinit uint16_t modm_fastdata modm_used delay_fcpu_MHz(computeDelayMhz(Rcc::BootFrequency));
constinit uint16_t modm_fastdata modm_used delay_ns_per_loop(computeDelayNsPerLoop(Rcc::BootFrequency));

// ----------------------------------------------------------------------------
%% if target.family == "f0"
Expand Down
7 changes: 4 additions & 3 deletions src/modm/platform/core/cortex/vectors.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef void (* const FunctionPointer)(void);
extern uint32_t __main_stack_top[];

// Define the vector table
modm_section(".vector_rom")
modm_section(".vector_rom") modm_used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably also necessary for vectorsRam just below.

Basically everything that's implicitly linked needs to be marked as used? Seems like a lot of work…

Copy link
Member

@salkinium salkinium Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you perhaps extract the symbols of the resulting ELF files with/without LTO and diff them? That would perhaps give you a more definitive list of lost symbols.
It's scons symbols but we seem to not have it for CMake.
Otherwise try: arm-none-eabi-nm -S -C --size-sort -td file.elf

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much difference any more. vectorsRam indeed is required to be used, I just use the ROM-mapped vector table in my project.

One more symbol missing is modm_abandon, but I think it is just optimised out as an empty function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, Undefined_Handler also requires the attribute. But I am not 100% sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a look myself tomorrow to check if we can enable LTO by default at least for the release build.

FunctionPointer vectorsRom[] =
{
(FunctionPointer)__main_stack_top, // -16: stack pointer
Expand All @@ -50,7 +50,7 @@ FunctionPointer vectorsRom[] =
};
%% if vector_table_location == "ram"
// reserve space for the remapped vector table in RAM
modm_section(".vector_ram")
modm_section(".vector_ram") modm_used
FunctionPointer vectorsRam[sizeof(vectorsRom) / sizeof(FunctionPointer)];
%% endif

Expand All @@ -65,7 +65,8 @@ FunctionPointer vectorsRam[sizeof(vectorsRom) / sizeof(FunctionPointer)];
#include <modm/architecture/interface/assert.h>
%% endif

void Undefined_Handler(void)
modm_used void
Undefined_Handler(void)
{
%% if with_assert
const int32_t irqn = ((int32_t)__get_IPSR()) - 16;
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/heap/cortex/heap_newlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void __modm_initialize_memory(void)
* Note: This implementation is not thread safe (despite taking a
* _reent structure as a parameter).
*/
void *
modm_used void *
_sbrk_r(struct _reent *, ptrdiff_t size)
{
const uint8_t *const heap = heap_top;
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/heap/cortex/no_heap.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void __modm_initialize_memory(void)
}

// ----------------------------------------------------------------------------
modm_weak modm_section("{{ no_heap_section }}")
modm_weak modm_used modm_section("{{ no_heap_section }}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that always trigger the warning of the heap module not being included even if heap is not used in the application code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When heap is used, no_heap.cpp is excluded from build, isn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but if heap is not used, then this weak _sbrk_r acts as a "canary function" that the linker tries to link if someone tries to use malloc (which internally calls _sbrk_r via Newlib.
This function is normally garbage collected by the linker because nobody calls it, but is then DISCARDed in the linkerscript, thus the linker will fail with an error message.

void* _sbrk_r(struct _reent *r, ptrdiff_t size)
{
(void) r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-gcc-ar)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-gcc-nm)

SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH ":")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_FINISH ":")

project({{ project_name }} CXX C)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down