[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I aga
From: |
nelsonc1225 at sourceware dot org |
Subject: |
[Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol |
Date: |
Fri, 12 Mar 2021 13:42:14 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=27566
Nelson Chu <nelsonc1225 at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nelsonc1225 at sourceware dot
org
--- Comment #1 from Nelson Chu <nelsonc1225 at sourceware dot org> ---
Hi Lifang,
thanks for reporting this. I'm really curious how this happened, so I spend
some times to research how DATA_SEGMENT_ALIGN and DATA_SEGMENT_RELRO_END work
in the current GNU linker. Consider the binutils doc,
* DATA_SEGMENT_ALIGN(maxpagesize, commonpagesize) =
[maxpagesize == commonpagesize]
(ALIGN(maxpagesize) + (. & (maxpagesize - 1)))
[maxpagesize != commonpagesize]
(ALIGN(maxpagesize)
+ ((. + commonpagesize - 1) & (maxpagesize - commonpagesize)))
* DATA_SEGMENT_RELRO_END(offset, exp)
When ‘-z relro’ option is not present, DATA_SEGMENT_RELRO_END does nothing,
otherwise DATA_SEGMENT_ALIGN is padded so that exp + offset is aligned to the
commonpagesize argument given to DATA_SEGMENT_ALIGN.
I only consider the default linker script here. Besides, I do some minor
changes to your original example, to see how the DATA_*_ALIGN work.
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$ cat tmp.s
.option nopic
.section .rodata
.align 10
.globl hello_rodata
hello_rodata:
.zero 0x10
.section .init_array
.globl padding_init_array
padding_init_array:
.zero 0xfc
.text
.align 1
.globl main
main:
lui a5,%hi(hello_rodata)
addi a5,a5,%lo(hello_rodata)
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$
~/binutils-dev/build-linux64-upstream/build-install/bin/riscv64-unknown-linux-gnu-as
tmp.s -o tmp.o
Therefore, consider four cases as follows,
1. norelro, maxpagesize=0x1000, commonpagesize=0x1000
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$
~/binutils-dev/build-linux64-upstream/build-install/bin/riscv64-unknown-linux-gnu-ld
-z norelro -z max-page-size=0x1000 -z common-page-size=0x1000 tmp.o -M > map1
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$ cat map1
...
.rodata 0x0000000000010400 0x10
*(.rodata .rodata.* .gnu.linkonce.r.*)
.rodata 0x0000000000010400 0x10 tmp.o
0x0000000000010400 hello_rodata
...
0x0000000000011410 . = DATA_SEGMENT_ALIGN (CONSTANT
(MAXPAGESIZE), CONSTANT (COMMONPAGESIZE))
...
.init_array 0x0000000000011410 0xfc
...
0x000000000001150c . = DATA_SEGMENT_RELRO_END (., 0x0)
.data 0x000000000001150c 0x0
...
DATA_SEGMENT_ALIGN should be
(ALIGN(0x1000) + (0x10410 & (0x1000 - 1)))
= 0x11000 + (0x10410 & 0xfff)
= 0x11410
And DATA_SEGMENT_RELRO_END = 0x11410 + 0xfc = 0x1150c.
So we need to reserve at most "MAXPAGESIZE" size.
2. relro, maxpagesize=0x1000, commonpagesize=0x1000
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$
~/binutils-dev/build-linux64-upstream/build-install/bin/riscv64-unknown-linux-gnu-ld
-z relro -z max-page-size=0x1000 -z common-page-size=0x1000 tmp.o -M > map2
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$ cat map2
...
.rodata 0x0000000000010400 0x10
*(.rodata .rodata.* .gnu.linkonce.r.*)
.rodata 0x0000000000010400 0x10 tmp.o
0x0000000000010400 hello_rodata
...
0x0000000000011f04 . = DATA_SEGMENT_ALIGN (CONSTANT
(MAXPAGESIZE), CONSTANT (COMMONPAGESIZE))
...
.init_array 0x0000000000011f04 0xfc
...
0x0000000000012000 . = DATA_SEGMENT_RELRO_END (., 0x0)
...
This is same as above, but since "-z relro",
DATA_SEGMENT_RELRO_END = ALIGN(0x1150c, 0x1000) = 0x12000
DATA_SEGMENT_ALIGN = 0x12000 - 0xfc = 0x11f04
So we need to reserve at most "MAXPAGESIZE + COMMONPAGESIZE" size =
"2*MAXPAGESIZE".
3. norelro, maxpagesize=0x10000, commonpagesize=0x2000
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$
~/binutils-dev/build-linux64-upstream/build-install/bin/riscv64-unknown-linux-gnu-ld
-z norelro -z max-page-size=0x10000 -z common-page-size=0x2000 tmp.o -M > map3
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$ cat map3
...
.rodata 0x0000000000010400 0x10
*(.rodata .rodata.* .gnu.linkonce.r.*)
.rodata 0x0000000000010400 0x10 tmp.o
0x0000000000010400 hello_rodata
...
0x0000000000020410 . = DATA_SEGMENT_ALIGN (CONSTANT
(MAXPAGESIZE), CONSTANT (COMMONPAGESIZE))
...
.init_array 0x0000000000020410 0xfc
...
0x000000000002050c . = DATA_SEGMENT_RELRO_END (., 0x0)
...
DATA_SEGMENT_ALIGN =
(ALIGN(0x10000) + (0x10410 & (0x2000 - 1)))
= 0x20000 + (0x10410 & 0x1fff)
= 0x20410
DATA_SEGMENT_RELRO_END = 0x20410 + 0xfc = 0x2050c.
So we need to reserve at most "MAXPAGESIZE" size.
4. relro, maxpagesize=0x10000, commonpagesize=0x2000
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$
~/binutils-dev/build-linux64-upstream/build-install/bin/riscv64-unknown-linux-gnu-ld
-z relro -z max-page-size=0x10000 -z common-page-size=0x2000 tmp.o -M > map4
nelson@LAPTOP-QFSGI1F2:~/test/pr27566$ cat map4
...
.rodata 0x0000000000010400 0x10
*(.rodata .rodata.* .gnu.linkonce.r.*)
.rodata 0x0000000000010400 0x10 tmp.o
0x0000000000010400 hello_rodata
...
0x0000000000021f04 . = DATA_SEGMENT_ALIGN (CONSTANT
(MAXPAGESIZE), CONSTANT (COMMONPAGESIZE))
...
.init_array 0x0000000000021f04 0xfc
...
0x0000000000022000 . = DATA_SEGMENT_RELRO_END (., 0x0)
...
DATA_SEGMENT_RELRO_END = ALIGN(0x20410, 0x2000) = 0x22000
DATA_SEGMENT_ALIGN = 0x22000 - 0xfc = 0x21f04
So we need to reserve at most "MAXPAGESIZE + COMMONPAGESIZE" size.
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug ld/27566] New: [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol, address@hidden, 2021/03/11
- [Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol,
nelsonc1225 at sourceware dot org <=
- [Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol, nelsonc1225 at sourceware dot org, 2021/03/12
- [Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol, address@hidden, 2021/03/15
- [Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol, address@hidden, 2021/03/15
- [Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol, wilson at gcc dot gnu.org, 2021/03/17
- [Bug ld/27566] [RISC-V] relocation truncated to fit: R_RISCV_GPREL_I against aymbol, nelsonc1225 at sourceware dot org, 2021/03/26