-
Notifications
You must be signed in to change notification settings - Fork 74
How to build for i686-unknown-linux-gnu? #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi. The type 32 is For the second error, it could just be a bug in libgccjit: are those 2 types (unsigned long long and __uint32_t) of the same size of that target? |
Yes, I use your fork. Here is how I configure it:
Also I set
|
Did you add |
No. I did right now, here are new errors:
|
This problem is likely to be caused by this code. You can probably replace In the long term, those would need to be replaced by |
Okay, new errors (several thousand repeating lines):
|
Try adding:
(also keep the |
Nice. New errors:
End the rest:
|
Try changing this line to the following: arg = self.cx.context.new_cast(None, arg, param_type); |
|
Can you please try running |
No, didn't help. |
Which is defined in |
Adding |
Nice! We should keep this issue open to have a list of what needs to be fixed and also to think about how to support multiarch easily. |
I created a working I will try to reduce the number of changed lines and post the patch. |
diff --git a/config.sh b/config.sh
index b25e215..18574f2 100644
--- a/config.sh
+++ b/config.sh
@@ -20,8 +20,9 @@ else
fi
HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
-TARGET_TRIPLE=$HOST_TRIPLE
+#TARGET_TRIPLE=$HOST_TRIPLE
#TARGET_TRIPLE="m68k-unknown-linux-gnu"
+TARGET_TRIPLE="i686-unknown-linux-gnu"
linker=''
RUN_WRAPPER=''
@@ -33,6 +34,8 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
linker='-Clinker=aarch64-linux-gnu-gcc'
RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'
+ elif [[ "$TARGET_TRIPLE" == "i686-unknown-linux-gnu" ]]; then
+ : # do nothing
else
echo "Unknown non-native platform"
fi
diff --git a/src/back/write.rs b/src/back/write.rs
index efcf18d..e640fbe 100644
--- a/src/back/write.rs
+++ b/src/back/write.rs
@@ -14,6 +14,8 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_codegen", &*module.name);
{
let context = &module.module_llvm.context;
+ context.add_command_line_option("-m32");
+ context.add_driver_option("-m32");
let module_name = module.name.clone();
let module_name = Some(&module_name[..]);
diff --git a/src/base.rs b/src/base.rs
index 8cc9581..fb8bd88 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -98,7 +98,7 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol, supports_
context.add_command_line_option("-mpclmul");
context.add_command_line_option("-mfma");
context.add_command_line_option("-mfma4");
- context.add_command_line_option("-m64");
+ context.add_command_line_option("-m32");
context.add_command_line_option("-mbmi");
context.add_command_line_option("-mgfni");
context.add_command_line_option("-mavxvnni");
diff --git a/src/context.rs b/src/context.rs
index 2699559..056352a 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -161,13 +161,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let ulonglong_type = context.new_c_type(CType::ULongLong);
let sizet_type = context.new_c_type(CType::SizeT);
- let isize_type = context.new_c_type(CType::LongLong);
- let usize_type = context.new_c_type(CType::ULongLong);
+ let isize_type = context.new_c_type(CType::Int);
+ let usize_type = context.new_c_type(CType::UInt);
let bool_type = context.new_type::<bool>();
// TODO(antoyo): only have those assertions on x86_64.
- assert_eq!(isize_type.get_size(), i64_type.get_size());
- assert_eq!(usize_type.get_size(), u64_type.get_size());
+ assert_eq!(isize_type.get_size(), i32_type.get_size());
+ assert_eq!(usize_type.get_size(), u32_type.get_size());
let mut functions = FxHashMap::default();
let builtins = [
diff --git a/src/int.rs b/src/int.rs
index 0c5dab0..5fd4925 100644
--- a/src/int.rs
+++ b/src/int.rs
@@ -524,7 +524,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
// when having proper sized integer types.
let param_type = bswap.get_param(0).to_rvalue().get_type();
if param_type != arg_type {
- arg = self.bitcast(arg, param_type);
+ arg = self.cx.context.new_cast(None, arg, param_type);
}
self.cx.context.new_call(None, bswap, &[arg])
}
diff --git a/src/lib.rs b/src/lib.rs
index e43ee5c..8fb5823 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -104,6 +104,7 @@ impl CodegenBackend for GccCodegenBackend {
let temp_dir = TempDir::new().expect("cannot create temporary directory");
let temp_file = temp_dir.into_path().join("result.asm");
let check_context = Context::default();
+ check_context.add_command_line_option("-m32");
check_context.set_print_errors_to_stderr(false);
let _int128_ty = check_context.new_c_type(CType::UInt128t);
// NOTE: we cannot just call compile() as this would require other files than libgccjit.so. |
@antoyo I found out "int $$0x80" fails with:
whereas "int 0x80" works fine. MRE:
|
|
That's how I got here: https://github.com/jasonwhite/syscalls/blob/288d146210fd378999d0f825ffef9cb3a002f38e/src/syscall/x86.rs#L28. Why is it working with the LLVM backend but not with yours?
|
LLVM tries to be compatible with GCC/GAS, but because of a license incompatibility (Apache-2.0 WITH LLVM-exception vs GPL-3.0) LLVM can't copy the parser code from GAS and instead has to write it from scratch while attempting to stay compatible with all weirdness. This doesn't always work. For example at some point LLVM didn't accept
The att_syntax flag should be implemented based on a look at the source. (by the way @antoyo is the author of cg_gcc. I'm the author of cg_clif.) |
The One thing that could be causing an issues is if the LLVM flag That would help if you would post the complete |
/tmp/libgccjit-TeTOpc/fake.s
|
Yeah, there's nothing that indicates that it should use the AT&T syntax. |
Here's your LLVM IR.
turns into
|
So, it seems to me that @bjorn3 is right:
As such, this is an incompatibility between the LLVM and GCC codegen and won't be fixed. The library source code should probably be fixed instead. (Linking the issue you opened for posterity.) |
@kpp: Can we close this issue or did you have any other issues? If we can close it, I'll open a new issue with the content of this comment. |
Yes! Thank you for your help! |
Hello, I would like to build a x86 only binary. I tried to build libgccjit multiple times but I failed. So I got errors like:
or
Can you please help me?
The text was updated successfully, but these errors were encountered: