https://sourceware.org/bugzilla/show_bug.cgi?id=32377
Bug ID: 32377 Summary: [RISCV]Variables within the range of gp ± 2KB have not been indexed Product: binutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: mumuxi_ll at outlook dot com Target Milestone: --- Hi all, Here is the test case and ld file: test.c: ================ int i = 1; int main(){ return i; } ================ gp_reloc.ld: ================ MEMORY { ROM : ORIGIN = 0x000030000 LENGTH = 0x10000 } SECTIONS{ .text : { *(.text) *(.rodata *.rodata.*) } >ROM .data : { *(.data) PROVIDE( __global_pointer$ = . + 0x400 ); *(.sdata .sdata.* .sdata*) *(.gnu.linkonce.s.*) /* readonly data placed in RAM for access speed */ . = ALIGN(8); *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) *(.sbss*) } >ROM PROVIDE( __bss_start = . ); .bss (NOLOAD) : ALIGN(8) { *(.sbss*) *(.gnu.linkonce.sb.*) *(.bss .bss.*) *(.gnu.linkonce.b.*) *(COMMON) . = ALIGN(4); } >ROM PROVIDE( _end = . ); } ================ Perform simple compilation and linking using the following command: $riscv64-unknown-elf-gcc -march=rv32imac -mabi=ilp32 -c test.c -o test.o $riscv64-unknown-elf-gcc -march=rv32imac -mabi=ilp32 -o test test.o -T gp_reloc.ld -Wl,-Map=test.map $riscv64-unknown-elf-objdump -d test> test.dasm The disassembly of the main function is as follows, and it can be seen that the variable i is indexed through the GP register ================ 00030082 <main>: 30082: 1141 addi sp,sp,-16 30084: c606 sw ra,12(sp) 30086: c422 sw s0,8(sp) 30088: 0800 addi s0,sp,16 3008a: c041a783 lw a5,-1020(gp) # 31728 <i> 3008e: 853e mv a0,a5 30090: 40b2 lw ra,12(sp) 30092: 4422 lw s0,8(sp) 30094: 0141 addi sp,sp,16 30096: 8082 ret ================ When I change the value of `__globalis_pointer` to . + 0x800, the corresponding disassembly is as follows: ================ 0003008a <main>: 3008a: 1141 addi sp,sp,-16 3008c: c606 sw ra,12(sp) 3008e: c422 sw s0,8(sp) 30090: 0800 addi s0,sp,16 30092: 000317b7 lui a5,0x31 30096: 7507a783 lw a5,1872(a5) # 31750 <i> 3009a: 853e mv a0,a5 3009c: 40b2 lw ra,12(sp) 3009e: 4422 lw s0,8(sp) 300a0: 0141 addi sp,sp,16 300a2: 8082 ret ================ At this point, it becomes indexing the variable i through the `lui+lw`, however, upon reviewing the map file, it is clear that i falls within the range of gp ± 2KB ================ 0x00031f4c PROVIDE (__global_pointer$ = (. + 0x800)) *(.sdata .sdata.* .sdata*) .sdata 0x0003174c 0x4 ...... 0x0003174c ......... .sdata 0x00031750 0x4 test.o 0x00031750 i ================ So I want to know if this is a bug in ld or if there are additional restrictions on gp. -- You are receiving this mail because: You are on the CC list for the bug.