https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103291
Bug ID: 103291 Summary: gcc 11 regression with #pragma GCC visibility vs extern inside C++ functions Product: gcc Version: 11.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: --- GCC 11 has a regression with: ``` #pragma GCC visibility push(hidden) int hidden_fetch(void) { extern const int hidden_global; return hidden_global; } ``` when compiled with -fpic. GCC 10 would always avoid the GOT for this case. GCC 11 avoids the GOT when it's compiled as C, but uses the GOT when it's compiled as C++. Moving the extern decl outside the function makes it dtrt again in C++ as well. Reproduced on trunk at 4cdf7db9a39d18bd536d816a5751d4d3cf23808b and on 11 branch at b52e2254b30445f3cd667ae0f0d99b183394e37b.