-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
function pointer address space handling (for AVR) is wrong #106367
Comments
Ouch, I see - is it something that would be fixable by a person with, uhm, moderate knowledge on rustc (such as me) or rather you'd say it's something pretty big? In any case, I can surely offer my help in testing out patches on AVR simulators and actual hardware. |
I'm not entirely sure -- I have worked a bunch with |
It's going to be moderately annoying to keep rebasing, but nothing complex. Afaict there should be no issues like performance or accidental regressions/bugs coming out of this. As an MVP you could change https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/enum.Primitive.html#variant.Pointer to have a |
That would however also affect all other targets, and e.g. I think the |
Hmm... I was thinking we'd make this decision in the backend, but you're right, the |
It's all memory, so that would be inappropriate (at least here) - the usual split is "data" vs "code". However, I agree with @RalfJung - we already have a type for it, even: rust/compiler/rustc_abi/src/lib.rs Lines 1188 to 1202 in deba5dd
(though I think that can be changed from |
I'm working on this. It's natural to add Something that keeps coming up while doing this is code that looks "obviously wrong" because it assumes all pointers are the same size as
Technically LLVM allows up to 23 bits (why 23?) for the address space. We need at least |
abi: add AddressSpace field to Primitive::Pointer ...and remove it from `PointeeInfo`, which isn't meant for this. There are still various places (marked with FIXMEs) that assume all pointers have the same size and alignment. Fixing this requires parsing non-default address spaces in the data layout string (and various other changes), which will be done in a followup. (That is, if it's actually worth it to support multiple different pointer sizes. There is a lot of code that would be affected by that.) Fixes rust-lang#106367 r? `@oli-obk` cc `@Patryk27`
@eddyb points out that the handling of address space for function pointers (introduced by #73270) is fundamentally wrong:
PointeeInfo
can be used for optimization hints only and also only becomes relevant way too late during compilation. To properly account for function pointers having a different address space, they need to be added in thePointer
variant of thePrimitive
ABI type. That is the only way to fix types likeResult<&i32, fn()>
, which are currently going horribly wrong for Harvard architectures because the enum layout algorithm will think that&i32
andfn()
are exactly the same fundamental type, and put them into one and the same field (resulting LLVM layout:{ i64, ptr }
).Not sure whom to ping here, so I will pick some people that seem to be active in an around AVR: @dylanmckay @Patryk27.
Also Cc @rust-lang/compiler since this is related to some pretty fundamental compiler infrastructure
The text was updated successfully, but these errors were encountered: