Okay, I just wanted to run a simple GNU Assembler program, but something is going wrong.
.data
hello_str:
.string "Hello, world!\n"
.set hello_str_length, . - hello_str - 1
.text
.globl main
.type main, @function
main:
movl $4, %eax
movl $1, %ebx
movl $hello_str, %ecx
movl $hello_str_length, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
.size main, . - main
I type gcc -no-pie hello.s -o hello
, then ./hello
and gets Segmentation fault (core dumped).
I thought maybe the whole point is that I'm running it on a 64-bit system, so I added .code32
at the beginning - it didn't help.
I tried to run it differently. For example, gcc -m32 -no-pie hello.s
and gcc -m32 --no-pie hello.s
gets me the same message:
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: cannot find libgcc_s.so.1: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
collect2: error: ld returned 1 exit status
Installed gcc-multilib
then I finally can type gcc -m32 -no-pie hello.s
, but when I type ./a.out
it throws:
-bash: ./a.out: cannot execute binary file: Exec format error
I am using Ubuntu on Windows.