https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94342
Bug ID: 94342 Summary: GCC ignores attribute((section(...))) for static variables inside templates Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bikineev at google dot com Target Milestone: --- GCC ignores the section attribute for static variables declared inside templates: template <typename T> void Index(int i) { static int VAR __attribute__((used,section("NEW_SECTION"))) = i; } template void Index<int>(int); Objdump shows that the VAR symbol is still located in .bss (not NEW_SECTION): objdump -tC result.o ... 0000000000000000 u O .bss._ZZ5IndexIiEviE3VAR 0000000000000004 Index<int>(int)::VAR ... Tested on gcc-9.2.1. Clang's behaviour is as expected.