gcc -flto=auto causes mh_sha256/mh_sha256_test to fail #165
Labels
No labels
announcement
bug
duplicate
enhancement
help wanted
invalid
Next release
question
sighting
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-intel/isa-l_crypto#165
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Setting
-flto=autowhen compiling with gcc 15 causesmh_sha256/mh_sha256_testto fail:test-suite.log
Steps to reproduce:
5fd4cdae15)./autogen.shCFLAGS="-flto=auto -O2 -g" ./configuremake checkoutput
lscpu
Thanks for reporting this. I can reproduce it also with gcc 13. Looks like the issue comes from mh_sha256_ref.c
It seems to me that this might be a case of undefined behaviour. It can also be triggered by the following (without lto):
and even with lto, it can avoided by:
But this also prevents the error:
Which leads me to believe that gcc's inter-procedural analysis might detect some kind of aliasing issue or such, and removes or modifies these stores.
And it appears so, since using
seems to also prevent the issue.
Since the code base does not seem to be "aliasing aware", I think it would be best to add
-fno-strict-aliasingby default.I'm also attaching a single c source file that can be used to trigger this issue (at least on gcc 15.2.1 20251112): repro.c
Notice that depending on whether
sha256_single_for_mh_sha256_ref()is notstatic inlineand the-fPICis present, then the output is different in the case of gcc, and that different out matches the result with clang in all cases.In fact, the disassembly of (3) and (1) shows a stark difference:
The store of
1insha256_for_mh_sha256_ref()disappears.Adding "no-strict-aliasing" seems to be working for all scenarios I'm testing, so thanks for this. I'm pushing a commit with this soon, so I would like to get your name and email address to add you as a contributor, if you are OK with it.
It's fine, feel free to just go ahead. But if you want, name is on my github profile, email is my username at protonmail.com.
Given this only happens when -flto=auto is passed, I decided to document the workaround of adding -fno-strict-aliasing:
github.com/intel/isa-l_crypto@6351fa0914The code base, at least the tests, is not strict aliasing compatible. I see no reason not to enable it globally. Any reason not to do it?
The reason is that we need to check if this affects performance in the library somehow. Since this has minor impact and there is a workaround documented, we will release the code as is and we will look further into it after the release.