Search Posts

a super skill to help you understand .init and .fini

a super skill to help you understand .init and .fini, just do “LD_DEBUG=libs ./a.out”, read detail http://www.bnikolic.co.uk/blog/linux-ld-debug.html

One thing need to remind you, loader pass control to a.out *BEFORE* it calls the fini.

/root>LD_DEBUG=libs ./a.out
      8044:	find library=libstdc++.so.6 [0]; searching
      8044:	 search cache=/etc/ld.so.cache
      8044:	  trying file=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
      8044:	
      8044:	find library=libgcc_s.so.1 [0]; searching
      8044:	 search cache=/etc/ld.so.cache
      8044:	  trying file=/lib/x86_64-linux-gnu/libgcc_s.so.1
      8044:	
      8044:	find library=libc.so.6 [0]; searching
      8044:	 search cache=/etc/ld.so.cache
      8044:	  trying file=/lib/x86_64-linux-gnu/libc.so.6
      8044:	
      8044:	find library=libm.so.6 [0]; searching
      8044:	 search cache=/etc/ld.so.cache
      8044:	  trying file=/lib/x86_64-linux-gnu/libm.so.6
      8044:	
      8044:	
      8044:	calling init: /lib/x86_64-linux-gnu/libc.so.6
      8044:	
      8044:	
      8044:	calling init: /lib/x86_64-linux-gnu/libm.so.6
      8044:	
      8044:	
      8044:	calling init: /lib/x86_64-linux-gnu/libgcc_s.so.1
      8044:	
      8044:	
      8044:	calling init: /usr/lib/x86_64-linux-gnu/libstdc++.so.6
      8044:	
      8044:	
      8044:	initialize program: ./a.out
      8044:	
      8044:	
      8044:	transferring control: ./a.out
      8044:	
4660
      8044:	
      8044:	calling fini: ./a.out [0]
      8044:	
      8044:	
      8044:	calling fini: /usr/lib/x86_64-linux-gnu/libstdc++.so.6 [0]
      8044:	
      8044:	
      8044:	calling fini: /lib/x86_64-linux-gnu/libgcc_s.so.1 [0]
      8044:	
      8044:	
      8044:	calling fini: /lib/x86_64-linux-gnu/libm.so.6 [0]
      8044:	

Leave a Reply

Your email address will not be published. Required fields are marked *