If a variable is declared as extern non-array
in one module and then defined as an array in another, a linker error
may occur:
Definition: foo.c:uint64_t variable[SIZE];
Reference: bar.c:extern uint64_t variable;
ld: The value 0xXXX does not fit when applying the relocation GPREL22 for
symbol "variable" at offset 0xYYY in section index ZZZ of file bar.o. |
Workaround: The declaration should be changed
to:
extern uint64_t variable[]; |
This error can also occur in assembly code if
items <= 8 bytes are put into.data/.bss instead
of .sdata/.sbss.
Workaround (assembler): For "small" variables
defined in assembly, change the section name from .bss to .sbss or .data to .sdata:
.section .sdata = "asw", "progbits"
.align 8
gggggggg:: data4 0x000003e7 |