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

pub const items have no linker symbol #21856

Closed
richo opened this issue Feb 2, 2015 · 5 comments · Fixed by #21881
Closed

pub const items have no linker symbol #21856

richo opened this issue Feb 2, 2015 · 5 comments · Fixed by #21881
Labels
A-FFI Area: Foreign function interface (FFI) A-linkage Area: linking into static, shared libraries and binaries A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@richo
Copy link
Contributor

richo commented Feb 2, 2015

#[no_mangle]
pub const THING: libc::c_int = 42;

Will not actually be exported in the resulting object. There are two obvious fixes, the first being to expand on my pub-not-exported lint to warn you that this will not work, the second being to fix the compiler to export the symbol with the appropriate value (Without altering the existing inlining behaviour, although it may give a more reasonable option for cases like trying to take the address of a constitem).

Happy to work on either, although I would need a mentor for the second part.

@tomjakubowski
Copy link
Contributor

I'm not sure what you mean by it not being exported. It might not be visible as a symbol (if you're linking with some C code or something), but you can certainly reference that item from another Rust crate.

@richo
Copy link
Contributor Author

richo commented Feb 2, 2015

Sorry for not being clear. That's exactly what I meant, the symbol is not visible in the resulting object.

This is pretty confusing (I've been doing a lot of C(++) <-> Rust lately and I'm trying to make the compiler warn people about all the things that have tripped me up)

@kmcallister kmcallister changed the title pub const items are not exported pub const items have no linker symbol Feb 3, 2015
@kmcallister
Copy link
Contributor

I think the right option is to expand the lint. The whole difference between const and static is that the former isn't guaranteed to have a location in memory. To a C programmer it's like a #define variable.

@kmcallister kmcallister added A-linkage Area: linking into static, shared libraries and binaries A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-FFI Area: Foreign function interface (FFI) labels Feb 3, 2015
@richo
Copy link
Contributor Author

richo commented Feb 3, 2015

Sounds totally reasonable. I'll expand the lint.

@tomjakubowski
Copy link
Contributor

Ah, I see now. I didn't know there was a lint for #[no_mangle] on items that don't export a symbol. That explains a lot!

bors added a commit that referenced this issue Feb 11, 2015
This renames the PrivateNoMangleFns lint to allow both to happen in a
single pass, since they do roughly the same work.

Closes #21856

Open questions:

[ ]: Do the tests actually pass (I'm running make check and running out the door now)
[ ]: Is the name of this lint ok. it seems to mostly be fine with [convention](https://github.com/rust-lang/rfcs/blob/cc53afbe5dea41e1f7d1c3dce71e013abe025211/text/0344-conventions-galore.md#lints)
[ ]: I'm not super thrilled about the warning text

r? @kmcallister (Shamelessly nominating because you were looking at my other ticket)
richo added a commit to richo/rust that referenced this issue Feb 11, 2015
…lister

This renames the PrivateNoMangleFns lint to allow both to happen in a
single pass, since they do roughly the same work.

Closes rust-lang#21856

Open questions:

[ ]: Do the tests actually pass (I'm running make check and running out the door now)
[ ]: Is the name of this lint ok. it seems to mostly be fine with [convention](https://github.com/rust-lang/rfcs/blob/cc53afbe5dea41e1f7d1c3dce71e013abe025211/text/0344-conventions-galore.md#lints)
[ ]: I'm not super thrilled about the warning text

r? @kmcallister (Shamelessly nominating because you were looking at my other ticket)
alexcrichton added a commit to alexcrichton/rust that referenced this issue Feb 11, 2015
This renames the PrivateNoMangleFns lint to allow both to happen in a
single pass, since they do roughly the same work.

Closes rust-lang#21856

Open questions:

[ ]: Do the tests actually pass (I'm running make check and running out the door now)
[ ]: Is the name of this lint ok. it seems to mostly be fine with [convention](https://github.com/rust-lang/rfcs/blob/cc53afbe5dea41e1f7d1c3dce71e013abe025211/text/0344-conventions-galore.md#lints)
[ ]: I'm not super thrilled about the warning text

r? @kmcallister (Shamelessly nominating because you were looking at my other ticket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-FFI Area: Foreign function interface (FFI) A-linkage Area: linking into static, shared libraries and binaries A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants