[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 --- Comment #11 from Patrick Palka --- 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?
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Patrick Palka 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 --- Fixed for GCC 14
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 --- Comment #9 from GCC Commits --- The master branch has been updated by Patrick Palka : https://gcc.gnu.org/g:ea7bebff7cc5a5eb780a6ca646cb77cad1b625d6 commit r14-6595-gea7bebff7cc5a5eb780a6ca646cb77cad1b625d6 Author: Patrick Palka 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) : 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.
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 --- Comment #8 from Milan Svoboda --- 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).
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Milan Svoboda changed: What|Removed |Added CC||milan.svoboda at centrum dot cz --- Comment #7 from Milan Svoboda --- template static void foo() { static int PUT_IN_MEOW_value = 0; } When the template function is static, this workaround with linker doesn't work.
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 --- Comment #6 from Barry Revzin --- 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 void foo() { [[gnu::section(".meow")]] static int value = 0; } to code that looks like: template 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.
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Barry Revzin changed: What|Removed |Added CC||barry.revzin at gmail dot com --- Comment #5 from Barry Revzin --- (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 [[gnu::used, gnu::section(".my_data")]] inline T data{}; int& get() { return data; } Except the latter puts data into .bss.data, 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).
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Andrew Pinski changed: What|Removed |Added CC||erstrauss at gmail dot com --- Comment #4 from Andrew Pinski --- *** Bug 97771 has been marked as a duplicate of this bug. ***
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Andrew Pinski changed: What|Removed |Added Status|WAITING |NEW
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Strager Neds changed: What|Removed |Added CC||strager.nds at gmail dot com --- Comment #3 from Strager Neds --- I also encountered this bug. I started fixing this bug (and PR 70435): https://gcc.gnu.org/ml/gcc-patches/2019-11/msg00348.html
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Felix Jones changed: What|Removed |Added CC||fewix3000 at hotmail dot co.uk --- Comment #2 from Felix Jones --- Related bug 70435 Here's a demonstration of the issue with GCC trunk x86-64 on godbolt: https://godbolt.org/z/9GFWZR Minimal example for reproducing: > template > __attribute__( ( used, section( ".my_section" ) ) ) const int s_value { x }; > > int main( int argc, char * argv[] ) { >return s_value<3>; > } Current behaviour: s_value within section .rodata Desired behaviour: s_value within section .my_section Clang trunk demonstrates the desired behaviour: https://godbolt.org/z/t8FNe0
[Bug c++/88061] section attributes of variable templates are ignored
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061 Richard Biener changed: What|Removed |Added Status|UNCONFIRMED |WAITING Last reconfirmed||2018-11-19 Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- I'm not sure such request can be honored given the section has to be comdat which essentially means it has to have it's own section for each different instantiation. Thus, would we reject template [[gnu::section(".my_data")]] const unsigned g_my_data {x}; template const unsigned g_my_data<0xf0f0f0f0>; template const unsigned g_my_data<0xf0f0f0f1>; as invalid with an error? Or somehow take .my_data as prefix and mangle it appropriately, assigning it COMDAT? Some things do not make very much sense for C++...