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

LTO build fixes #339

Merged
merged 2 commits into from
Oct 26, 2023
Merged

LTO build fixes #339

merged 2 commits into from
Oct 26, 2023

Conversation

Damian-Nordic
Copy link
Contributor

@Damian-Nordic Damian-Nordic commented Oct 16, 2023

[Zephyr] Fix sys_heap malloc build with LTO
[nrfconnect] Do not link libCHIPShell.a with --whole-archive

Copy link
Collaborator

@LuDuda LuDuda left a comment

Choose a reason for hiding this comment

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

This is awesome! Thank you 👍

I would like to merge the changes needed to enable LTO, but would like to either (ideally) have KConfig option to enable LTO for Matter, or alternatively not adding -flto flags now yet - those will be added for generic CONFIG_LTO soon.

@Damian-Nordic
Copy link
Contributor Author

@LuDuda The commit to enable LTO was added just for testing. I removed it, so the PR can be merged now.

Copy link
Collaborator

@LuDuda LuDuda left a comment

Choose a reason for hiding this comment

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

Awesome!

Fix the build of Matter samples with sys_heap malloc enabled.
The linker errors would occur because:
1. The realloc() function is not used outside the LTO-
   optimized code.
2. Thus, the LTO linker plugin would mark __wrap_realloc
   symbol as PREVAILING_DEF_IRONLY, which would enable
   the compiler to optimize away the function.
3. As a result, undefined references to realloc() could not
   be resolved by the linker.

Mark malloc/calloc/realloc/free as externally visible.

Signed-off-by: Damian Krolik <[email protected]>
libCHIPShell.a is already part of libCHIP.a but the former
had to be linked additionally with --whole-archive flag to
process the shell and init objects defined with SHELL_XXX
and SYS_INIT Zephyr macros and, in turn, register Matter
shell commands properly.

This symbol duplication between the two libraries causes
issues when building Matter with LTO, so replace the current
approach with explicitly pulling in one symbol from
MainLoopZephyr.cpp file.

Signed-off-by: Damian Krolik <[email protected]>
@Damian-Nordic Damian-Nordic merged commit e77603b into nrfconnect:master Oct 26, 2023
7 checks passed
@Damian-Nordic Damian-Nordic deleted the lto-fixes branch October 26, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants