binutils-gdb/ld/emultempl
Nelson Chu ef9d256562 RISC-V: PR27566, Do not relax when data segment phase is exp_seg_relro_adjust.
2021-05-31  Nelson Chu  <nelson.chu@sifive.com>
            Lifang Xia  <lifang_xia@c-sky.com>

The data segment phase exp_seg_relro_adjust means we are still adjusting the
relro segments, so we will get the symbol values which havn't consider the
relro.  It is dangerous and we shouldn't do the relaxations at this stage.
Otherwise, we may get the truncated fails when the relax range crossing the
data segment.

One of the solution is that, we use a pointer to monitor the data segment
phase while relaxing, to know whether the relro has been handled or not.
Once we check the phase is exp_seg_relro_adjust, we should skip this round
of relaxations, since the incorrect symbol values will affect the correctness
of relaxations.  I think we probably need to record more information about
data segment or alignments in the future, to make sure it is safe to doing
relaxations.

For the two new testcases, relro-relax-lui and relro-relax-pcrel, we get
the following truncated errors when using toolchains, which enable relro:

(.text+0x0): relocation truncated to fit: R_RISCV_GPREL_I against symbol `SymbolRodata' defined in .rodata section in test1.o

After applying this patch, the truncated errors should be resolved.
However, only linux toolchains support -z relro, so we only test these
two testcases when supporting shared library.

bfd/
    PR 27566
    * elfnn-riscv.c (struct riscv_elf_link_hash_table): New integer pointer
    to monitor the data segment phase.
    (bfd_elfNN_riscv_set_data_segment_info): New function called by
    after_allocation, to set the data_segment_phase from expld.dataseg.
    (_bfd_riscv_relax_section): Don't relax when data_segment_phase is
    exp_seg_relro_adjust (0x4).
    * elfxx-riscv.h (bfd_elf32_riscv_set_data_segment_info): New extern.
    (bfd_elf64_riscv_set_data_segment_info): Likewise.
ld/
    PR 27566
    * emultempl/riscvelf.em (after_allocation): Call
    riscv_set_data_segment_info to set data segment phase before relaxing.
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * testsuite/ld-riscv-elf/relro-relax-lui.d: New testcase.
    * testsuite/ld-riscv-elf/relro-relax-lui.s: Likewise.
    * testsuite/ld-riscv-elf/relro-relax-pcrel.d: Likewise.
    * testsuite/ld-riscv-elf/relro-relax-pcrel.s: Likewise.
2021-05-31 11:29:26 +08:00
..
aarch64elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
aix.em Use bool in ld 2021-03-31 10:49:23 +10:30
alphaelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
arclinux.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
armcoff.em Use bool in ld 2021-03-31 10:49:23 +10:30
armelf.em PR27719, lang_mark_undefineds trashes memory 2021-04-12 11:57:03 +09:30
astring.sed
avrelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
beos.em Use bool in ld 2021-03-31 10:49:23 +10:30
bfin.em Use bool in ld 2021-03-31 10:49:23 +10:30
cr16elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
crxelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
cskyelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
elf-generic.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
elf-x86.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
epiphanyelf_4x4.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
genelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
generic.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
hppaelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
ia64elf.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
irix.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
linux.em Use bool in ld 2021-03-31 10:49:23 +10:30
m68hc1xelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
m68kelf.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
metagelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
mipself.em convert elf_link_hash macros to inline functions 2021-04-12 21:19:02 +09:30
mmix-elfnmmo.em Use bool in ld 2021-03-31 10:49:23 +10:30
mmixelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
mmo.em Use bool in ld 2021-03-31 10:49:23 +10:30
msp430.em Use bool in ld 2021-03-31 10:49:23 +10:30
nds32elf.em Remove bfd_stdint.h 2021-03-31 10:49:23 +10:30
needrelax.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
netbsd.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
nios2elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
ostring.sed
pdp11.em Use bool in ld 2021-03-31 10:49:23 +10:30
pe.em Use bool in ld 2021-03-31 10:49:23 +10:30
pep.em Use bool in ld 2021-03-31 10:49:23 +10:30
ppc32elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
ppc64elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
pruelf.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
README Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
riscvelf.em RISC-V: PR27566, Do not relax when data segment phase is exp_seg_relro_adjust. 2021-05-31 11:29:26 +08:00
rxelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
rxlinux.em Use bool in ld 2021-03-31 10:49:23 +10:30
s390.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
scoreelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
solaris2-x86.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
solaris2.em PR27719, lang_mark_undefineds trashes memory 2021-04-12 11:57:03 +09:30
spu_icache.o_c Regenerate spu overlay and icache manager files 2014-11-04 22:36:13 +10:30
spu_icache.S bfd/ 2009-03-17 12:46:19 +00:00
spu_ovl.o_c Regenerate spu_ovl.o_c 2016-10-15 12:53:57 +10:30
spu_ovl.S Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
spuelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
tic6xdsbt.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
ticoff.em Use bool in ld 2021-03-31 10:49:23 +10:30
v850elf.em Use bool in ld 2021-03-31 10:49:23 +10:30
vanilla.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
vms.em Use bool in ld 2021-03-31 10:49:23 +10:30
vxworks.em Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
xtensaelf.em Use bool in ld 2021-03-31 10:49:23 +10:30
z80.em Use bool in ld 2021-03-31 10:49:23 +10:30

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

The files in this directory are sourced by genscripts.sh, after
setting some variables to substitute in, to produce
C source files that contain jump tables for each emulation.

Copyright (C) 2012-2021 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.