Skip to main content
added 104 characters in body
Source Link

The awesome ltrace tool traces both library calls and system calls, and is therefore perfect to examine what is going on in this case.

A closer analysis shows that open returns the file descriptor 3 (next free one after stdin, out and err).

read then uses that file descriptor, but TODO why mmap's arguments are limited to four, and we can't see which fd was used there since that is the 5th argumentTODO why mmap's arguments are limited to four, and we can't see which fd was used there since that is the 5th argument. strace confirms as expected that 3 is the one, and the order of the universe is restored.

The awesome ltrace tool traces both library calls and system calls, and is therefore perfect to examine what is going on in this case.

A closer analysis shows that open returns the file descriptor 3 (next free one after stdin, out and err).

read then uses that file descriptor, but TODO why mmap's arguments are limited to four, and we can't see which fd was used there since that is the 5th argument. strace confirms as expected that 3 is the one, and the order of the universe is restored.

The awesome ltrace tool traces both library calls and system calls, and is therefore perfect to examine what is going on in this case.

The awesome ltrace tool traces both library calls and system calls, and is therefore perfect to examine what is going on in this case.

A closer analysis shows that open returns the file descriptor 3 (next free one after stdin, out and err).

read then uses that file descriptor, but TODO why mmap's arguments are limited to four, and we can't see which fd was used there since that is the 5th argument. strace confirms as expected that 3 is the one, and the order of the universe is restored.

added 227 characters in body
Source Link
dlopen("libcirosantilli_ab.so", 1 <unfinished ...> SYS_open("./tls/x86_64/libcirosantilli_ab."..., 524288, 06267650550) = -2 SYS_open("./tls/libcirosantilli_ab.so", 524288, 06267650550)  = -2 SYS_open("./x86_64/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./libcirosantilli_ab.so", 524288, 06267650550)  = 3 SYS_read(3, "\177ELF\002\001\001", 832) = 832 SYS_brk(0) = 0x244c000 SYS_brk(0x246d000) = 0x246d000 SYS_fstat(3, 0x7fff42f9ce30) = 0 SYS_getcwd("/home/ciro/bak/git/cpp-cheat"..., 128) = 54 SYS_mmap(0, 0x201028, 5, 2050) = 0x7f1c323fe000 SYS_mprotect(0x7f1c323ff000, 2093056, 0) = 0 SYS_mmap(0x7f1c325fe000, 8192, 3, 2066) = 0x7f1c325fe000 SYS_close(3) = 0 SYS_mprotect(0x7f1c325fe000, 4096, 1) = 0 

so we see immediately that dlopen doescalls open + mmap.

A closer analysis shows that open returns the file descriptor 3 (next free one after stdin, out and err).

read then uses that file descriptor, but TODO why mmap's arguments are limited to four, and we can't see which fd was used there since that is the 5th argument. strace confirms as expected that 3 is the one, and the order of the universe is restored.

dlopen("libcirosantilli_ab.so", 1 <unfinished ...> SYS_open("./tls/x86_64/libcirosantilli_ab."..., 524288, 06267650550) = -2 SYS_open("./tls/libcirosantilli_ab.so", 524288, 06267650550)  = -2 SYS_open("./x86_64/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./libcirosantilli_ab.so", 524288, 06267650550)  = 3 SYS_read(3, "\177ELF\002\001\001", 832) = 832 SYS_brk(0) = 0x244c000 SYS_brk(0x246d000) = 0x246d000 SYS_fstat(3, 0x7fff42f9ce30) = 0 SYS_getcwd("/home/ciro/bak/git/cpp-cheat"..., 128) = 54 SYS_mmap(0, 0x201028, 5, 2050) = 0x7f1c323fe000 SYS_mprotect(0x7f1c323ff000, 2093056, 0) = 0 SYS_mmap(0x7f1c325fe000, 8192, 3, 2066) = 0x7f1c325fe000 SYS_close(3) = 0 SYS_mprotect(0x7f1c325fe000, 4096, 1) = 0 

so we see immediately that dlopen does open + mmap.

dlopen("libcirosantilli_ab.so", 1 <unfinished ...> SYS_open("./x86_64/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./libcirosantilli_ab.so", 524288, 06267650550) = 3 SYS_read(3, "\177ELF\002\001\001", 832) = 832 SYS_brk(0) = 0x244c000 SYS_brk(0x246d000) = 0x246d000 SYS_fstat(3, 0x7fff42f9ce30) = 0 SYS_getcwd("/home/ciro/bak/git/cpp-cheat"..., 128) = 54 SYS_mmap(0, 0x201028, 5, 2050) = 0x7f1c323fe000 SYS_mprotect(0x7f1c323ff000, 2093056, 0) = 0 SYS_mmap(0x7f1c325fe000, 8192, 3, 2066) = 0x7f1c325fe000 SYS_close(3) = 0 SYS_mprotect(0x7f1c325fe000, 4096, 1) = 0 

so we see immediately that dlopen calls open + mmap.

A closer analysis shows that open returns the file descriptor 3 (next free one after stdin, out and err).

read then uses that file descriptor, but TODO why mmap's arguments are limited to four, and we can't see which fd was used there since that is the 5th argument. strace confirms as expected that 3 is the one, and the order of the universe is restored.

use correct dlopen trace, previous missed LD_LIBRARY_PATH
Source Link
dlopen("libcirosantilli_ab.so", 1 <unfinished ...> SYS_open("/usr./localtls/libx86_64/libcirosantilli_a"libcirosantilli_ab."..., 524288, 02637336055006267650550) = -2  SYS_open("./tls/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./x86_64/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./libcirosantilli_ab.so", 524288, 06267650550) = 3 SYS_read(3, "\177ELF\002\001\001", 832) = 832 SYS_openSYS_brk("/etc/ld.so.cache",0) 524288, 01) = 3  = 0x244c000 SYS_brk(0x246d000) = 0x246d000 SYS_fstat(3, 0x7ffddaac0a000x7fff42f9ce30)  = 0  SYS_getcwd("/home/ciro/bak/git/cpp-cheat"..., 128) = 54 SYS_mmap(0, 0x201028, 5, 2050) = 0x7f1c323fe000 SYS_mmapSYS_mprotect(0, 0x2af830x7f1c323ff000, 12093056, 20)  = 0 SYS_mmap(0x7f1c325fe000, 8192, 3, 2066) = 0x7f0eb3eb1000 = 0x7f1c325fe000 SYS_close(3)  SYS_close(3)  = 0 SYS_mprotect(0x7f1c325fe000, 4096, 1) = 0    
dlopen("libcirosantilli_ab.so", 1 <unfinished ...> SYS_open("/usr/local/lib/libcirosantilli_a"..., 524288, 026373360550) = -2  SYS_open("/etc/ld.so.cache", 524288, 01) = 3 SYS_fstat(3, 0x7ffddaac0a00)  = 0  SYS_mmap(0, 0x2af83, 1, 2)  = 0x7f0eb3eb1000  SYS_close(3)  = 0  
dlopen("libcirosantilli_ab.so", 1 <unfinished ...> SYS_open("./tls/x86_64/libcirosantilli_ab."..., 524288, 06267650550) = -2 SYS_open("./tls/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./x86_64/libcirosantilli_ab.so", 524288, 06267650550) = -2 SYS_open("./libcirosantilli_ab.so", 524288, 06267650550) = 3 SYS_read(3, "\177ELF\002\001\001", 832) = 832 SYS_brk(0)   = 0x244c000 SYS_brk(0x246d000) = 0x246d000 SYS_fstat(3, 0x7fff42f9ce30) = 0 SYS_getcwd("/home/ciro/bak/git/cpp-cheat"..., 128) = 54 SYS_mmap(0, 0x201028, 5, 2050) = 0x7f1c323fe000 SYS_mprotect(0x7f1c323ff000, 2093056, 0) = 0 SYS_mmap(0x7f1c325fe000, 8192, 3, 2066) = 0x7f1c325fe000 SYS_close(3) = 0 SYS_mprotect(0x7f1c325fe000, 4096, 1) = 0   
added 4 characters in body
Source Link
Loading
Source Link
Loading