Skip to content

Support dylib LTO #765

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
steveklabnik opened this issue Jan 29, 2015 · 4 comments
Closed

Support dylib LTO #765

steveklabnik opened this issue Jan 29, 2015 · 4 comments
Labels
T-dev-tools Relevant to the development tools team, which will review and decide on the RFC.

Comments

@steveklabnik
Copy link
Member

Issue by mprobinson
Tuesday Nov 11, 2014 at 00:52 GMT

For earlier discussion, see rust-lang/rust#18863

This issue was labelled with: in the Rust repository


Dylibs are currently bloated with useless library code, see #18541. This can be worked around in a platform specific manner using linker scripts, but the correct solution would be to build them with LTO.

@alexcrichton alexcrichton added the T-dev-tools Relevant to the development tools team, which will review and decide on the RFC. label May 18, 2015
@alexchandel
Copy link

Why hasn't this happened yet? LTO is necessary for programs that attempt to dynamically load modules/algorithms, when you want to implement such a module in Rust. The fact that this,

#![crate_type = "dylib"]
#![feature(no_std)]
// ...use stmts, C struct&enum declarations...
#[no_mangle]
pub unsafe extern "system" fn alg_run(p: *mut c_rect, dt: f64, stage: c_stage) -> c_int {
    (if let Some(r) = p.as_mut() {
        r.outputs[0] = 0.;
        r.outputs[1] = 1.;
        r.outputs[2] = 2.;
        r.outputs[3] = 3.;
        OK
    } else {
        NullPtr
    }) as c_int
}

compiles to a 724K dylib after optimization is revolting. I agree that static linking is better. But on platforms where it exists, for programs that use it, dynamic linking is sometimes absolutely necessary. Please stop neglecting it.

@steveklabnik
Copy link
Member Author

Please stop neglecting it.

Please try to recognize that the Rust project has a lot going on, in many different directions. There are tons of things which would be nice to have, but there are only so many hours in the day.

@comex
Copy link

comex commented Dec 1, 2015

Just for the record, you can simulate this by compiling to a staticlib and then converting it to a dylib. For example, on OS X:

rustc --crate-type staticlib test.rs -O -C lto 
clang -dynamiclib -o libtest.dylib libtest.a -Wl,-exported_symbol,_foo -Wl,-dead_strip

@hanna-kruppe
Copy link

We have the cdylib crate type now, which should address all cases where one wants to export only extern fns. dylib is just an intermediate Rust-specific output to be consumed by other Rust crates that are compiled with -C prefer-dynamic.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-dev-tools Relevant to the development tools team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

7 participants