https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99978
Bug ID: 99978 Summary: attribute section rejected on an extern declaration in local scope Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC rejects a declaration of an extern variable with the section attribute in a local scope. The error it issues suggests it confuses the declaration with one of a automatic variable. Other Linux compilers (Clang and ICC) accept the code. $ cat a.c && gcc -S -Wall a.c extern __attribute__ ((section ("foo"))) int i_in_foo; int f (void) { extern __attribute__ ((section ("foo"))) int i_in_foo; return i_in_foo; } a.c: In function âfâ: a.c:5:48: error: section attribute cannot be specified for local variables 5 | extern __attribute__ ((section ("foo"))) int i_in_foo; | ^~~~~~~~