Skip to content

Commit 43740ff

Browse files
committed
WIP: fix endianness of non-native 128-bit integers
1 parent 07f2116 commit 43740ff

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

.github/workflows/m68k.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,8 @@ jobs:
140140
141141
- name: Build
142142
run: |
143-
./y.sh prepare --only-libcore
144-
# TODO: move into prepare command under a flag --cross-patches?
145-
pushd build_sysroot/sysroot_src
146-
git am ../../cross_patches/*.patch
147-
popd
148-
./build.sh
143+
./y.sh prepare --only-libcore --cross
144+
./y.sh build --target m68k-unknown-linux-gnu
149145
cargo test
150146
./clean_all.sh
151147

build_system/src/build.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::path::Path;
1111
struct BuildArg {
1212
codegen_release_channel: bool,
1313
sysroot_release_channel: bool,
14-
features: Vec<String>,
14+
flags: Vec<String>,
1515
gcc_path: String,
1616
}
1717

@@ -30,12 +30,22 @@ impl BuildArg {
3030
"--release" => build_arg.codegen_release_channel = true,
3131
"--release-sysroot" => build_arg.sysroot_release_channel = true,
3232
"--no-default-features" => {
33-
build_arg.features.push("--no-default-features".to_string());
33+
build_arg.flags.push("--no-default-features".to_string());
34+
}
35+
"--target" => {
36+
if let Some(arg) = args.next() {
37+
build_arg.flags.push("--target".to_string());
38+
build_arg.flags.push(arg.as_str().into());
39+
} else {
40+
return Err(
41+
"Expected a value after `--target`, found nothing".to_string()
42+
);
43+
}
3444
}
3545
"--features" => {
3646
if let Some(arg) = args.next() {
37-
build_arg.features.push("--features".to_string());
38-
build_arg.features.push(arg.as_str().into());
47+
build_arg.flags.push("--features".to_string());
48+
build_arg.flags.push(arg.as_str().into());
3949
} else {
4050
return Err(
4151
"Expected a value after `--features`, found nothing".to_string()
@@ -61,6 +71,7 @@ impl BuildArg {
6171
--release-sysroot : Build sysroot in release mode
6272
--no-default-features : Add `--no-default-features` flag
6373
--features [arg] : Add a new feature [arg]
74+
--target [arg] : Set the target to [arg]
6475
--help : Show this help
6576
"#
6677
)
@@ -147,8 +158,6 @@ fn build_sysroot(
147158
&"build",
148159
&"--target",
149160
&target_triple,
150-
&"--features",
151-
&"compiler_builtins/c",
152161
],
153162
None,
154163
Some(env),
@@ -196,9 +205,9 @@ fn build_codegen(args: &BuildArg) -> Result<(), String> {
196205
} else {
197206
env.insert("CHANNEL".to_string(), "debug".to_string());
198207
}
199-
let ref_features = args.features.iter().map(|s| s.as_str()).collect::<Vec<_>>();
200-
for feature in &ref_features {
201-
command.push(feature);
208+
let flags = args.flags.iter().map(|s| s.as_str()).collect::<Vec<_>>();
209+
for flag in &flags {
210+
command.push(flag);
202211
}
203212
run_command_with_output_and_env(&command, None, Some(&env))?;
204213

src/context.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
2020
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
2121

2222
use crate::callee::get_fn;
23+
use crate::common::SignType;
2324

2425
#[derive(Clone)]
2526
pub struct FuncSig<'gcc> {
@@ -187,8 +188,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
187188
let ulonglong_type = context.new_c_type(CType::ULongLong);
188189
let sizet_type = context.new_c_type(CType::SizeT);
189190

190-
let isize_type = context.new_c_type(CType::Int);
191-
let usize_type = context.new_c_type(CType::UInt);
191+
let usize_type = sizet_type;
192+
let isize_type = usize_type;
192193
let bool_type = context.new_type::<bool>();
193194

194195
// TODO(antoyo): only have those assertions on x86_64.
@@ -212,7 +213,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
212213
functions.insert(builtin.to_string(), context.get_builtin_function(builtin));
213214
}
214215

215-
Self {
216+
let mut cx = Self {
216217
check_overflow,
217218
codegen_unit,
218219
context,
@@ -274,7 +275,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
274275
pointee_infos: Default::default(),
275276
structs_as_pointer: Default::default(),
276277
cleanup_blocks: Default::default(),
277-
}
278+
};
279+
// TODO(antoyo): instead of doing this, add SsizeT to libgccjit.
280+
cx.isize_type = usize_type.to_signed(&cx);
281+
cx
278282
}
279283

280284
pub fn rvalue_as_function(&self, value: RValue<'gcc>) -> Function<'gcc> {

src/int.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gccjit::{ComparisonOp, FunctionType, RValue, ToRValue, Type, UnaryOp, Binary
88
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
99
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeMethods, BuilderMethods, OverflowOp};
1010
use rustc_middle::ty::Ty;
11+
use rustc_target::abi::Endian;
1112

1213
use crate::builder::ToGccComp;
1314
use crate::{builder::Builder, common::{SignType, TypeReflection}, context::CodegenCx};
@@ -792,10 +793,16 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
792793
}
793794

794795
fn from_low_high(&self, typ: Type<'gcc>, low: i64, high: i64) -> RValue<'gcc> {
796+
let (first, last) =
797+
match self.sess().target.options.endian {
798+
Endian::Little => (low, high),
799+
Endian::Big => (high, low),
800+
};
801+
795802
let native_int_type = typ.dyncast_array().expect("get element type");
796803
let values = [
797-
self.context.new_rvalue_from_long(native_int_type, low),
798-
self.context.new_rvalue_from_long(native_int_type, high),
804+
self.context.new_rvalue_from_long(native_int_type, first),
805+
self.context.new_rvalue_from_long(native_int_type, last),
799806
];
800807
self.context.new_array_constructor(None, typ, &values)
801808
}

tests/lang_tests_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn main_inner(profile: Profile) {
7474
}
7575
// Test command 2: run `tempdir/x`.
7676
let vm_parent_dir = "/home/bouanto/Ordinateur/VirtualMachines";
77-
let vm_dir = "debian-m68k-root-img/";
77+
let vm_dir = "debian-m68k-root/";
7878
let exe_filename = exe.file_name().unwrap();
7979
let vm_exe_path = PathBuf::from(vm_parent_dir).join(vm_dir).join("home").join(exe_filename);
8080
// FIXME: panicking here makes the test pass.

0 commit comments

Comments
 (0)