From c151220a84e40b65e45308cc0f3bbea4466d3acf Mon Sep 17 00:00:00 2001
From: Tobias Schaffner <tschaff@genua.de>
Date: Thu, 3 Aug 2017 10:37:11 +0200
Subject: [PATCH] Add L4Re Support in librustc_back

Add support for x86_64-unknown-l4re-uclibc target, which covers
the L4 Runtime Environment.
---
 src/librustc_back/target/l4re_base.rs         | 32 +++++++++++++++++++
 src/librustc_back/target/mod.rs               |  3 ++
 .../target/x86_64_unknown_l4re_uclibc.rs      | 31 ++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 src/librustc_back/target/l4re_base.rs
 create mode 100644 src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs

diff --git a/src/librustc_back/target/l4re_base.rs b/src/librustc_back/target/l4re_base.rs
new file mode 100644
index 00000000000..998183d4015
--- /dev/null
+++ b/src/librustc_back/target/l4re_base.rs
@@ -0,0 +1,32 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use PanicStrategy;
+use LinkerFlavor;
+use target::{LinkArgs, TargetOptions};
+use std::default::Default;
+
+pub fn opts() -> TargetOptions {
+    let mut pre_link_args = LinkArgs::new();
+    pre_link_args.insert(LinkerFlavor::Ld, vec![
+            "-nostdlib".to_string(),
+    ]);
+
+    TargetOptions {
+        executables: true,
+        has_elf_tls: false,
+        exe_allocation_crate: Some("alloc_system".to_string()),
+        panic_strategy: PanicStrategy::Abort,
+        linker: "ld".to_string(),
+        pre_link_args: pre_link_args,
+        target_family: Some("unix".to_string()),
+        .. Default::default()
+    }
+}
diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs
index 0dbfdb4d809..08b94d5a01c 100644
--- a/src/librustc_back/target/mod.rs
+++ b/src/librustc_back/target/mod.rs
@@ -69,6 +69,7 @@ mod solaris_base;
 mod windows_base;
 mod windows_msvc_base;
 mod thumb_base;
+mod l4re_base;
 mod fuchsia_base;
 mod redox_base;
 
@@ -193,6 +194,8 @@ supported_targets! {
     ("aarch64-unknown-fuchsia", aarch64_unknown_fuchsia),
     ("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia),
 
+    ("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),
+
     ("x86_64-unknown-redox", x86_64_unknown_redox),
 
     ("i386-apple-ios", i386_apple_ios),
diff --git a/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs b/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs
new file mode 100644
index 00000000000..b447f8a989d
--- /dev/null
+++ b/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs
@@ -0,0 +1,31 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use LinkerFlavor;
+use target::{Target, TargetResult};
+
+pub fn target() -> TargetResult {
+    let mut base = super::l4re_base::opts();
+    base.cpu = "x86-64".to_string();
+    base.max_atomic_width = Some(64);
+
+    Ok(Target {
+        llvm_target: "x86_64-unknown-l4re-uclibc".to_string(),
+        target_endian: "little".to_string(),
+        target_pointer_width: "64".to_string(),
+        data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
+        arch: "x86_64".to_string(),
+        target_os: "l4re".to_string(),
+        target_env: "uclibc".to_string(),
+        target_vendor: "unknown".to_string(),
+        linker_flavor: LinkerFlavor::Ld,
+        options: base,
+    })
+}