Linux – /sbin/init is shared object

initlinux

I know 'init' is first process that is started after the kernel is loaded, but there is an ambiguity for me. If it is a process it must have a binary executable file. However, the following shared object is compiled code that looks like an executable file, but there is no main function.

sardari@mint / $ file /sbin/init
/sbin/init: ELF 64-bit LSB  shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7a4c688d009fc1f06ffc692f5f42ab09e68582b2, stripped

Apparently a shared object can be an executable file, but why?

Best Answer

When a file compiled with -pie (Position Independent Executable) such as :

gcc -pie -fPIC hello.c

Then you have :

#file ./a.out 
a.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x2afb7892000a1dc5b9010c591b75987188aa2d66, stripped

If you need more information , You can visit Position-independent code

Related Question