【问题标题】:gcc linking error for assembly program汇编程序的 gcc 链接错误
【发布时间】:2018-04-14 06:35:32
【问题描述】:

我正在尝试执行一个计算二次方程根的汇编程序。

nasm -f elf64 assgn10.asm
gcc -o assgn10 assgn10.o

/usr/bin/ld: assgn10.o: relocation R_X86_64_32S 对`.bss' 制作共享对象时不能使用;用 -fPIC 重新编译

/usr/bin/ld: 最终链接失败:输出中不可表示的部分

collect2: 错误:ld 返回 1 个退出状态

我使用了 2 个宏。

%macro myprintf 1
mov rdi,formatpf
sub rsp,8
movsd xmm0,[%1]
mov rax,1
call printf
add rsp,8
syscall
%endmacro

%macro myscanf 1
mov rdi,formatsf
mov rax,0
mov rsi,qword[%1]
call scanf
;syscall
%endmacro

这就是我的 .bss 部分的外观。

section .bss

a resq 1
b resq 1
c resq 1
b2 resq 1 ; b square
fac resq 1 ; 4ac
delta resq 1 ; delta value
rdelta resq 1 ; root of delta
r1 resq 1 ;root 1
r2 resq 1 ;root 2
ta resq 1  ; 2a
realn resq 1
img1 resq 1
img2 resq 1

同样的程序在不同的 PC 上运行起来毫不费力。

【问题讨论】:

标签: gcc assembly linker nasm x86-64


【解决方案1】:

同样的程序在另一台电脑上运行起来毫不费力。

您的gcc 配置为默认生成position-independent executables (configure --enable-default-pie ...),而您的程序集与此不兼容。

这应该可行:

gcc -o assgn10 assgn10.o -no-pie

【讨论】:

    猜你喜欢
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多