jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.84k stars 612 forks source link

Cannot compile on aarch64 #139

Closed dosisod closed 3 years ago

dosisod commented 3 years ago

I am trying to compile Cosmopolitan on Android (via Termux), and am getting the following output:

$ uname -a
Linux localhost 3.18.71-14948330 #1 SMP PREEMPT Mon Jan 25 18:01:59 KST 2021 aarch64 Android

$ make
♥cosmo
o/third_party/gcc/bin/x86_64-linux-musl-gcc: 23: o/third_party/gcc/bin/x86_64-linux-musl-gcc: Syntax error: ")" unexpected
o/build/bootstrap/compile.com: 33: o/build/bootstrap/compile.com: Syntax error: "(" unexpected (expecting ")")
o/build/bootstrap/compile.com: 33: o/build/bootstrap/compile.com: Syntax error: "(" unexpected (expecting ")")
make: *** [build/rules.mk:57: o//ape/ape.o] Error 2

compile.com is an x86_64 ELF binary, not ARM, hence the errors. To fix this, we could have an option to re-build compile.com from scratch so that it is in the right architecture, or provide multiple pre-compiled versions for different architectures (for all the bootstrapped binaries). This also means that we will need to provide alternate versions for thrid_party/gcc/x86_64-linux-musl/*.

jart commented 3 years ago

The error you encountered is just the first hurdle of a long marathon. Porting to aarch64 would also mean we'd need to rewrite files like syscalls.sh and possibly consts.sh too. Plus rewriting all the assembly code that exists in this codebase. Also all the data structures like struct stat would need to be thunked differently for each architecture.

I'm reluctant to support ARM because it would increase the dimensionality of our support vector, and I'm not even convinced that portable binaries is what ARM users want. ARM users value resource efficiency and they're unlikely to be happy with binaries that aren't cross-compiled for the specific superset of the ISA that they're using.

What I want to see happen is for our qemu-user-x86_64 shim in the APE bootloader to work better.