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 1 commit
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
3 changes: 1 addition & 2 deletions src/modm/platform/heap/cortex/heap_newlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ void __modm_initialize_memory(void)
* Note: This implementation is not thread safe (despite taking a
* _reent structure as a parameter).
*/
void *
_sbrk_r(struct _reent *, ptrdiff_t size)
modm_used void * _sbrk_r(struct _reent *, ptrdiff_t size)
ser-plu marked this conversation as resolved.
Show resolved Hide resolved
{
const uint8_t *const heap = heap_top;
heap_top += size;
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