[llvm-dev] Finding the entry point function in a LLVM IR

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 25 01:37:16 PDT 2017


On 25 Oct 2017, at 05:34, mohie pokhriyal <mohie10 at gmail.com> wrote:
> 
> Thank You David and Mats for the reply, 
> 
> The reason I need to know that main is the entry point is as follows :
> 
> I have a dead code elimination pass that removes the function call for boo. boo was initially called from the main function , but since the return in the main function has no dependency on boo, boo function call is removed. 

This is not sound.  The linkage of boo means that it is externally visible.  There is no guarantee that it will not be called from another compilation unit.  If boo had internal or private linkage, then you would be safe to delete it as soon as its uses count dropped to zero (and LLVM’s dead code elimination pass will do exactly that).

If you run the Internalize pass first, then it will mark functions that are not reachable from main as internal and then DCE can delete them.

David



More information about the llvm-dev mailing list