-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
x86_64-musl: allow building dylibs with -crt-static #38075
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,7 +237,7 @@ pub fn default_output_for_target(sess: &Session) -> config::CrateType { | |
/// Checks if target supports crate_type as output | ||
pub fn invalid_output_for_target(sess: &Session, | ||
crate_type: config::CrateType) -> bool { | ||
match (sess.target.target.options.dynamic_linking, | ||
match (sess.target.target.options.dynamic_linking && !sess.target_is_crt_static(), | ||
sess.target.target.options.executables, crate_type) { | ||
(false, _, config::CrateTypeCdylib) | | ||
(false, _, config::CrateTypeProcMacro) | | ||
|
@@ -668,6 +668,9 @@ fn link_natively(sess: &Session, | |
let (pname, mut cmd, extra) = get_linker(sess); | ||
cmd.env("PATH", command_path(sess, extra)); | ||
|
||
let musl = sess.target.target.llvm_target.contains("musl"); | ||
let crt_static = sess.target_is_crt_static(); | ||
|
||
let root = sess.target_filesearch(PathKind::Native).get_lib_path(); | ||
cmd.args(&sess.target.target.options.pre_link_args); | ||
|
||
|
@@ -676,8 +679,12 @@ fn link_natively(sess: &Session, | |
} else { | ||
&sess.target.target.options.pre_link_objects_dll | ||
}; | ||
for obj in pre_link_objects { | ||
cmd.arg(root.join(obj)); | ||
// When dynamically linking to MUSL we don't need to pass our startup | ||
// objects as those will be provided by the MUSL toolchain | ||
if !musl || crt_static { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm this is always something I wish we could sink into the target specs rather than have here... Does anything leap to mind for you as an easy way to do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
BTW, is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think all options are configurable from json files now (we round-trip through that format to read our own options IIRC). I mean all the options in the custom target specs are already super specific... I guess I wouldn't really have a problem with those. |
||
for obj in pre_link_objects { | ||
cmd.arg(root.join(obj)); | ||
} | ||
} | ||
|
||
{ | ||
|
@@ -686,8 +693,11 @@ fn link_natively(sess: &Session, | |
objects, out_filename, outputs, trans); | ||
} | ||
cmd.args(&sess.target.target.options.late_link_args); | ||
for obj in &sess.target.target.options.post_link_objects { | ||
cmd.arg(root.join(obj)); | ||
// Same as above | ||
if !musl || crt_static { | ||
for obj in &sess.target.target.options.post_link_objects { | ||
cmd.arg(root.join(obj)); | ||
} | ||
} | ||
cmd.args(&sess.target.target.options.post_link_args); | ||
|
||
|
@@ -813,8 +823,9 @@ fn link_args(cmd: &mut Linker, | |
let mut args = args.iter().chain(more_args.iter()).chain(used_link_args.iter()); | ||
let relocation_model = sess.opts.cg.relocation_model.as_ref() | ||
.unwrap_or(&empty_str); | ||
let crt_static = sess.target_is_crt_static(); | ||
if (t.options.relocation_model == "pic" || *relocation_model == "pic") | ||
&& !args.any(|x| *x == "-static") { | ||
&& !args.any(|x| *x == "-static") && !crt_static { | ||
cmd.position_independent_executable(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I think this isn't quite accurate for MSVC where you can statically link msvcrt but still create DLLs (I believe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following that logic, it should also be possible to build MUSL dylibs (
.so
libraries) that statically link to libc but link dynamically to other libraries I think (maybe not?). Do we want to support that as well?If not then I can just add a
!musl ||
here I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose if it's possible we should allow it. AFAIK it just gave a weird linker error when I tried with musl awhile back. That's probably b/c we were using wrong startup objects or something like that?
Ideally we'd avoid as many
!musl
conditions as possible...