Код: Выделить всё
/usr/bin/ld: my_write.o: warning: relocation against `__errno_location@@GLIBC_2.2.5' in read-only section `.text'
/usr/bin/ld: my_write.o: relocation R_X86_64_PC32 against symbol `__errno_location@@GLIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
Если я компилирую с опцией -no-pie, он компилируется на этот раз, но это также противоречит правила
Есть идеи?
ниже я делюсь содержимым файлов и этапами компиляции;
my_write.s;
Код: Выделить всё
section .text
global my_write
extern __errno_location
my_write:
mov rax, 1
syscall
cmp rax, -1
je err
ret
err:
neg rax
mov rdi, rax
call __errno_location
mov [rax], rdi
mov rax, -1
ret
Код: Выделить всё
#include
#include
#include
#include
#include
#include
extern ssize_t my_write(int fd, const void *buf, size_t count);
int main(void)
{
char *str = "Hello";
my_write(1, str, 5);
}
1.
Код: Выделить всё
nasm -felf64 -o my_write.o my_write.s
Код: Выделить всё
gcc -o test main.c my_write.o
Код: Выделить всё
/usr/bin/ld: my_write.o: warning: relocation against `__errno_location@@GLIBC_2.2.5' in read-only section `.text'
/usr/bin/ld: my_write.o: relocation R_X86_64_PC32 against symbol `__errno_location@@GLIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
Подробнее здесь: https://stackoverflow.com/questions/791 ... urs-due-to
Мобильная версия