Suppose I have
-
an object file (
source.o) without functionmain. -
a shared object (
libmain.so) with functionmain.
How will the linker take care of the entry point when both are linked dynamically to create binary source.bin?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Whenever you have a dynamic linked program, there are several “entry points” involved. The first is in entry point of the dynamic linker itself, e.g.
/lib/ld-linux.so.2(on Linux/x86) or similar. The dynamic linker runs first, resolving all symbol names to their definitions (regardless of whether the definitions are in the main program or a library), then passes execution to the second entry point in the main program binary. This is notmainbut part of the “C runtime” (thuscrt.oand similar names) that takes care of some pre-mainstuff (like C++ ctors, setting up the pointer to the environment variables, and constructing the right arguments formain). This code ends with (the equivalent of)exit(main(argc, argv));which will use the relocated (by the dynamic linker) addresses of bothexitandmain.