I am currently compiling a bought data stack in C. I use their own tool to compile it, using in the background gcc. I can pass flags and parameters to gcc as I see fit. I want to know, from which file is the main() used. That is, in the project, which file is the starting point. Is there any way to tell gcc to generate a list of files, or similar, given that I dont know from which file is main() being taken? Thank you.
Share
You can disassemble the final executable to find the starting point. Although you have not provided any additional info to help you more. I’m using a sample code to demonstrate the process.
Now the object
main.ohas the following thisYou can see main is not initialized. Because it will changed in linking stage. Now after linking :
You see that main has a address now. But its still not final. Because this main will called by C runtime dynamically. you can see who will do the part of
U __libc_start_main@@GLIBC_2.2.5:Now you can verify this by viewing the disassembly :
If you don’t have the source with you, then you can search in the executable for references to
libc_start_mainormainorstartto see how your executable is initialized and starts themain.Now all of these is done when linking is done with default linker script. Many big project will use its own linker script. If your project has custom linker script, then finding the start point will be different depending on the linker script used. There are projects which does not uses
glibc'sruntime. In that case, its still possible to find the start point by hacking the object files, library archives etc.If your binary is
strippedfrom symbols, then you have to actually rely on your assembler skill to find where it starts.I’ve assumed that you don’t have the source, that is the stack is distributed with some libraries and some header definitions only.(A common practice of commercial software vendors).
But if you have source with you, then its just too trivial. just
grepyour way through it. Some answers already pointed that out.