dr0n3
Posts: 1
Joined: Wed Jun 16, 2021 9:25 am

Compile and run a 32bit binary on Rp4 running linux 64bit

Wed Jun 16, 2021 9:47 am

Hi Everyone,

i need to compile and run a 32bit binary on rp4 running linux 64bit. I am using gcc compiler and following this https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html i am trying to understand how to do it.
I am realized that the -m32 flag is not supported on ARMv8 linux machines. Looking at https://gcc.gnu.org/onlinedocs/gcc/AArc ... ions.html i didn’t find anything interesting.

In according to https://linux.die.net/man/1/arm-linux-gnu-gcc the AArch64 gcc options are listed here:

Code: Select all

Machine Dependent Options
    AArch64 Options -mbig-endian -mlittle-endian -mgeneral-regs-only -mcmodel=tiny -mcmodel=small -mcmodel=large -mstrict-align -momit-leaf-frame-pointer -mno-omit-leaf-frame-pointer -mtls-dialect=desc -mtls-dialect=traditional -march=name -mcpu=name -mtune=name
So my question is: is it possible to compile and run a 32-bit binary on a 64-bit linux Armv8 machine ? and is so, how ?

Thank you.

User avatar
Gavinmc42
Posts: 5875
Joined: Wed Aug 28, 2013 3:31 am

Re: Compile and run a 32bit binary on Rp4 running linux 64bit

Mon Jun 21, 2021 3:51 am

Search for "Chroot".
Forgotten how to do it, but here is one way.
viewtopic.php?f=66&t=254027&p=1554468&h ... 4#p1554468

Wiki for Gentoo6, similar for Debian?
https://github.com/sakaki-/gentoo-on-rp ... too-System
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

m4r35n357
Posts: 100
Joined: Fri Jul 06, 2012 4:31 pm
Location: UK

Re: Compile and run a 32bit binary on Rp4 running linux 64bit

Mon Jun 21, 2021 8:40 am

A little unconventional, but this is how I do it (I use the MUSL targets):

https://andrewkelley.me/post/zig-cc-pow ... clang.html

It might seem clunky using Zig to compile c code, but once you have set it up it works like magic, for a wide variety of targets! Read the article anyway, I predict you will be impressed.

In this way, using the long double type, I can get a choice of 128-bit floats in software (by selecting 64 bit), or 64-bit floats in hardware (32 bit) from the same source code ;) I can (and do) even create these targets on my x86-64 NUC. I think cross compilation is now a solved problem ;)

Return to “General discussion”