On Mar 15, 2012, at 10:37 AM, Richard Guenther wrote:
> On Wed, 14 Mar 2012, Tristan Gingold wrote:
>
>>
>> On Mar 14, 2012, at 5:08 PM, Richard Guenther wrote:
>>
>>> On Wed, 14 Mar 2012, Tristan Gingold wrote:
>>>
>>>> Hi,
>>>>
>>>> the code to call expand_main_function currently only checks DECL_NAME.
>>>> This leads
>>>> to a hack in ada/gcc-interface/utils.c to handle the gnatbind generated
>>>> file that could
>>>> declare:
>>>>
>>>> package ada_main is
>>>> …
>>>> function my_main
>>>> (argc : Integer;
>>>> argv : System.Address;
>>>> envp : System.Address)
>>>> return Integer;
>>>> pragma Export (C, my_main, "main");
>>>> …
>>>> end ada_main;
>>>>
>>>> But expand_main_function is also called for function whose name is main
>>>> but assembly name isn't. Eg:
>>>>
>>>> package pkg is
>>>> procedure main;
>>>> end pkg;
>>>>
>>>> So I think we should consider the assembler name is set, otherwise the
>>>> decl name.
>>>>
>>>> Manually tested on ia64-hp-openvms (where this issue was discovered).
>>>> No C regressions for x86_64-darwin.
>>>>
>>>> Ok for trunk ?
>>>
>>> There are more checks for MAIN_NAME_P, so this certainly isn't enough.
>>> And if it is a good idea then the whole check, whether a FUNCTION_DECL
>>> is considered 'main' should be put into a function in tree.[ch] and
>>> used everywhere. Note that what is 'main' is controlled by
>>> main_identifier_node, controlled by frontends. So - why is that not
>>> enough to control for Ada?
>>
>> Indeed, I think we could handle this issue in gigi for Ada. (I also think
>> we don't want to handle crazy C code such as 'int my_main () asm ("main")'.
>>
>> But, unless I missed something, doing this in gigi won't work with LTO.
>
> Well. To make this work in LTO the "main" function (thus, the program
> entry point) should be marked at cgraph level and all users of
> MAIN_NAME_P should instead check a flag on the cgraph node.
>
>> Will write a predicate in tree.[ch].
>
> Please instead transition "main-ness" to the graph.
Ok, I will explore this way.
Tristan.