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

[toolchain] Enable LLD, LTO and minsize by default #26354

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

pamaury
Copy link
Contributor

@pamaury pamaury commented Feb 18, 2025

Now that many targets depend on the DT, LTO has become a lot more important. Since we already compile critical piece of software with it (test_rom, mask_rom), it makes sense to enable it for everything.

NOTE: I don't know if this going to break stuff, our guardian CI will surely let us know.

@pamaury
Copy link
Contributor Author

pamaury commented Feb 18, 2025

Fixes #26352

@pamaury pamaury force-pushed the enable_lto_minsize_lld branch from 58a1d2c to c72b81b Compare February 19, 2025 17:02
@pamaury pamaury requested a review from a team as a code owner February 19, 2025 17:02
@moidx moidx removed the request for review from a team February 19, 2025 17:11
@jwnrt
Copy link
Contributor

jwnrt commented Feb 20, 2025

Thanks for figuring this out, it will be very helpful.

For posterity, those shift functions were removed because of concerns about the type punning in the union. We know it's "correct" because we know the representation on Ibex, but we weren't sure if it's UB and could allow that compiler to miscompile. Is that a correct summary @pamaury?

@pamaury pamaury force-pushed the enable_lto_minsize_lld branch from c192769 to 926c1e0 Compare February 20, 2025 14:21
@pamaury
Copy link
Contributor Author

pamaury commented Feb 20, 2025

Thanks for figuring this out, it will be very helpful.

For posterity, those shift functions were removed because of concerns about the type punning in the union. We know it's "correct" because we know the representation on Ibex, but we weren't sure if it's UB and could allow that compiler to miscompile. Is that a correct summary @pamaury?

I am not an expert on the C specification but my understanding is that type punning in C99 is a priori not undefined behaviour, although the standard is quite weak on that point. However, unless one knows what the actual representation of integers are, this is still UB. One could say that this is fixed by C23 that set the representation to two's complement but we are not compiling for C23. That being said, as you noted, we know that we are compiling for the Ibex so there is no ambiguity here about the representation.

@pamaury pamaury force-pushed the enable_lto_minsize_lld branch 3 times, most recently from 392d4cb to 80c2e16 Compare February 20, 2025 14:45
pamaury and others added 8 commits February 24, 2025 14:07
Now that many targets depend on the DT, LTO has become a lot more
important. Since we already compile critical piece of software
with it (test_rom, mask_rom), it makes sense to enable it for
everything.

Signed-off-by: Amaury Pouly <[email protected]>
Forcing the linker to keep all sections causes linking problem
with the math polyfill and is also just bad practice. We still
mark the entry point section as KEEP.

Signed-off-by: Amaury Pouly <[email protected]>
The way the code is written can cause the compiler, with certain
optimization settings, to call `__lshrdi3` instead of implementing
the shifts with 32-bit operations. This commit rewrites the code
so that all shifts on 64-bit values are by one so that any reasonable
compiler will refrain from calling `__lshrdi3`.

Signed-off-by: Amaury Pouly <[email protected]>
This partiall yreverts commit eb69eed,
restoring the implementation of the shifts plus a tiny tweak to avoid
a compiler warning.

Signed-off-by: Amaury Pouly <[email protected]>
Those functions are called from assembly and will be discarded otherwise.

Signed-off-by: Amaury Pouly <[email protected]>
Those can be optimized y the compiler in nontrivial ways in tests
where they are only read but not written to for example.

Signed-off-by: Amaury Pouly <[email protected]>
@pamaury pamaury force-pushed the enable_lto_minsize_lld branch from 27fb7f7 to f1b0f86 Compare February 24, 2025 14:13
@pamaury pamaury requested a review from rswarbrick as a code owner February 24, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants