rustc: Add support for linking arbitrary objects
MUSL for example provides its own start/end objects in place of the standard ones shipped by gcc.
This commit is contained in:
parent
22da16a4c5
commit
d09851730c
@ -91,14 +91,22 @@ pub struct Target {
|
||||
pub struct TargetOptions {
|
||||
/// Linker to invoke. Defaults to "cc".
|
||||
pub linker: String,
|
||||
/// Linker arguments that are unconditionally passed *before* any user-defined libraries.
|
||||
/// Linker arguments that are unconditionally passed *before* any
|
||||
/// user-defined libraries.
|
||||
pub pre_link_args: Vec<String>,
|
||||
/// Linker arguments that are unconditionally passed *after* any user-defined libraries.
|
||||
/// Linker arguments that are unconditionally passed *after* any
|
||||
/// user-defined libraries.
|
||||
pub post_link_args: Vec<String>,
|
||||
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults to "default".
|
||||
/// Objects to link before and after all others, always found within the
|
||||
/// sysroot folder.
|
||||
pub pre_link_objects: Vec<String>,
|
||||
pub post_link_objects: Vec<String>,
|
||||
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
|
||||
/// to "default".
|
||||
pub cpu: String,
|
||||
/// Default target features to pass to LLVM. These features will *always* be passed, and cannot
|
||||
/// be disabled even via `-C`. Corresponds to `llc -mattr=$features`.
|
||||
/// Default target features to pass to LLVM. These features will *always* be
|
||||
/// passed, and cannot be disabled even via `-C`. Corresponds to `llc
|
||||
/// -mattr=$features`.
|
||||
pub features: String,
|
||||
/// Whether dynamic linking is available on this target. Defaults to false.
|
||||
pub dynamic_linking: bool,
|
||||
@ -183,6 +191,8 @@ impl Default for TargetOptions {
|
||||
has_rpath: false,
|
||||
no_compiler_rt: false,
|
||||
position_independent_executables: false,
|
||||
pre_link_objects: Vec::new(),
|
||||
post_link_objects: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ use target::Target;
|
||||
pub fn target() -> Target {
|
||||
let mut base = super::linux_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.linker = "musl-gcc".to_string();
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
// Make sure that the linker/gcc really don't pull in anything, including
|
||||
|
@ -794,13 +794,21 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
|
||||
let pname = get_cc_prog(sess);
|
||||
let mut cmd = Command::new(&pname[..]);
|
||||
|
||||
let root = sess.target_filesearch(PathKind::Native).get_lib_path();
|
||||
cmd.args(&sess.target.target.options.pre_link_args);
|
||||
for obj in &sess.target.target.options.pre_link_objects {
|
||||
cmd.arg(root.join(obj));
|
||||
}
|
||||
|
||||
link_args(&mut cmd, sess, dylib, tmpdir.path(),
|
||||
trans, obj_filename, out_filename);
|
||||
cmd.args(&sess.target.target.options.post_link_args);
|
||||
if !sess.target.target.options.no_compiler_rt {
|
||||
cmd.arg("-lcompiler-rt");
|
||||
}
|
||||
for obj in &sess.target.target.options.post_link_objects {
|
||||
cmd.arg(root.join(obj));
|
||||
}
|
||||
cmd.args(&sess.target.target.options.post_link_args);
|
||||
|
||||
if sess.opts.debugging_opts.print_link_args {
|
||||
println!("{:?}", &cmd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user