http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59710
Bug ID: 59710 Summary: Nios2: Missing gprel optimization Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: sebastian.hu...@embedded-brains.de The compiler doesn't generate gprel load/store operations for variables external to the translation unit (this is unlike the PowerPC target for example). Consider the following test case: gprel-ok.c: int iii; int jjj = 456; void gprel_ok(void) { iii = 123; jjj = 789; } gprel-not-ok.c: extern int iii; extern int jjj; void gprel_not_ok(void) { iii = 123; jjj = 789; } nios2-elf-gcc -O2 -fno-common -S gprel-ok.c nios2-elf-gcc -O2 -fno-common -S gprel-not-ok.c gprel-ok.s: .file "gprel-ok.c" .section .text .align 2 .global gprel_ok .type gprel_ok, @function gprel_ok: movi r2, 123 stw r2, %gprel(iii)(gp) movi r2, 789 stw r2, %gprel(jjj)(gp) ret .size gprel_ok, .-gprel_ok .global jjj .section .sdata,"aws",@progbits .align 2 .type jjj, @object .size jjj, 4 jjj: .long 456 .global iii .section .sbss,"aws",@nobits .align 2 .type iii, @object .size iii, 4 iii: .zero 4 .ident "GCC: (GNU) 4.9.0 20140103 (experimental)" gprel-not-ok.s: .file "gprel-not-ok.c" .section .text .align 2 .global gprel_not_ok .type gprel_not_ok, @function gprel_not_ok: movi r3, 123 movhi r2, %hiadj(iii) addi r2, r2, %lo(iii) stw r3, 0(r2) movi r3, 789 movhi r2, %hiadj(jjj) addi r2, r2, %lo(jjj) stw r3, 0(r2) ret .size gprel_not_ok, .-gprel_not_ok .ident "GCC: (GNU) 4.9.0 20140103 (experimental)"