Skip to content

Commit b66c4ed

Browse files
committed
Only use pre/post_link_objects for static linking
These options only exist for the special case of static cross-linking pure rust code for a musl-based target with a non-musl toolchain. In all other situations (dynamic linking, presence of a native or cross compiler) these objects will be automatically provided and linked by the toolchain.
1 parent e6dbe3b commit b66c4ed

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/librustc_trans/back/link.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,15 @@ fn link_natively(sess: &Session,
715715
let root = sess.target_filesearch(PathKind::Native).get_lib_path();
716716
cmd.args(&sess.target.target.options.pre_link_args);
717717

718-
let pre_link_objects = if crate_type == config::CrateTypeExecutable {
719-
&sess.target.target.options.pre_link_objects_exe
720-
} else {
721-
&sess.target.target.options.pre_link_objects_dll
722-
};
723-
for obj in pre_link_objects {
724-
cmd.arg(root.join(obj));
718+
if sess.crt_static() {
719+
let pre_link_objects = if crate_type == config::CrateTypeExecutable {
720+
&sess.target.target.options.pre_link_objects_exe
721+
} else {
722+
&sess.target.target.options.pre_link_objects_dll
723+
};
724+
for obj in pre_link_objects {
725+
cmd.arg(root.join(obj));
726+
}
725727
}
726728

727729
if sess.target.target.options.is_like_emscripten {
@@ -739,8 +741,10 @@ fn link_natively(sess: &Session,
739741
objects, out_filename, outputs, trans);
740742
}
741743
cmd.args(&sess.target.target.options.late_link_args);
742-
for obj in &sess.target.target.options.post_link_objects {
743-
cmd.arg(root.join(obj));
744+
if sess.crt_static() {
745+
for obj in &sess.target.target.options.post_link_objects {
746+
cmd.arg(root.join(obj));
747+
}
744748
}
745749
cmd.args(&sess.target.target.options.post_link_args);
746750

0 commit comments

Comments
 (0)