Open karel-m opened 7 years ago
Update: with -DLTC_NO_FAST
no UBSAN issues in release/1.18.0
This is relevant: http://dbp-consulting.com/tutorials/StrictAliasing.html
It explains the problem and lists possible solutions.
Well I doubt there's a fix for this feature which deliberately exists to (ab)use a potential CPU/architecture feature where unaligned accesses are handled as if the access was aligned to get some speed. The easiest fix is defining LTC_NO_FAST
if you've a problem with this behavior.
Or do you think any of the solutions on that page could be implemented here to solve this aliasing problem @andreyv @karel-m ?
If not I think we can close this.
Well, if the intent is to explicitly load unaligned integers, then two possible choices are to either leave it like it is now (in practice this may "work", I see there is a may_alias
attribute), or change the macros to do a union or memcpy
operation as described in the linked article.
As the target of this optimization is speed, the memcpy
approach obviously won't work.
IIUC the union approach also involves copying the data and thereby is also useless.
I'd say we leave it as it is now. If someone has a problem with the aliasing, he should simply define LTC_NO_FAST
.
is that documented somewhere ? maybe a paragraph above the commented out option in tomcrypt-config.h should warn about the UB invoked by it.
UBSAN (UndefinedBehaviorSanitizer) reports the following issues on current
release/1.18.0
(all related toLTC_FAST_TYPE
):This is just FYI, I have no suggestion what to do (I am even in doubts whether we can or should do anything).
Can be reproduced by: