https://sourceware.org/bugzilla/show_bug.cgi?id=27566
--- Comment #3 from lifang_...@c-sky.com --- Hi Nelson, I agree with you, the previous patch is not a best choice. I have do some debug today. I add a print here: =========================================== diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 364d67b..e774cff 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4247,14 +4247,23 @@ _bfd_riscv_relax_lui (bfd *abfd, max_alignment = (bfd_vma) 1 << sym_sec->output_section->alignment_power; } + printf ("gp: %lx, sym val: %lx\n", gp, symval); /* Is the reference in range of x0 or gp? Valid gp range conservatively because of alignment issue. */ if (undefined_weak || (VALID_ITYPE_IMM (symval) || (symval >= gp ============================================== And I got a result: ----------------------------------------------- xialf@magics:build-linux$ ./ld/ld-new -o a a.o -e main -z norelro gp: 11d90, sym val: 11c10 gp: 11d90, sym val: 11c10 xialf@magics:build-linux$ readelf -s a |grep global 5: 0000000000011d90 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$ ----------------------------------------------- >From this, GP is not changed, that means DATA_SEGMENT_ALIGN has been finished while relaxing.Therefore we can just consider about COMMON_PAGESIZE, not MAX_PAGESIZE+COMMON_PAGESIZE. ===================================================== For -z relro xialf@magics:build-linux$ ./ld/ld-new -o a a.o -e main -z relro gp: 12800, sym val: 11c10 gp: 12800, sym val: 11c10 gp: 11d90, sym val: 11c10 gp: 11d90, sym val: 11c10 xialf@magics:build-linux$ readelf -s a |grep global 5: 0000000000012800 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$ ======================================================= DATA_SEGMENT_RELRO_END has been aligned to 0x12000, and gp is 0x12800. ======================================================= common-page-size=0x4000 xialf@magics:build-linux$ ./ld/ld-new -o a a.o -e main -z common-page-size=0x4000 -z relro gp: 14800, sym val: 11c10 gp: 14800, sym val: 11c10 gp: 11d90, sym val: 11c10 gp: 11d90, sym val: 11c10 xialf@magics:build-linux$ readelf -s a |grep global 5: 0000000000014800 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$ ======================================================== DATA_SEGMENT_RELRO_END has been aligned to 0x14000, gp is 0x14800. It is not check the imm with (MAX_PAGESIZE + COMMON_PAGE_SIZE) or (COMMON_PAGESIZE); It need to align to COMMON_PAGE_SIZE. -- You are receiving this mail because: You are on the CC list for the bug.