Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1868,11 +1868,11 @@ fn add_post_link_objects(
/// Add arbitrary "pre-link" args defined by the target spec or from command line.
/// FIXME: Determine where exactly these args need to be inserted.
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
cmd.verbatim_args(&sess.opts.unstable_opts.pre_link_args);

if let Some(args) = sess.target.pre_link_args.get(&flavor) {
cmd.verbatim_args(args.iter().map(Deref::deref));
}

cmd.verbatim_args(&sess.opts.unstable_opts.pre_link_args);
}

/// Add a link script embedded in the target, if applicable.
Expand Down Expand Up @@ -2219,6 +2219,12 @@ fn linker_with_args(

// ------------ Early order-dependent options ------------

// Can be used for adding custom CRT objects or overriding order-dependent options above.
// FIXME: In practice built-in target specs use this for arbitrary order-independent options,
// introduce a target spec option for order-independent linker options and migrate built-in
// specs to it.
add_pre_link_args(cmd, sess, flavor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd.export_symbols() has to be before any object files on some targets.

Copy link
Member

@bjorn3 bjorn3 Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you really need it before any arguments, this is still too late. get_linker already adds some args in some cases. In particular for Windows UWP it passes /LIBPATH (though there is a FIXME to move it out of get_linker.

Copy link
Author

@alban-moizan-smile alban-moizan-smile Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I understand, so, should I implement a new parameter to rustc named -Cbefore-link-args instead, put the result as the really first args, and patch the FIXME for get_linker ?


// If we're building something like a dynamic library then some platforms
// need to make sure that all symbols are exported correctly from the
// dynamic library.
Expand All @@ -2230,12 +2236,6 @@ fn linker_with_args(
&codegen_results.crate_info.exported_symbols[&crate_type],
);

// Can be used for adding custom CRT objects or overriding order-dependent options above.
// FIXME: In practice built-in target specs use this for arbitrary order-independent options,
// introduce a target spec option for order-independent linker options and migrate built-in
// specs to it.
add_pre_link_args(cmd, sess, flavor);

// ------------ Object code and libraries, order-dependent ------------

// Pre-link CRT objects.
Expand Down