Reputation: 99418
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!
Upvotes: 7
Views: 2562
Reputation: 363547
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).Upvotes: 3
Reputation: 45652
Exelent description about how does linux execute my main()? There you will find the answer and probably a lot more!
Upvotes: 2
Reputation: 283624
ld-linux.so
provides the magic that helps ldd
work.
libc.so
is part of the C runtime library. Among other things, the runtime library contains the actual entry point that calls main
.
main
is provided by your code.
return
is not a function, it's a keyword in the C language.
Upvotes: 1
Reputation: 798606
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.
Upvotes: 2
Reputation: 55392
linux-gate
is a virtual library that provides access to system functions. Its full name is the Linux Virtual Dynamic Shared Object. It's used by libc
.
libc
is the C run time. It's what actually calls main() for you. (It's possible to bypass this if you don't use any C functions.)
ld-linux
is the dynamic linker, which actually knows how to load and call the C run time for you.
main
lives in test.o, not in a library.
return
is a keyword, not a function. It directs the compiler to emit code to cause the function to return control to its caller.
Upvotes: 1