I've parsed a bitcode file with llvm::parseBitcodeFile
and I've got the llvm::Module
, I can iterate over the functions of the module:
std::unique_ptr<llvm::Module>& M = *parsed;
for(auto& func : M->functions())
{
// how to identify the entry point?
}
And I would like to identify the entry point of the module (and thus of the application - if there are multiple modules, one of them should have an entry point..) , but I wasn't able to find anything in func
to do that, what would be the proper way to identify the entry point? (In most cases it will be the main
function, so looking for the name seems to work, but not always).
More generically, I'm looking for a way to find the entry point (if any - perhaps main
) of a/many bitcode file that I'm given..
CodePudding user response:
There is no "entry point" in a LLVM Module. Entry point is a feature of an application and could be very different depending on e.g. source language, etc. Also, since LLVM Module represents somehow a translation unit there might be no "main function at all.
If you happen to know the name of the function you're looking for, then you can certainly use Module::getFunction
call to perform name-based lookup.