[Bug c++/97771] gcc/g++ failed to generate proper .init_array entries for local scope function, should create "axG", .init_array comdat

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Aug 29 03:12:29 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97771

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Erez Strauss from comment #7)
> Hi Andrew,
> 
> Here is a very simple test program, under clang++ its output is 3, as
> expected.

Right I already mentioned this is a dup of still opened bug 88061 .  The
problem is clang might be emitting really really broken assembly and only can
be resolved at link time.

Take:
template<typename T>
void funcB() {
    static funcP init_func [[gnu::used, gnu::section(".init_array")]] {
[]()->void{++X;} };
}

----- CUT -----
funcB<int>::init_func has to be the same between TUs and that means emiting it
in the comdat section.  In fact the use of X here might actually cause this
code to be full on invalid anyways.


More information about the Gcc-bugs mailing list