linux c asm编译错误,使用C程序编译ASM文件的命令

我正在尝试将我的ASM(hello.asm)文件与C文件(main.c)链接并编译为执行文件.

我创建了一个ASM文件,通过printHello函数使用printf打印“Hello”.

extern printf, exit

section .data

format db "Hello", 10, 0

section .text

global printHello

printHello:

sub rsp, 8

mov rsi, 0x12345677

mov rdi, format

xor rax, rax

call printf

mov rdi, 0

call exit

我创建一个简单的main.c并调用我的函数“printHello”来打印“Hello”

#include

void printHello();

int main()

{

printHello();

}

我的编译命令:

$nasm -f elf64 hello.asm

$gcc -c main.c

$gcc -o executable main.o hello.o

$./executable

它打印:

./executable: Symbol `printf' causes overflow in R_X86_64_PC32 relocation

./executable: Symbol `exit' causes overflow in R_X86_64_PC32 relocation

[1] 6011 segmentation fault ./executable

我已经在学习ASM了.问题来自我的命令还是我的代码?

解决方法:

我使用您的@Jester解决方案解决了这个问题:

gcc -no-pie -o executable main.o hello.o

并感谢Ped7g的解释.

标签:c-3,linux,assembly,x86-64

来源: https://codeday.me/bug/20190701/1347580.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值