From 34ea8f4435370cb30e15ab0ab3243771a3bcf9d2 Mon Sep 17 00:00:00 2001
From: Jonathan Behrens <fintelia@gmail.com>
Date: Wed, 30 Jan 2019 15:36:14 -0500
Subject: [PATCH 1/3] Add riscv64imc target

These changes are based on 8dfd5c39a121521124d5500b172f46ae12ee3e0c which added
the riscv32imc target.
---
 src/ci/docker/dist-various-1/Dockerfile       |  1 +
 src/librustc_target/spec/mod.rs               |  1 +
 .../spec/riscv64imc_unknown_none_elf.rs       | 42 +++++++++++++++++++
 src/tools/build-manifest/src/main.rs          |  1 +
 4 files changed, 45 insertions(+)
 create mode 100644 src/librustc_target/spec/riscv64imc_unknown_none_elf.rs

diff --git a/src/ci/docker/dist-various-1/Dockerfile b/src/ci/docker/dist-various-1/Dockerfile
index ab2dd5a399280..9f58e078cf52f 100644
--- a/src/ci/docker/dist-various-1/Dockerfile
+++ b/src/ci/docker/dist-various-1/Dockerfile
@@ -112,6 +112,7 @@ ENV TARGETS=$TARGETS,thumbv7em-none-eabihf
 ENV TARGETS=$TARGETS,thumbv8m.main-none-eabi
 ENV TARGETS=$TARGETS,riscv32imc-unknown-none-elf
 ENV TARGETS=$TARGETS,riscv32imac-unknown-none-elf
+ENV TARGETS=$TARGETS,riscv64imc-unknown-none-elf
 ENV TARGETS=$TARGETS,armebv7r-none-eabi
 ENV TARGETS=$TARGETS,armebv7r-none-eabihf
 ENV TARGETS=$TARGETS,armv7r-none-eabi
diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs
index 107583e4fc0a0..ab5425c5a91ff 100644
--- a/src/librustc_target/spec/mod.rs
+++ b/src/librustc_target/spec/mod.rs
@@ -451,6 +451,7 @@ supported_targets! {
 
     ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
     ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
+    ("riscv64imc-unknown-none-elf", riscv64imc_unknown_none_elf),
 
     ("aarch64-unknown-none", aarch64_unknown_none),
 
diff --git a/src/librustc_target/spec/riscv64imc_unknown_none_elf.rs b/src/librustc_target/spec/riscv64imc_unknown_none_elf.rs
new file mode 100644
index 0000000000000..7586f2134495a
--- /dev/null
+++ b/src/librustc_target/spec/riscv64imc_unknown_none_elf.rs
@@ -0,0 +1,42 @@
+// Copyright 2018 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 spec::{LinkerFlavor, LldFlavor, PanicStrategy,
+           Target, TargetOptions, TargetResult};
+
+pub fn target() -> TargetResult {
+    Ok(Target {
+        data_layout: "e-m:e-i64:64-n64-S128".to_string(),
+        llvm_target: "riscv64".to_string(),
+        target_endian: "little".to_string(),
+        target_pointer_width: "64".to_string(),
+        target_c_int_width: "32".to_string(),
+        target_os: "none".to_string(),
+        target_env: String::new(),
+        target_vendor: "unknown".to_string(),
+        arch: "riscv64".to_string(),
+        linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
+
+        options: TargetOptions {
+            linker: Some("rust-lld".to_string()),
+            cpu: "generic-rv64".to_string(),
+            // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005
+            max_atomic_width: None, //Some(32),
+            atomic_cas: false,
+            features: "+m,+c".to_string(),
+            executables: true,
+            panic_strategy: PanicStrategy::Abort,
+            relocation_model: "static".to_string(),
+            emit_debug_gdb_scripts: false,
+            abi_blacklist: super::riscv_base::abi_blacklist(),
+            .. Default::default()
+        },
+    })
+}
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
index eaba473f9c3b8..05a86da68535f 100644
--- a/src/tools/build-manifest/src/main.rs
+++ b/src/tools/build-manifest/src/main.rs
@@ -85,6 +85,7 @@ static TARGETS: &'static [&'static str] = &[
     "powerpc64le-unknown-linux-gnu",
     "riscv32imc-unknown-none-elf",
     "riscv32imac-unknown-none-elf",
+    "riscv64imc-unknown-none-elf",
     "s390x-unknown-linux-gnu",
     "sparc64-unknown-linux-gnu",
     "sparcv9-sun-solaris",

From de3e93c68307851b167a644f209fb573fabe6757 Mon Sep 17 00:00:00 2001
From: Jonathan Behrens <fintelia@gmail.com>
Date: Wed, 30 Jan 2019 16:29:52 -0500
Subject: [PATCH 2/3] Change target to riscv64gc-unknown-none-elf and remove
 copyright notice

---
 src/ci/docker/dist-various-1/Dockerfile              |  2 +-
 src/librustc_target/spec/mod.rs                      |  2 +-
 ...own_none_elf.rs => riscv64gc_unknown_none_elf.rs} | 12 +-----------
 src/tools/build-manifest/src/main.rs                 |  2 +-
 4 files changed, 4 insertions(+), 14 deletions(-)
 rename src/librustc_target/spec/{riscv64imc_unknown_none_elf.rs => riscv64gc_unknown_none_elf.rs} (68%)

diff --git a/src/ci/docker/dist-various-1/Dockerfile b/src/ci/docker/dist-various-1/Dockerfile
index 9f58e078cf52f..41295c3b16c27 100644
--- a/src/ci/docker/dist-various-1/Dockerfile
+++ b/src/ci/docker/dist-various-1/Dockerfile
@@ -112,7 +112,7 @@ ENV TARGETS=$TARGETS,thumbv7em-none-eabihf
 ENV TARGETS=$TARGETS,thumbv8m.main-none-eabi
 ENV TARGETS=$TARGETS,riscv32imc-unknown-none-elf
 ENV TARGETS=$TARGETS,riscv32imac-unknown-none-elf
-ENV TARGETS=$TARGETS,riscv64imc-unknown-none-elf
+ENV TARGETS=$TARGETS,riscv64gc-unknown-none-elf
 ENV TARGETS=$TARGETS,armebv7r-none-eabi
 ENV TARGETS=$TARGETS,armebv7r-none-eabihf
 ENV TARGETS=$TARGETS,armv7r-none-eabi
diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs
index ab5425c5a91ff..ae7904f553973 100644
--- a/src/librustc_target/spec/mod.rs
+++ b/src/librustc_target/spec/mod.rs
@@ -451,7 +451,7 @@ supported_targets! {
 
     ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
     ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
-    ("riscv64imc-unknown-none-elf", riscv64imc_unknown_none_elf),
+    ("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
 
     ("aarch64-unknown-none", aarch64_unknown_none),
 
diff --git a/src/librustc_target/spec/riscv64imc_unknown_none_elf.rs b/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
similarity index 68%
rename from src/librustc_target/spec/riscv64imc_unknown_none_elf.rs
rename to src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
index 7586f2134495a..12bae4c2e47ac 100644
--- a/src/librustc_target/spec/riscv64imc_unknown_none_elf.rs
+++ b/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
@@ -1,19 +1,9 @@
-// Copyright 2018 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 spec::{LinkerFlavor, LldFlavor, PanicStrategy,
            Target, TargetOptions, TargetResult};
 
 pub fn target() -> TargetResult {
     Ok(Target {
-        data_layout: "e-m:e-i64:64-n64-S128".to_string(),
+        data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(),
         llvm_target: "riscv64".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
index 05a86da68535f..34c9fa6ca27ad 100644
--- a/src/tools/build-manifest/src/main.rs
+++ b/src/tools/build-manifest/src/main.rs
@@ -85,7 +85,7 @@ static TARGETS: &'static [&'static str] = &[
     "powerpc64le-unknown-linux-gnu",
     "riscv32imc-unknown-none-elf",
     "riscv32imac-unknown-none-elf",
-    "riscv64imc-unknown-none-elf",
+    "riscv64gc-unknown-none-elf",
     "s390x-unknown-linux-gnu",
     "sparc64-unknown-linux-gnu",
     "sparcv9-sun-solaris",

From ebb1a522074c54c5c0555a2be334b86a64feb9ef Mon Sep 17 00:00:00 2001
From: Jonathan Behrens <fintelia@gmail.com>
Date: Wed, 30 Jan 2019 16:55:45 -0500
Subject: [PATCH 3/3] Pass more features to LLVM

---
 src/librustc_target/spec/riscv64gc_unknown_none_elf.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs b/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
index 12bae4c2e47ac..eeb10bec1aef8 100644
--- a/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
+++ b/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
@@ -20,7 +20,7 @@ pub fn target() -> TargetResult {
             // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005
             max_atomic_width: None, //Some(32),
             atomic_cas: false,
-            features: "+m,+c".to_string(),
+            features: "+m,+a,+f,+d,+c".to_string(),
             executables: true,
             panic_strategy: PanicStrategy::Abort,
             relocation_model: "static".to_string(),