0

我的简单程序:

#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;
}

当我将此程序编译为:

gcc -no-pie -o test test.c

它工作正常,打印“hello word”并成功退出。但是当我将它编译为:

gcc -o test test.c

我收到此错误:

/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

我不想用-no-pie选项编译我的程序。我应该怎么办?如何在没有-no-pie选项的情况下更改我的程序以正确编译?

4

0 回答 0