Re: lto: from insert_attributes to file_end?

Richard Biener via Gcc <[email protected]>
Newsgroups gmane.comp.gcc.devel
Message-ID <CAFiYyc3r_NmLuJOOEJi69+EdSP0K1LcKoLLsVvA0ZE8DGxFE6Q@mail.gmail.com>
On Tue, May 5, 2026 at 8:16 PM Georg-Johann Lay <[email protected]> wrote:
>
> Am 05.05.26 um 19:05 schrieb Richard Biener:
> > On Tue, May 5, 2026 at 5:41 PM Georg-Johann Lay via Gcc <[email protected]> wrote:
> >>
> >> In the avr backend there is a static variable avr_no_call_main_p that
> >> is set in TARGET_INSERT_ATTRIBUTES and used in TARGET_ASM_FILE_END.
> >>
> >> This works as expected in non-LTO compilations, with LTO however,
> >> TARGET_INSERT_ATTRIBUTES runs in cc1[plus] but TARGET_ASM_FILE_END
> >> is run by lto1, hence the variable is not set as expected.
> >>
> >> What's the recommended way to handle such a situation?
> >
> > Without looking too closely I assume there's an actual attribute somewhere
> > (on the main function decl?).  Instead of using a global variable you'd
> > check for the presence of the attribute.  Now - the question is whether
> > the TARGET_ASM_FILE_END behavior is only required in the TU with
> > the main() definition?  In that case this should work.
>
> What works is to attach a new attribute to main when the conditions are
> right, then check for that attribute in, say,
> TARGET_DECLARE_FUNCTION_NAME and set a variable accordingly, and then
> check for that var in TARGET_ASM_FILE_END.

It's not technically required to be handled from TARGET_ASM_FILE_END,
correct?  It should work to emit the symbol from ASM_OUTPUT_FUNCTION_LABEL?
(not sure if there's sth more appropriate for 'before function' or
'after function')  You'd
at least have access to the functions decl there.

> What's a bit ugly is that it requires a new target attribute that's only
> for internal usage and should not to be set by the user.  Maybe not
> document it is okay then.

As Sam says, an attribute with a space cannot be used by users.  Like
"avr no_call_main".

But also see the PR iff the only way for the user to get the behavior
with -mno-call-main

>
> Is there some policy for such internal-use-only function attributes?
>
> Johann
>
> > I see you emit a special symbol conditional so what you can also do is
> > create that as a global variable in the symbol table and rely on the middle-end
> > to output it.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.