编译失败

时间:2021-05-14 23:18:46

标签: linux gcc x86-64 nasm kali-linux

我尝试运行以下命令:

build.sh:

nasm -felf64 hello.asm && gcc hello.o && ./a.out

但由于某种原因它失败了,并产生以下错误,我不太确定为什么。我想知道有没有办法解决这个问题。

错误:

/usr/bin/ld: hello.o: warning: relocation in read-only section `.text'
/usr/bin/ld: hello.o: relocation R_X86_64_PC32 against symbol `puts@@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

hello.asm

      global    main
      extern    puts
      section   .text
main:                                       ; This is called by the C library startup code
          mov       rdi, message            ; First integer (or pointer) argument in rdi
          call      puts                    ; puts(message)
          ret                               ; Return from main back into C library wrapper
message:
          db        "Hello, World", 0

0 个答案:

没有答案