linux - 使用 scanf 的程序中的分段错误
问题描述
我的 VirtualBox 上的汇编程序有问题。
在 VB 上,我有 Linux Mint(64 位)。我试图编译这个汇编代码(在文件中my_file.asm
):
extern printf
extern scanf
section .data
format: db "%d",0
napis: db "a/b=%d",10,0
section .bss
a: resd 1
b: resd 1
global main
section .text
main:
mov rdi, format
mov rsi, a
xor rax, rax
call scanf
mov rdi, format
mov rsi, b
xor rax, rax
call scanf
mov eax, [a]
xor edx, edx
div dword[b]
ret
首先我输入:nasm -f elf64 myfile.asm
然后我输入: 然后我gcc myfile.o -o myfile
有这个错误消息:
“/usr/bin/ld: plik.o: relocation R_X86_64_32S against .bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld:最终链接失败:输出
collect2 上的不可表示部分:错误:ld 返回 1 退出状态“
所以我添加-no-pie
到 gcc 命令:gcc -o test test.o -no-pie
现在,当我使用./my_file
我有这个错误:Segmentation fault (core dumped)
而且我不知道该怎么做。
解决方案
推荐阅读
- node.js - 为什么我的项目在 6 个月不活动后会失败,即使它有一个 yarn.lock 文件?
- laravel - 我们如何在背包 Laravel Admin 中添加小部件
- tsql - 来自 T-SQL 的条件滞后
- python - 如何在 python 3.4.4 中一次将相同的转换逻辑应用于多个列
- linux - BASH - 是否可以检查命令的内存使用情况?
- java - 如果可能,将字符串拆分为 3 个块(文本 - 数字 - 其他字符)
- c# - 如何有效地复制列表中的特定值
- java - Spring Boot Maven 插件 - 测试失败
- python - SF30 控制器 Bluez 编程
- c# - Asp.net 核心无效 JSON