0

I have a simple assembly program like this:

$ cat hello.asm
          global    _start

          section   .text
_start:   mov       rax, 1                  ; system call for write
          mov       rdi, 1                  ; file handle 1 is stdout
          mov       rsi, message            ; address of string to output
          mov       rdx, 13                 ; number of bytes
          syscall                           ; invoke operating system to do the write
          mov       rax, 60                 ; system call for exit
          xor       rdi, rdi                ; exit code 0
          syscall                           ; invoke operating system to exit

          section   .data
message:  db        "Hello, World", 10      ; note the newline at the end

It can be built and execute correctly as:

$ nasm -f elf64 hello.asm && ld hello.o && ./a.out
Hello, World

But when I add "-pie" to "ld" command, it failed as:

$ nasm -f elf64 hello.asm && ld -pie hello.o && ./a.out
bash: ./a.out: No such file or directory

$ ls -al a.out
-rwxrwxr-x 1 louyang louyang 13816 Nov 29 13:14 a.out

Why?

L. Ouyang
  • 505
  • 6
  • 14
  • seems some useful information at https://stackoverflow.com/questions/55664494/how-to-create-a-statically-linked-position-independent-executable-elf-in-linux – L. Ouyang Nov 29 '20 at 11:42
  • 1
    The main problem is that the name of the dynamic linker is set incorrectly by default. I recommend linking through the C compiler if possible. – fuz Nov 29 '20 at 12:09

0 Answers0