如何才能把这个简单的汇编程序编译通过并成功运行

durant durant 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
WSL Ubuntu18.04
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

.section .rodata
msg:
.ascii "Hello, world.\n"

.section .text
.globl main
main:
movl $4, %eax
movl $1, %ebx
movl $msg, %ecx
movl $14, %edx
int $0x80

movl $1, %eax
movl $0, %ebx
int $0x80

1. 不加任何选项,是这样的

$ gcc hello.s
/usr/bin/ld: /tmp/ccjICv40.o: relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status


2. 加-no-pie选项后是这样的

gcc -no-pie hello.s
wj@wj:~/study/asm$ ./a.out
Segmentation fault (core dumped)


可这明明是个简单的程序,不会有段错误的啊

我向学写汇编,怎么就这么难啊
...全文
评论 1
收藏 已收藏
分享
返回顶部
durant
汇编语言 21,500 成员 41,619 内容