https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70146
Bug ID: 70146 Summary: missed-optimization: i386 hidden references should use PC32 relocations instead of GOTOFF Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: luto at kernel dot org Target Milestone: --- If I compile: extern char foo[] __attribute__((visibility("hidden"))); char *get_foo(void) { return foo; } with gcc -m32 -O2 -fPIC, I get (annocataions trimmed for brevity): get_foo: call __x86.get_pc_thunk.ax addl $_GLOBAL_OFFSET_TABLE_, %eax leal foo@GOTOFF(%eax), %eax ret I think this should generate: get_foo: call __x86.get_pc_thunk.ax .Lpcbase: leal foo-.Lpcbase(%eax), %eax ret That would be smaller, faster, and result in fewer relocations and thus less time spend linking.