public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
@ 2021-08-17  7:47 ` pinskia at gcc dot gnu.org
  2021-08-17  7:47 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  7:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
  2021-08-17  7:47 ` [Bug c++/88061] section attributes of variable templates are ignored pinskia at gcc dot gnu.org
@ 2021-08-17  7:47 ` pinskia at gcc dot gnu.org
  2022-03-08 17:31 ` barry.revzin at gmail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  7:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |erstrauss at gmail dot com

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 97771 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
  2021-08-17  7:47 ` [Bug c++/88061] section attributes of variable templates are ignored pinskia at gcc dot gnu.org
  2021-08-17  7:47 ` pinskia at gcc dot gnu.org
@ 2022-03-08 17:31 ` barry.revzin at gmail dot com
  2023-04-06 16:32 ` barry.revzin at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: barry.revzin at gmail dot com @ 2022-03-08 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

Barry Revzin <barry.revzin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |barry.revzin at gmail dot com

--- Comment #5 from Barry Revzin <barry.revzin at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> Some things do not make very much sense for C++...

I disagree. This definitely makes sense for C++ and it is disappointing that it
doesn't work. 

For instance, this works:

[[gnu::used, gnu::section(".my_data")]] inline int data_int;
[[gnu::used, gnu::section(".my_data")]] inline double data_double;

int& get() {
    return data_int;
}

The C++ analogue, necessary for contexts where I may not be able to spell the
type in advance, would be this (or a static data member of a class template,
same thing):

template <typename T>
[[gnu::used, gnu::section(".my_data")]] inline T data{};

int& get() {
    return data<int>;
}

Except the latter puts data<int> into .bss.data<int>, while the former puts it
into .my_data. clang respects the section attribute
(https://godbolt.org/z/7137EbxsW), gcc does not
(https://godbolt.org/z/548YKjhzn).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-03-08 17:31 ` barry.revzin at gmail dot com
@ 2023-04-06 16:32 ` barry.revzin at gmail dot com
  2023-04-20  8:39 ` milan.svoboda at centrum dot cz
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: barry.revzin at gmail dot com @ 2023-04-06 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Barry Revzin <barry.revzin at gmail dot com> ---
Any action on this one?

A workaround right now is to change code that would ideally look like (which is
pretty clean in my opinion):

template <typename T>
void foo() {
    [[gnu::section(".meow")]] static int value = 0;
}

to code that looks like:

template <typename T>
void foo() {
    static int PUT_IN_MEOW_value = 0;
}

and add a linker script that moves these variables over:

.meow : {
KEEP(*(SORT(.*PUT_IN_MEOW_*)))
}

But this is, to put it mildly, less than ideal.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2023-04-06 16:32 ` barry.revzin at gmail dot com
@ 2023-04-20  8:39 ` milan.svoboda at centrum dot cz
  2023-04-20  9:59 ` milan.svoboda at centrum dot cz
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: milan.svoboda at centrum dot cz @ 2023-04-20  8:39 UTC (permalink / raw)
  To: gcc-bugs

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

Milan Svoboda <milan.svoboda at centrum dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |milan.svoboda at centrum dot cz

--- Comment #7 from Milan Svoboda <milan.svoboda at centrum dot cz> ---
template <typename T>
static void foo() {
    static int PUT_IN_MEOW_value = 0;
}


When the template function is static, this workaround with linker doesn't work.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2023-04-20  8:39 ` milan.svoboda at centrum dot cz
@ 2023-04-20  9:59 ` milan.svoboda at centrum dot cz
  2023-12-15 15:04 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: milan.svoboda at centrum dot cz @ 2023-04-20  9:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Milan Svoboda <milan.svoboda at centrum dot cz> ---
Well, additional workaround is to use -fdata-sections. Then the workaround with
the linker script works also for the templated static functions and for
functions (templated, static) in anonymous namespace (which is another
occurrence of this bug).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2023-04-20  9:59 ` milan.svoboda at centrum dot cz
@ 2023-12-15 15:04 ` cvs-commit at gcc dot gnu.org
  2023-12-16 17:17 ` ppalka at gcc dot gnu.org
  2023-12-16 17:58 ` ppalka at gcc dot gnu.org
  8 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-15 15:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:ea7bebff7cc5a5eb780a6ca646cb77cad1b625d6

commit r14-6595-gea7bebff7cc5a5eb780a6ca646cb77cad1b625d6
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Dec 15 10:03:31 2023 -0500

    c++: section attribute on templates [PR70435, PR88061]

    The section attribute currently has no effect on templates because the
    call to set_decl_section_name only happens at parse time (on the
    dependent decl) and not also at instantiation time.  This patch fixes
    this by propagating the section name from the template to the
    instantiation.

            PR c++/70435
            PR c++/88061

    gcc/cp/ChangeLog:

            * pt.cc (tsubst_function_decl): Propagate DECL_SECTION_NAME
            via set_decl_section_name.
            (tsubst_decl) <case VAR_DECL>: Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/attr-section1.C: New test.
            * g++.dg/ext/attr-section1a.C: New test.
            * g++.dg/ext/attr-section2.C: New test.
            * g++.dg/ext/attr-section2a.C: New test.
            * g++.dg/ext/attr-section2b.C: New test.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2023-12-15 15:04 ` cvs-commit at gcc dot gnu.org
@ 2023-12-16 17:17 ` ppalka at gcc dot gnu.org
  2023-12-16 17:58 ` ppalka at gcc dot gnu.org
  8 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-16 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
                 CC|                            |ppalka at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

--- Comment #10 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/88061] section attributes of variable templates are ignored
       [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2023-12-16 17:17 ` ppalka at gcc dot gnu.org
@ 2023-12-16 17:58 ` ppalka at gcc dot gnu.org
  8 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-16 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Patrick Palka <ppalka at gcc dot gnu.org> ---
N.B. that commit just naively fixes the attribute propagation issue which seems
to make at least simple examples work as expected.  The question of section +
comdat handling could IIUC be demonstrated using non-template inline
functions/variables as well and so is really an orthogonal issue I think?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-16 17:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-88061-4@http.gcc.gnu.org/bugzilla/>
2021-08-17  7:47 ` [Bug c++/88061] section attributes of variable templates are ignored pinskia at gcc dot gnu.org
2021-08-17  7:47 ` pinskia at gcc dot gnu.org
2022-03-08 17:31 ` barry.revzin at gmail dot com
2023-04-06 16:32 ` barry.revzin at gmail dot com
2023-04-20  8:39 ` milan.svoboda at centrum dot cz
2023-04-20  9:59 ` milan.svoboda at centrum dot cz
2023-12-15 15:04 ` cvs-commit at gcc dot gnu.org
2023-12-16 17:17 ` ppalka at gcc dot gnu.org
2023-12-16 17:58 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).