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

            Bug ID: 116184
           Summary: section attributes in COMDAT groups use wrong group
                    name for multiple instances in same TU
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland at gnu dot org
  Target Milestone: ---

This might belong in a different component.  The test case here is in C++ but
the same thing probably arises with C(>=99) `extern inline` functions (and
static variables inside them) too.  It might be specific to ELF targets, but
might also manifest the same way on any non-ELF targets that support the
section attributes.  It doesn't seem to be specific to any particular subset of
ELF targets AFAICT.

Previously bug 94342 prevented `[[gnu::section("name")]]` (and other spellings)
in COMDAT group contexts (C `extern inline`, C++ `inline` and templates, etc.)
from honoring the named-section attribute.  That's now been fixed, but this
exposed a new bug.  Things work correctly when there is only one instance of an
entity in a named section in some COMDAT group in the TU.  But when there are
multiple entities in one TU, they all wind up in the same COMDAT group instead
of the proper group for each entity.

This is currently observed using commit
973097d801a30385cd39a570624eefa7547f8ff3 from the 14 branch.

```
template<char... C>                                                             
struct Chars {                                                                  
  static inline const char storage[] = {C..., '\0'};                            
  static inline const char* const string [[gnu::section("strings")]] {storage}; 
};                                                                              

const char* const* foo_string = &Chars<'f','o','o'>::string;                    
const char* const* bar_string = &Chars<'b','a','r'>::string;                    
```

Compiled with `g++ -std=c++17 -S` shows the issue straightforwardly:
```
...
        .section       
strings,"aG",@progbits,_ZN5CharsIJLc102ELc111ELc111EEE6stringE,comdat
        .align 8
        .type   _ZN5CharsIJLc102ELc111ELc111EEE6stringE, @object
        .size   _ZN5CharsIJLc102ELc111ELc111EEE6stringE, 8
_ZN5CharsIJLc102ELc111ELc111EEE6stringE:
...
        .section       
strings,"aG",@progbits,_ZN5CharsIJLc102ELc111ELc111EEE6stringE,comdat
        .align 8
        .type   _ZN5CharsIJLc98ELc97ELc114EEE6stringE, @object
        .size   _ZN5CharsIJLc98ELc97ELc114EEE6stringE, 8
_ZN5CharsIJLc98ELc97ELc114EEE6stringE:
...
```

Everything is right about both definitions, except that the group name in the
second `.section` directive matches the first symbol rather than the second.

Reply via email to