On 14/10/2010 16:24, Richard Guenther wrote:
> On Thu, Oct 14, 2010 at 5:28 PM, Dave Korn <[email protected]> wrote:
>> On 14/10/2010 15:44, Richard Guenther wrote:
>>> I have no idea about the linker-plugin side, but we could of course
>>> avoid generating any calls that were not there before (by for example
>>> streaming builtin decls and only if they are used). But that's as much
>>> a workaround as fixing things up in the linker afterwards ...
>> Sorry, I don't quite understand that suggestion! Do you mean we'd emit a
>> symbol for printf and that would result in an explicit printf which wouldn't
>> have the chance of being optimised to a puts at link-time?
>
> Yes.
I'd rather leave that as a real last resort!
>> If so I see how
>> it'd work, but it would be a shame to lose optimisation in LTO. Or to
>> include
>> unnecessary library members. I *think* that re-adding the stdlibs after all
>> the new input files in the plugin might work, but haven't tried it yet.
>>
>> I have the same problem with '__main', BTW. Is that supposed to count as a
>> builtin, or do we need to do something in expand_main_function() to make LTO
>> aware when it calls __main?
>
> Hm, I don't know - I suppose that's from the crt*.o stuff?
Typically it's from libgcc:
" If no init section is available, when GCC compiles any function called
`main' (or more accurately, any function designated as a program entry
point by the language front end calling `expand_main_function'), it
inserts a procedure call to `__main' as the first executable code after
the function prologue. The `__main' function is defined in `libgcc2.c'
and runs the global constructors."
On cygwin, it's supplied by libc. On other systems I don't know, maybe it
can be in the crt.o files, but in that case there wouldn't be any problem with
it getting pulled into the link, it's only a problem when it's a library
archive member.
> The main function itself should already appear in the symbols.
It does, but there's no reference to __main. I was wondering if that was
supposed to happen, and looking at expand_main_function I guess so, because
it's calling "emit_library_call (init_one_libfunc (...))", but this is one
libfunc that we know can't be optimised away at linktime, so it would probably
be OK to stream it. (But there's a lot I don't know about LTO, so I could
always be wrong there.)
cheers,
DaveK