]> git.lizzy.rs Git - rust.git/blob - src/librustc_back/target/l4re_base.rs
Merge branch 'refactor-select' of https://github.com/aravind-pg/rust into update...
[rust.git] / src / librustc_back / target / l4re_base.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use PanicStrategy;
12 use LinkerFlavor;
13 use target::{LinkArgs, TargetOptions};
14 use std::default::Default;
15 use std::env;
16 use std::process::Command;
17
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();
32     let mut pre_link_args = LinkArgs::new();
33     pre_link_args.insert(LinkerFlavor::Ld, vec![
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),
69     ]);
70
71     Ok(TargetOptions {
72         executables: true,
73         has_elf_tls: false,
74         exe_allocation_crate: None,
75         panic_strategy: PanicStrategy::Abort,
76         pre_link_args,
77         post_link_args,
78         target_family: Some("unix".to_string()),
79         .. Default::default()
80     })
81 }