“Hello World”的分段错误

问题描述 投票:0回答:0

好吧,我只是想运行一个简单的 GNU 汇编程序,但是出了点问题。

.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    

我键入

gcc -no-pie hello.s -o hello
,然后
./hello
并得到 Segmentation fault (core dumped).

我想也许重点是我在 64 位系统上运行它,所以我在开头添加了

.code32
- 它没有帮助。

我尝试以不同的方式运行它。例如,

gcc -m32 -no-pie hello.s
gcc -m32 --no-pie hello.s
得到相同的消息:

/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

我在 Windows 上使用 Ubuntu。

assembly x86-64 gnu gnu-assembler
© www.soinside.com 2019 - 2024. All rights reserved.