My simple program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char argmore[]="Hello world";
int main ( int argc , char** argv) {
/////// printf
asm ("movq $1, %rax\n"
"movq $1, %rdi\n"
"movq $argmore, %rsi\n"
"movq $11, %rdx\n"
"syscall");
/////// exit
asm ("movq $60, %rax\n"
"movq $1, %rdi\n"
"syscall");
return 0;
}
When I compile this program as:
gcc -no-pie -o test test.c
It works correctly, prints "hello word" and exits successfully. But when I compile it as:
gcc -o test test.c
I receive this error:
/usr/bin/ld: /tmp/ccjSTY9T.o: relocation R_X86_64_32S against undefined symbol `argmore' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
I don't want to compile my program with -no-pie
option. What should I do? How can I change my program to compile correctly without -no-pie
option?