Skip to content

Private lang items should be exported symbols #11591

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

Closed
huonw opened this issue Jan 16, 2014 · 5 comments · Fixed by #11603
Closed

Private lang items should be exported symbols #11591

huonw opened this issue Jan 16, 2014 · 5 comments · Fixed by #11603
Labels
A-linkage Area: linking into static, shared libraries and binaries

Comments

@huonw
Copy link
Member

huonw commented Jan 16, 2014

// lang_lib.rs
#[no_std];
#[crate_type="lib"];

#[lang="fail_"]
fn fail(_: *i8, _: *i8, _: uint) -> ! { loop {} }
// lang_bin.rs
#[no_std];

extern mod lang_lib;

#[no_mangle]
pub extern "C" fn rust_stack_exhausted() {}

#[start]
fn main(_: int, _: **u8) -> int {
    1 % 1
}

Fails to compile with linking errors:

error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'lang_bin' 'lang_bin.o' '-Wl,--as-needed' '-L.' '-L/home/huon/projects/test-rust/.rust' '-L/home/huon/projects/test-rust' '-L/home/huon/.rust' '-L.' '-llang_lib-18b73ee1-0.0' '-lmorestack' '-Wl,-rpath,$ORIGIN/.' '-Wl,-rpath,$ORIGIN/../../../../usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/home/huon/projects/test-rust' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib'
note: lang_bin.o: In function `main::h1f6a57660259bd57ag::v0.0':
lang_bin.rc:(.text+0xe8): undefined reference to `fail::h1cf66c4f37e71757ac::v0.0'
collect2: error: ld returned 1 exit status
@huonw
Copy link
Member Author

huonw commented Jan 16, 2014

Either this or require that they are pub.

@brson
Copy link
Contributor

brson commented Jan 16, 2014

I think I disagree. Lang items should be public - for the most part they are used just like any other item.

@brson
Copy link
Contributor

brson commented Jan 16, 2014

Though there is some appeal to being able to hide lang items that aren't part of the public API.

@alexcrichton
Copy link
Member

I don't think we'll ever expect someone to use a lang item directly, and for an executable there's no need for lang items to be public, there's not even a need for them to be reachable really. I suppose we could just require that libraries have public lang items?

Regardless, this seems like kinda a corner case to me because there's not that much interaction with lang items.

@brson
Copy link
Contributor

brson commented Jan 16, 2014

I'm actually surprised that this example compiled. I guess something in rustc was ignoring visibility when encoding calls to fail_.

bors added a commit that referenced this issue Feb 22, 2014
This prevents linker errors as found in #11591

Closes #11591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants