Skip to content

Commit af6298d

Browse files
committed
Auto merge of #44011 - TobiasSchaffner:improved_target_spec_clean, r=alexcrichton
L4Re Target: Add the needed Libraries and locate them Add the libraries and objects that have to be linked to a get working L4Re Binary using pre- and post-link-args. Additionaly some ld commands had to be passed. * L4Re libraries and objects will be located by an environment variable. * gcc libraries and objects will be located using a gcc call. GCC is mandatory for this target, that might need documentation somewhere. As soon as something mandatory cannot be found, the compiler will panic. This is intended, because the functions involved don't allow the usage of a Result type. libgcc_eh is now passed using `-l` and crtbeginT.o and crtend.o are now located using `gcc -print-filename`.
2 parents a125ec9 + c60fc4b commit af6298d

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

src/librustc_back/target/l4re_base.rs

+55-5
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,71 @@ use PanicStrategy;
1212
use LinkerFlavor;
1313
use target::{LinkArgs, TargetOptions};
1414
use std::default::Default;
15+
use std::env;
16+
use std::process::Command;
1517

16-
pub fn opts() -> TargetOptions {
18+
// Use GCC to locate code for crt* libraries from the host, not from L4Re. Note
19+
// that a few files also come from L4Re, for these, the function shouldn't be
20+
// used. This uses GCC for the location of the file, but GCC is required for L4Re anyway.
21+
fn get_path_or(filename: &str) -> String {
22+
let child = Command::new("gcc")
23+
.arg(format!("-print-file-name={}", filename)).output()
24+
.expect("Failed to execute GCC");
25+
String::from_utf8(child.stdout)
26+
.expect("Couldn't read path from GCC").trim().into()
27+
}
28+
29+
pub fn opts() -> Result<TargetOptions, String> {
30+
let l4re_lib_path = env::var_os("L4RE_LIBDIR").ok_or("Unable to find L4Re \
31+
library directory: L4RE_LIBDIR not set.")?.into_string().unwrap();
1732
let mut pre_link_args = LinkArgs::new();
1833
pre_link_args.insert(LinkerFlavor::Ld, vec![
19-
"-nostdlib".to_string(),
34+
format!("-T{}/main_stat.ld", l4re_lib_path),
35+
"--defsym=__executable_start=0x01000000".to_string(),
36+
"--defsym=__L4_KIP_ADDR__=0x6ffff000".to_string(),
37+
format!("{}/crt1.o", l4re_lib_path),
38+
format!("{}/crti.o", l4re_lib_path),
39+
get_path_or("crtbeginT.o"),
40+
]);
41+
let mut post_link_args = LinkArgs::new();
42+
post_link_args.insert(LinkerFlavor::Ld, vec![
43+
format!("{}/l4f/libpthread.a", l4re_lib_path),
44+
format!("{}/l4f/libc_be_sig.a", l4re_lib_path),
45+
format!("{}/l4f/libc_be_sig_noop.a", l4re_lib_path),
46+
format!("{}/l4f/libc_be_socket_noop.a", l4re_lib_path),
47+
format!("{}/l4f/libc_be_fs_noop.a", l4re_lib_path),
48+
format!("{}/l4f/libc_be_sem_noop.a", l4re_lib_path),
49+
format!("{}/l4f/libl4re-vfs.o.a", l4re_lib_path),
50+
format!("{}/l4f/lib4re.a", l4re_lib_path),
51+
format!("{}/l4f/lib4re-util.a", l4re_lib_path),
52+
format!("{}/l4f/libc_support_misc.a", l4re_lib_path),
53+
format!("{}/l4f/libsupc++.a", l4re_lib_path),
54+
format!("{}/l4f/lib4shmc.a", l4re_lib_path),
55+
format!("{}/l4f/lib4re-c.a", l4re_lib_path),
56+
format!("{}/l4f/lib4re-c-util.a", l4re_lib_path),
57+
get_path_or("libgcc_eh.a"),
58+
format!("{}/l4f/libdl.a", l4re_lib_path),
59+
"--start-group".to_string(),
60+
format!("{}/l4f/libl4util.a", l4re_lib_path),
61+
format!("{}/l4f/libc_be_l4re.a", l4re_lib_path),
62+
format!("{}/l4f/libuc_c.a", l4re_lib_path),
63+
format!("{}/l4f/libc_be_l4refile.a", l4re_lib_path),
64+
"--end-group".to_string(),
65+
format!("{}/l4f/libl4sys.a", l4re_lib_path),
66+
"-gc-sections".to_string(),
67+
get_path_or("crtend.o"),
68+
format!("{}/crtn.o", l4re_lib_path),
2069
]);
2170

22-
TargetOptions {
71+
Ok(TargetOptions {
2372
executables: true,
2473
has_elf_tls: false,
25-
exe_allocation_crate: Some("alloc_system".to_string()),
74+
exe_allocation_crate: None,
2675
panic_strategy: PanicStrategy::Abort,
2776
linker: "ld".to_string(),
2877
pre_link_args,
78+
post_link_args,
2979
target_family: Some("unix".to_string()),
3080
.. Default::default()
31-
}
81+
})
3282
}

src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use LinkerFlavor;
1212
use target::{Target, TargetResult};
1313

1414
pub fn target() -> TargetResult {
15-
let mut base = super::l4re_base::opts();
15+
let mut base = super::l4re_base::opts()?;
1616
base.cpu = "x86-64".to_string();
1717
base.max_atomic_width = Some(64);
1818

0 commit comments

Comments
 (0)