]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/linux_musl_base.rs
Auto merge of #68414 - michaelwoerister:share-drop-glue, r=alexcrichton
[rust.git] / src / librustc_target / spec / linux_musl_base.rs
1 use crate::spec::{LinkerFlavor, TargetOptions};
2
3 pub fn opts() -> TargetOptions {
4     let mut base = super::linux_base::opts();
5
6     // Make sure that the linker/gcc really don't pull in anything, including
7     // default objects, libs, etc.
8     base.pre_link_args_crt.insert(LinkerFlavor::Gcc, Vec::new());
9     base.pre_link_args_crt.get_mut(&LinkerFlavor::Gcc).unwrap().push("-nostdlib".to_string());
10
11     // At least when this was tested, the linker would not add the
12     // `GNU_EH_FRAME` program header to executables generated, which is required
13     // when unwinding to locate the unwinding information. I'm not sure why this
14     // argument is *not* necessary for normal builds, but it can't hurt!
15     base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--eh-frame-hdr".to_string());
16
17     // When generating a statically linked executable there's generally some
18     // small setup needed which is listed in these files. These are provided by
19     // a musl toolchain and are linked by default by the `musl-gcc` script. Note
20     // that `gcc` also does this by default, it just uses some different files.
21     //
22     // Each target directory for musl has these object files included in it so
23     // they'll be included from there.
24     base.pre_link_objects_exe_crt.push("crt1.o".to_string());
25     base.pre_link_objects_exe_crt.push("crti.o".to_string());
26     base.post_link_objects_crt.push("crtn.o".to_string());
27
28     // These targets statically link libc by default
29     base.crt_static_default = true;
30     // These targets allow the user to choose between static and dynamic linking.
31     base.crt_static_respected = true;
32
33     base
34 }