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

RFC: linker placement attribute #44

Closed
wants to merge 2 commits into from

Conversation

farcaller
Copy link

No description provided.

@mcpherrinm
Copy link

Your RFC seems to show:

#[link_placement=0xdeadbeef]
pub static mut UART0: UART;

Which differs from your proposed implementation, which is:

#[unsafe_override_address]
static t: T = 123;

I'm unclear how that version is supposed to work -- is this creating a "T" at location 123? If so, why isn't it static t: &'static T = 123;? If not, the syntax is not what I'd expect at all - T = 123; makes me think T must be a pointer type. But then how is that different from just having a pointer to that explicit location without your additions? So I must conclude this is putting a "T" at location 123, which the syntax seems very misleading for. The RFC seems much better in that respect, putting the address in an attribute.

If nothing else, the RFC should be the same as any proposed implementation.

@farcaller
Copy link
Author

I've updated the actual implementation as per suggestion of eddyb on IRC. The original RFC proposal is a bit more tricky to maintain as it also requires modification to parser, I would rather settle with #[unsafe_override_address] static t: &'static T = 123 which is similar to having static t: *mut T = 123 as *mut T without the burden of unsafety everywhere where t is used.

My current code is using externs and expects linker script to provide the actual placement address, so #[unsafe_override_address] static t: T = 123 is closer to that. Funnily enough, implementing this patch makes my binary bigger for some reason (still going through diffs of ir), but the code gets a bit more readable as well.

I will update the RFC to match my current implementation.

@liigo
Copy link
Contributor

liigo commented Apr 23, 2014

@farcaller Why not update your implementation to match the RFC?
I like #[link_placement=0xdeadbeef] ( or #[unsafe_override_address("0xdeadbeef")] ).

@farcaller
Copy link
Author

I've updated RFC with two alternative options.

@alexcrichton
Copy link
Member

Thanks for the RFC! This is something that can definitely be done today, as you discovered with linker scripts or casting integers to pointers.

For now, this is something we'd like to postpone until later, although we may perhaps consider this in the future when taking a close look at how Rust fits into the embedded systems space.

Closing.

withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
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.

4 participants