Key difference in the out of ld -pie and ld without -pie?
Tadeus Prastowo
tadeus.prastowo@unitn.it
Fri Apr 23 16:55:49 GMT 2021
On Fri, Apr 23, 2021 at 3:03 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> On 4/23/21, Tadeus Prastowo <tadeus.prastowo@unitn.it> wrote:
> > I simplified your hello.s and did:
> > $ cat hello.s
> > .text
> > .global main
> > main:
> > lea s(%rip), %rdi
> > xor %rax, %rax
> > ret
> > .section .rodata
> > s:
> > .string "Hello World!"
> > $ as -c -o hello.o hello.s
> > $ ld -pie hello.o
> > ld: warning: cannot find entry symbol _start; defaulting to
> > 0000000000000221
> >
> > It's just a warning. I obtained the a.out executable. Now you can
> > try this on your own and perform further experiments.
>
> It doesn't run. The output should be able to run.
>
> $ ./a.out
> -bash: ./a.out: No such file or directory
Modifying hello.s to use some of your earlier code...
$ cat hello.s
.global _start
.text
_start:
lea s(%rip), %rdi
xor %rax, %rax
# exit(0)
mov $60, %rax # system call 60 is exit
xor %rdi, %rdi # we want return code 0
syscall # invoke operating system to exit
.section .rodata
s:
.string "Hello World!"
$ as -c -o hello.o hello.s
$ ld -pie -o hello hello.o
$ ./hello
bash: ./hello: No such file or directory
$ readelf -e hello | grep interpreter
[Requesting program interpreter: /lib/ld64.so.1]
$ ls /lib/ld64.so.1
ls: cannot access '/lib/ld64.so.1': No such file or directory
$ ld --dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o hello hello.o
$ readelf -e hello | grep interpreter
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
$ ls /lib64/ld-linux-x86-64.so.2
/lib64/ld-linux-x86-64.so.2
$ ./hello; echo $?
0
> --
> Regards,
> Peng
--
Best regards,
Tadeus
More information about the Binutils
mailing list