-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The executable file produced in the libso listing of chapter 5 does not work. #12
Comments
Thank you for this issue! This is indeed an error. The right sequence should be:
The If you compare $ # Without dynamic linker
$ ld -o main main.o -d libso.so $ ./main bash: no such file or directory: ./main
$ readelf -l main
Elf file type is EXEC (Executable file)
Entry point 0x400270
There are 5 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040
0x0000000000000118 0x0000000000000118 R E 8
INTERP 0x0000000000000158 0x0000000000400158 0x0000000000400158
0x000000000000000f 0x000000000000000f R 1
[Requesting program interpreter: /lib/ld64.so.1]
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x0000000000000288 0x0000000000000288 R E 200000
LOAD 0x0000000000000288 0x0000000000600288 0x0000000000600288
0x0000000000000130 0x0000000000000130 RW 200000
DYNAMIC 0x0000000000000288 0x0000000000600288 0x0000000000600288
0x0000000000000110 0x0000000000000110 RW 8
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .hash .dynsym .dynstr .rela.plt .plt .text
03 .dynamic .got.plt
04 .dynamic
$ # Now with dynamic linker
$ ld -o main main.o -d libso.so --dynamic-linker=/lib64/ld-linux-x86-64.so.2
$ ./main
Shared object
$ readelf -l main sayon@antheus
Elf file type is EXEC (Executable file)
Entry point 0x400280
There are 5 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040
0x0000000000000118 0x0000000000000118 R E 8
INTERP 0x0000000000000158 0x0000000000400158 0x0000000000400158
0x000000000000001c 0x000000000000001c R 1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x0000000000000298 0x0000000000000298 R E 200000
LOAD 0x0000000000000298 0x0000000000600298 0x0000000000600298
0x0000000000000130 0x0000000000000130 RW 200000
DYNAMIC 0x0000000000000298 0x0000000000600298 0x0000000000600298
0x0000000000000110 0x0000000000000110 RW 8
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .hash .dynsym .dynstr .rela.plt .plt .text
03 .dynamic .got.plt
04 .dynamic
Without
Most of us do not have a dynamic loader stored with such a name in
GCC resolves the loader path for you before calling linker internally. You will read more on that in Chapter 15 which is entirely dedicated to writing dynamic libraries in C and assembly. Again thank you and I am going to correct that in my next commit. |
Fixed in #13 |
Thanks for the solusion and explanation. The same correction needs to be done for the make files also. I'll create a pull request for that. |
Makefiles fixed in pull request #14. |
The executable file produced in the libso listing of chapter 5 does not work. The problem is reproduced below:
Executing
main
does not work:The problem seems to be with the last command. If we change it to using
gcc
instead ofld
, the execution works:gcc -nostdlib -o main main.o libso.so
It should be possible to fix this without using
gcc
instead ofld
, but I don't know how.The text was updated successfully, but these errors were encountered: