汇编程序的 gcc 链接错误
gcc linking error for assembly program
我正在尝试执行计算二次方程根的汇编程序。
nasm -f elf64 assgn10.asm
gcc -o assgn10 assgn10.o
/usr/bin/ld: assgn10.o: relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
我用了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 上可以正常运行。
The same program worked without fuss on a different pc.
您的 gcc
默认配置为生成 position-independent executables (configure --enable-default-pie ...
),您的程序集与此不兼容。
这应该有效:
gcc -o assgn10 assgn10.o -no-pie
我正在尝试执行计算二次方程根的汇编程序。
nasm -f elf64 assgn10.asm
gcc -o assgn10 assgn10.o
/usr/bin/ld: assgn10.o: relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
我用了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 上可以正常运行。
The same program worked without fuss on a different pc.
您的 gcc
默认配置为生成 position-independent executables (configure --enable-default-pie ...
),您的程序集与此不兼容。
这应该有效:
gcc -o assgn10 assgn10.o -no-pie