Моей системой является Ubuntu 18.04 64bit. с основами сборки и установленным devtools.
Привет, у меня есть файл блока по имени Hello.s, Вот, это довольно:
#This is a simple "Hello World!" program
.section .rodata #read only data section
str: .string "Hello World!\n"
########
.text #the beginnig of the code
.globl main #the label "main" is used to state the initial point of this program
.type main, @function # the label "main" representing the beginning of a function
main: # the main function:
pushq %rbp #save the old frame pointer
movq %rsp, %rbp #create the new frame pointer
movq $str,%rdi #the string is the only paramter passed to the printf function (remember- first parameter goes in %rdi).
movq $0,%rax
call printf #calling to printf AFTER we passed its parameters.
#return from printf:
movq $0, %rax #return value is zero (just like in c - we tell the OS that this program finished seccessfully)
movq %rbp, %rsp #restore the old stack pointer - release all used memory.
popq %rbp #restore old frame pointer (the caller function frame)
ret #return to caller function (OS)
При попытке скомпилировать его с помощью gcc-Hello.s возвращает следующее сообщение:
/usr/bin/ld: /tmp/ccY9hdWi.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: последняя ссылка перестала работать: непредставимый раздел по выводу collect2: ошибка: ld возвратил 1 статус выхода
Испытанный gcc-fPIC Hello.s, который не имеет никакого эффекта - приносит то же сообщение.
Некоторые люди сказали мне устанавливать gcc-4.8, хорошо который не работал
Установка предыдущей версии человечности была также предложена.. хорошо это - последнее средство, по-моему.
Какие-либо предложения?
Для любого заинтересованного. (Не таким образом тривиальный для новичков как я :)) Можно на самом деле выбрать между компиляторами! так:
gcc-4.8 Hello.s
ответ.