ahgamut / superconfigure

wrap autotools configure scripts to build with Cosmopolitan Libc
The Unlicense
201 stars 26 forks source link

Fix invalid file (bad magic number) Exec format error on Linux #50

Closed metaist closed 3 months ago

metaist commented 3 months ago

I'm having trouble running datasette (or any of the releases) on Linux:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:    22.04
Codename:   jammy

$ wget https://github.com/ahgamut/superconfigure/releases/download/z0.0.51/datasette.zip
$ chmod +x datasette.zip
$ mv datasette.zip datasette
$ ./datasette 
invalid file (bad magic number): Exec format error
ahgamut commented 3 months ago

You can try changing binfmt_misc: https://github.com/jart/cosmopolitan?tab=readme-ov-file#linux

metaist commented 3 months ago

Thanks for getting back to me.

$ sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf
$ sudo chmod +x /usr/bin/ape
$ sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sh: 1: echo: echo: I/O error
$ sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sh: 1: echo: echo: I/O error

Ok, so maybe the problem is that root can't write to /proc/sys/fs/binfmt_misc. I'll see if I can get that to work.

metaist commented 3 months ago

I tried looking at how other people handled similar issues: https://github.com/multiarch/qemu-user-static/issues/38#issuecomment-543521290

But then after reading the actual binfmt_misc docs I see that I actually created the APE and APE-jart files in /proc/sys/fs/binfmt_misc (it was just when I tried recreating them that I got the I/O error).

Still doesn't work.

$ ./datasette 
invalid file (bad magic number): Exec format error

$ /usr/bin/ape ./datasette
ape error: ./datasette: didn't embed ELF magic
ahgamut commented 3 months ago

Okay, I'll cut a new release in a bit and we can try again. Are you running this inside a Docker image?

metaist commented 3 months ago

Thanks. I'm running this directly on my machine.

ahgamut commented 3 months ago

I think you can get it to work by:

wget https://github.com/ahgamut/superconfigure/releases/download/z0.0.51/datasette.zip
unzip datasette.zip
chmod +x bin/datasette
./bin/datasette 
metaist commented 3 months ago

Thank you; confirmed that works. I didn't realize that the APE was inside the first level of zip file.