-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[AVR] Changing a struct size changes program behaviour #107293
Comments
What happens if you use the -Zrandomize-layout rustc flag with and without the extra u8? |
Indeed, it makes the problem go away (the two outputs match, and it's the (I haven't tried yet if it also fixes my original real program) |
By default, the layout of types without a It seems like there is code that relies on the layout of repr Rust types, which is unsound. This causes your field change to have an effect and breaking the code in weird ways (probably due to undefined behavior). |
Hmm interesting, but I am only changing a struct here that is internal to my project, i.e. a |
Hmm. I tried adding
|
Based on this explanation, I would expect that it is Can you explain in more detail how this all hangs together? |
Also, why does |
No idea 😄 I only wanted to say that I don't trust that crate regarding safety |
As of Cryptjar/avr-progmem-rs@31382d5 the UB in question has been fixed afaict (there may be more or I may be wrong), however this is an unreleased version. Yet, the current fix (to be updated later) is equivalent to enabling the feature |
Indeed, turning on the |
Nice. Given that this appears to have arisen through UB and through the resolution of the UB has been dissolved, I am going to close this. Rust may have less UB in typical programs but when it does appear it gets very exciting. The other issue that was stopping you from exploring things further will hopefully be fixed by #107592 and otherwise is a duplicate. If for some reason circumstances change then feel free to reopen this stuff. |
I don't have a minimal demonstrator for this: it's been difficult to even cut it down to this size. The program at this repo shows that its SPI output changes when a single new
u8
(otherwise unused) is added to astruct
.Note that the version without the extra
u8
is the one that produces the output I expect.The text was updated successfully, but these errors were encountered: