My code is in test.c:
int main(){
return 0;
}
The dynamically shared libraries the executable compiled from it depends on are:
$ gcc -o test test.c
$ ldd test
linux-gate.so.1 => (0x00783000)
libc.so.6 => /lib/libc.so.6 (0x00935000)
/lib/ld-linux.so.2 (0x00ea5000)
main belong to? /lib/libc.so.6?return belong to? /lib/libc.so.6?Thanks!
linux-gate.so isn't really a shared lib, but a part of the kernel that acts like one and makes fast system calls possible. ld-linux.so is a piece of code that makes loading other shared libraries possible. libc.so is the C library, containing standard functions like printf and strcpy.main doesn't belong to any library. It belongs to your program, in the sense that its assembled version is stored entirely in the test binary file.return is not a function but a C language construct.libgcc, which is apparently not a shared library on your system (or it would show up) and some startup code. g++ would additionally link in libstdc++.so (the C++ standard library) and libm.so (the math part of the C standard library).linux-gate is a virtual shared object that acts as a connection to system calls within the kernel. libc is glibc, which provides functions such as printf() and so on. ld-linux is the glibc loader, which allows loading of other shared objects.
main() belongs to your code. It is called by crt1.o which is linked into the executable by gcc (well, ld specifically).
return is not a function but rather a language construct, so gcc turns it directly into code contained within the object (and eventually executable) file. As an aside, the value returned from main() is caught by crt1.o and turned into a program result code.
Exelent description about how does linux execute my main()? There you will find the answer and probably a lot more!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With