toolchain-gcc/0001-codegen-add-support-for-megadrive.patch
2025-01-15 13:17:41 +01:00

124 lines
4.4 KiB
Diff

From 0c4bd1d8bb2863f16f13faad58eb3cbbcf7044cc Mon Sep 17 00:00:00 2001
From: User <user@example.com>
Date: Wed, 15 Jan 2025 11:49:31 +0000
Subject: [PATCH] codegen: add support for megadrive
---
build_system/build_sysroot/Cargo.toml | 8 +++-----
src/base.rs | 17 +++++++++++++++++
src/gcc_util.rs | 3 +--
src/lib.rs | 1 +
target_specs/m68k-unknown-linux-gnu.json | 12 ++++++------
5 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/build_system/build_sysroot/Cargo.toml b/build_system/build_sysroot/Cargo.toml
index 2415207..8f928c5 100644
--- a/build_system/build_sysroot/Cargo.toml
+++ b/build_system/build_sysroot/Cargo.toml
@@ -6,11 +6,8 @@ resolver = "2"
[dependencies]
core = { path = "./sysroot_src/library/core" }
-compiler_builtins = "0.1"
+compiler_builtins = { version = "0.1", features = ["c"] }
alloc = { path = "./sysroot_src/library/alloc" }
-std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
-test = { path = "./sysroot_src/library/test" }
-proc_macro = { path = "./sysroot_src/library/proc_macro" }
[patch.crates-io]
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }
@@ -35,4 +32,5 @@ codegen-units = 10000
[profile.release]
debug = "limited"
-#lto = "fat" # TODO(antoyo): re-enable when the failing LTO tests regarding proc-macros are fixed.
+panic = "abort"
+lto = "fat"
diff --git a/src/base.rs b/src/base.rs
index c9701fb..989f8aa 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -156,7 +156,24 @@ pub fn compile_codegen_unit(
let target_cpu = gcc_util::target_cpu(tcx.sess);
if target_cpu != "generic" {
context.add_command_line_option(format!("-march={}", target_cpu));
+ context.add_command_line_option("-mcpu=68000");
}
+ context.add_command_line_option("-flto");
+ context.add_driver_option("-flto");
+ //context.add_command_line_option("-fno-rtti");
+ context.add_driver_option("-fno-rtti");
+ context.add_command_line_option("-fno-exceptions");
+ context.add_driver_option("-fno-exceptions");
+
+ // Improve linker garbage collection
+ context.add_driver_option("-ffunction-sections");
+ context.add_command_line_option("-ffunction-sections");
+ context.add_driver_option("-fdata-sections");
+ context.add_command_line_option("-fdata-sections");
+
+ // ?
+ context.add_driver_option("-mxgot");
+ context.add_command_line_option("-mxgot");
if tcx
.sess
diff --git a/src/gcc_util.rs b/src/gcc_util.rs
index 560aff4..39b1889 100644
--- a/src/gcc_util.rs
+++ b/src/gcc_util.rs
@@ -242,8 +242,7 @@ pub fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]>
fn arch_to_gcc(name: &str) -> &str {
match name {
- "M68020" => "68020",
- _ => name,
+ _ => "68000",
}
}
diff --git a/src/lib.rs b/src/lib.rs
index f6ad0c7..e19dbcf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -196,6 +196,7 @@ impl CodegenBackend for GccCodegenBackend {
let context = Context::default();
if target_cpu != "generic" {
context.add_command_line_option(format!("-march={}", target_cpu));
+ context.add_command_line_option("-mcpu=68000");
}
**self.target_info.info.lock().expect("lock") = context.get_target_info();
diff --git a/target_specs/m68k-unknown-linux-gnu.json b/target_specs/m68k-unknown-linux-gnu.json
index 95ea061..d1ff9a2 100644
--- a/target_specs/m68k-unknown-linux-gnu.json
+++ b/target_specs/m68k-unknown-linux-gnu.json
@@ -1,17 +1,17 @@
{
"arch": "m68k",
- "cpu": "M68020",
+ "cpu": "M68000",
"crt-static-respected": true,
"data-layout": "E-m:e-p:32:16:32-i8:8:8-i16:16:16-i32:16:32-n8:16:32-a:0:16-S16",
- "dynamic-linking": true,
+ "dynamic-linking": false,
"env": "gnu",
"has-rpath": true,
- "has-thread-local": true,
- "llvm-target": "m68k-unknown-linux-gnu",
+ "has-thread-local": false,
+ "llvm-target": "m68k-elf",
"max-atomic-width": 32,
"os": "linux",
- "position-independent-executables": true,
- "relro-level": "full",
+ "position-independent-executables": false,
+ "relro-level": "none",
"supported-split-debuginfo": [
"packed",
"unpacked",
--
2.34.1