Ld not properly compiling 32 bit binary

Problem description:
x86_64 is supposed to have backwards compatibility, and I have tested this on a couple of machines outside of repl, but when I try on repl, it does not work.

Expected behavior:
My repl is x86_64, and using nasm and ld goes well with my 32 bit asm, until i try to run it. I have checked my assembly in many different environments.

nasm -f elf ./index.asm
ld -m elf_i386 -o -s ./index.o -o index
./index
Hello World!

Actual behavior:

nasm -f elf ./index.asm
ld -m elf_i386 -o -s ./index.o -o index
./index
Bad system call (core dumped)
nasm -f elf ./index.asm
ld -m elf_i386 -o -s ./index.o -o index
qemu-i386 ./index
Hello World!

Steps to reproduce:

nasm -f elf ./index.asm
ld -m elf_i386 -o -s ./index.o -o index
./index
Bad system call (core dumped)
nasm -f elf ./index.asm
ld -m elf_i386 -o -s ./index.o -o index
qemu-i386 ./index
Hello World!

Bug appears at this link:
https://replit.com/@amukh1/rppt-1

Browser/OS/Device:
Me: Chrome, Windows + WSL, Laptop
Repl: AMD EPYK Ubuntu

1 Like

Can you use 64-bit binaries?

Yeah I have a couple c++ compiled as x86_64

Then try compiling 64-bit binaries

Iā€™m already doing that with g++/gcc (but idrk what im doing at this point)

i compiled ./rpp using g++, its an 64-bit binary as you can see from the file data. it runs ok (its supposed to do that).

./index is a 32-bit binary, doesnt run on the 64 bit machine, (checked with neofetch and uname)

I think pfs was asking you to compile ./index as a 64 bit binary. (Though I could be wrong, feel free to correct me)