binutils-gdb/bfd
Nelson Chu abd20cb637 RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.
I get the feedback recently that enable linker relaxations may fail to
build some program.  Consider the following case,

	.text
foo:
	addi	a0, a0, %pcrel_lo(.L2)
	call	foo
.L1:	auipc	a1, %pcrel_hi(data_g)
	addi	a1, a1, %pcrel_lo(.L1)
	lui	a2, %hi(data_g)
	addi	a2, a2, %lo(data_g)
	lui	a3, %tprel_hi(data_t)
	add	a3, a3, tp, %tprel_add(data_t)
	addi	a3, a3, %tprel_lo(data_t)
.L2:	auipc	a0, %pcrel_hi(data_g)

	.data
	.word 0x0
	.global data_g
data_g:	.word 0x1

	.section .tbss
data_t:	.word 0x0

The current ld reports `dangerous relocation error` when doing the
pcgp relaxation,
test.o: in function `foo':
(.text+0x0): dangerous relocation: %pcrel_lo missing matching %pcrel_hi

The .L2 auipc should not be removed since it is behind the corresponding
addi, so we record the information in the pcgp_relocs table to avoid
removing the auipc later.  But current ld still remove it since we do not
update the pcgp_relocs table while doing other relaxations.  I have two
solutions to fix the problem,

1. Update the pcgp_relocs table once we actually delete the code.
2. Add new relax pass to do the pcgp relaxations

At first I tried to do the first solution, and we need to update at
least three information - hi_sec_off of riscv_pcgp_lo_reloc, hi_sec_off
and hi_addr (symbol value) of riscv_pcgp_hi_reloc.  Update the hi_sec_off
is simple, but it is more complicate to update the symbol value, since we
almost have to do parts the same works of _bfd_riscv_relax_call again in
the riscv_relax_delete_bytes to get the correct symbol value.

Compared with the first solution, the second one is more intuitive and
simple.  We add a new relax pass to do the pcgp relaxations later, so
we will get all the information correctly in the _bfd_riscv_relax_call,
including the symbol value, without changing so much code.  I do not see
any penalty by adding a new relax pass for now, so it should be fine
to delay the pcgp relaxations.

Besides, I have pass all riscv-gnu-toolchain regressions for this patch.

	bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_section):  Add a new relax pass
	to do the pcgp relaxation later, after the lui and call relaxations,
	but before the delete and alignment relaxations.

	ld/
	* emultempl/riscvelf.em (riscv_elf_before_allocation): Change
	link_info.relax_pass from 3 to 4.
	* testsuite/ld-riscv-elf/pcgp-relax.d: New testcase.
	* testsuite/ld-riscv-elf/pcgp-relax.s: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-11-21 09:41:58 +08:00
..
doc
hosts
po Fix printf formatting errors where "0x" is used as a prefix for a decimal number. 2020-10-22 12:00:10 +01:00
.gitignore
acinclude.m4
aclocal.m4
aix5ppc-core.c
aix386-core.c
aout32.c
aout64.c
aout-cris.c
aout-ns32k.c
aout-target.h
aoutx.h
arc-got.h
arc-plt.def
arc-plt.h
archive64.c
archive.c Fix Windows-x-PPC build 2020-11-11 06:38:43 -07:00
archures.c aarch64: Add base support for Armv8-R 2020-09-08 14:14:11 +01:00
bfd-in2.h MSP430: Support relocations for subtract expressions in .uleb128 directives 2020-09-08 16:18:38 +01:00
bfd-in.h
bfd.c
bfd.m4
bfdio.c
bfdwin.c
binary.c
cache.c
cf-i386lynx.c
ChangeLog RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous. 2020-11-21 09:41:58 +08:00
ChangeLog-0001
ChangeLog-0203
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
ChangeLog-2018
ChangeLog-2019
ChangeLog-9193
ChangeLog-9495
ChangeLog-9697
ChangeLog-9899
cisco-core.c
coff64-rs6000.c
coff-alpha.c
coff-arm.c
coff-arm.h
coff-bfd.c
coff-bfd.h
coff-go32.c
coff-i386.c
coff-ia64.c
coff-mcore.c
coff-mips.c
coff-rs6000.c xcoff dependency list for static libraries 2020-11-09 14:09:01 +10:30
coff-sh.c
coff-stgo32.c
coff-tic4x.c
coff-tic30.c
coff-tic54x.c
coff-x86_64.c PE/x86-64: Display PE relocation names 2020-09-15 13:56:40 -07:00
coff-z8k.c
coff-z80.c
coffcode.h
coffgen.c
cofflink.c Fix thinko in the code to check coff archive elements. 2020-09-09 15:00:55 +01:00
coffswap.h
compress.c
config.bfd PR26667, Add powerpc64le-*-freebsd* support 2020-10-06 17:09:27 +10:30
config.in PR26469 UBSAN: elflink.c:8742 shift exponent 6148914691236511722 2020-08-27 22:05:00 +09:30
configure RISC-V: Support GNU indirect functions. 2020-10-16 10:11:18 +08:00
configure.ac RISC-V: Support GNU indirect functions. 2020-10-16 10:11:18 +08:00
configure.com
configure.host
COPYING
corefile.c
cpu-aarch64.c aarch64: Add base support for Armv8-R 2020-09-08 14:14:11 +01:00
cpu-aarch64.h
cpu-alpha.c
cpu-arc.c
cpu-arm.c arm: Add support for Cortex-A78C 2020-11-16 20:28:14 +00:00
cpu-arm.h
cpu-avr.c
cpu-bfin.c
cpu-bpf.c
cpu-cr16.c
cpu-cris.c
cpu-crx.c
cpu-csky.c
cpu-d10v.c
cpu-d30v.c
cpu-dlx.c
cpu-epiphany.c
cpu-fr30.c
cpu-frv.c
cpu-ft32.c
cpu-h8300.c
cpu-h8300.h
cpu-hppa.c
cpu-i386.c
cpu-ia64-opc.c
cpu-ia64.c
cpu-iamcu.c
cpu-ip2k.c
cpu-iq2000.c
cpu-k1om.c
cpu-l1om.c
cpu-lm32.c
cpu-m9s12x.c
cpu-m9s12xg.c
cpu-m32c.c
cpu-m32r.c
cpu-m68hc11.c
cpu-m68hc12.c
cpu-m68k.c
cpu-m68k.h
cpu-m10200.c
cpu-m10300.c
cpu-mcore.c
cpu-mep.c
cpu-metag.c
cpu-microblaze.c
cpu-mips.c
cpu-mmix.c
cpu-moxie.c
cpu-msp430.c
cpu-mt.c
cpu-nds32.c
cpu-nfp.c
cpu-nios2.c
cpu-ns32k.c
cpu-or1k.c
cpu-pdp11.c
cpu-pj.c
cpu-powerpc.c
cpu-pru.c
cpu-riscv.c
cpu-rl78.c
cpu-rs6000.c
cpu-rx.c
cpu-s12z.c
cpu-s390.c
cpu-score.c
cpu-sh.c
cpu-sparc.c
cpu-spu.c
cpu-tic4x.c
cpu-tic6x.c
cpu-tic30.c
cpu-tic54x.c
cpu-tilegx.c
cpu-tilepro.c
cpu-v850_rh850.c
cpu-v850.c
cpu-vax.c
cpu-visium.c
cpu-wasm32.c
cpu-xc16x.c
cpu-xgate.c
cpu-xstormy16.c
cpu-xtensa.c
cpu-z8k.c
cpu-z80.c
dep-in.sed
development.sh
dwarf1.c
dwarf2.c Include members in the variable table used when resolving DW_AT_specification tags. 2020-08-29 08:03:15 +01:00
ecoff-bfd.h
ecoff.c
ecofflink.c PR26418 UBSAN: cache.c:386 null pointer fwrite 2020-08-28 23:15:20 +09:30
ecoffswap.h
elf32-am33lin.c
elf32-arc.c elf32-arc.c: Don't cast between function pointer and void pointer 2020-10-16 10:35:23 +10:30
elf32-arm.c arm: ubsan: shift exponent 4G 2020-09-01 16:02:48 +09:30
elf32-arm.h
elf32-avr.c Fix sanitization problems in the BFD library when running the linker testsuite for the AVR target. 2020-08-26 17:43:39 +01:00
elf32-avr.h
elf32-bfin.c
elf32-bfin.h
elf32-cr16.c elf32-cr16.c tidy 2020-10-16 09:32:56 +10:30
elf32-cr16.h
elf32-cris.c CRIS: fix PR ld/26589, a missing NULL check in fix for PR ld/22269 2020-09-15 02:57:39 +02:00
elf32-crx.c PR26442 UBSAN: elf32-crx.c:512 cannot be represented in int 2020-08-31 20:28:09 +09:30
elf32-csky.c PR26445 UBSAN: elf32-csky.c:4115 left shift of negative value 2020-08-31 20:28:09 +09:30
elf32-csky.h
elf32-d10v.c
elf32-d30v.c
elf32-dlx.c
elf32-dlx.h
elf32-epiphany.c
elf32-fr30.c
elf32-frv.c
elf32-ft32.c
elf32-gen.c
elf32-h8300.c
elf32-hppa.c
elf32-hppa.h
elf32-i386.c
elf32-ip2k.c
elf32-iq2000.c
elf32-lm32.c
elf32-m32c.c
elf32-m32r.c
elf32-m68hc1x.c
elf32-m68hc1x.h
elf32-m68hc11.c
elf32-m68hc12.c
elf32-m68k.c
elf32-m68k.h
elf32-mcore.c
elf32-mep.c PR26466 UBSAN: elf32-mep.c:300 left shift of negative value 2020-08-31 20:28:10 +09:30
elf32-metag.c
elf32-metag.h
elf32-microblaze.c
elf32-mips.c
elf32-moxie.c
elf32-msp430.c MSP430: Support relocations for subtract expressions in .uleb128 directives 2020-09-08 16:18:38 +01:00
elf32-mt.c
elf32-nds32.c
elf32-nds32.h
elf32-nios2.c
elf32-nios2.h
elf32-or1k.c
elf32-pj.c
elf32-ppc.c
elf32-ppc.h
elf32-pru.c ubasn: elf32-pru.c:570 left shift of negative value 2020-09-02 16:30:42 +09:30
elf32-rl78.c
elf32-rx.c
elf32-rx.h
elf32-s12z.c
elf32-s390.c
elf32-score7.c
elf32-score.c
elf32-score.h
elf32-sh-relocs.h
elf32-sh.c
elf32-sparc.c
elf32-spu.c PR26498 UBSAN: elf32-spu.c:2292 left shift overflow 2020-08-26 23:23:45 +09:30
elf32-spu.h
elf32-tic6x.c
elf32-tic6x.h
elf32-tilegx.c
elf32-tilegx.h
elf32-tilepro.c
elf32-tilepro.h
elf32-v850.c
elf32-v850.h
elf32-vax.c
elf32-visium.c
elf32-wasm32.c
elf32-xc16x.c
elf32-xgate.c
elf32-xstormy16.c
elf32-xtensa.c PR26507 UBSAN: elf32-xtensa.c:6013 null pointer bsearch 2020-08-26 23:23:45 +09:30
elf32-z80.c
elf32.c
elf64-alpha.c Re: commit eae0b5c3b2 2020-08-27 21:56:33 +09:30
elf64-bpf.c
elf64-gen.c
elf64-hppa.c Fix seg-fault when running the ld testsuite for the hppa64-linux target. 2020-10-27 16:23:09 +00:00
elf64-hppa.h
elf64-ia64-vms.c
elf64-mips.c
elf64-mmix.c
elf64-nfp.c
elf64-ppc.c R_PPC64_GOT_LO_DS and R_PPC64_GOT_HA sanity check 2020-10-16 09:26:32 +10:30
elf64-ppc.h PR26655, Power10 libstdc++.so R_PPC64_NONE dynamic relocs 2020-09-24 07:52:53 +09:30
elf64-s390.c Fix a bug in the s390x linker when discarding all inpuit files. 2020-11-19 17:36:24 +00:00
elf64-sparc.c
elf64-tilegx.c
elf64-tilegx.h
elf64-x86-64.c
elf64.c
elf-attrs.c
elf-bfd.h Support SHF_GNU_RETAIN ELF section flag 2020-11-18 11:51:13 +00:00
elf-eh-frame.c
elf-hppa.h
elf-ifunc.c
elf-linker-x86.h x86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker 2020-10-09 05:13:26 -07:00
elf-linux-core.h
elf-m10200.c
elf-m10300.c mn10300: ubsan: shift exponent too large 2020-08-31 20:28:08 +09:30
elf-nacl.c
elf-nacl.h
elf-properties.c
elf-s390-common.c
elf-s390.h
elf-strtab.c
elf-vxworks.c
elf-vxworks.h
elf.c bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym 2020-11-20 13:34:07 +00:00
elfcode.h PR26574, heap buffer overflow in _bfd_elf_slurp_secondary_reloc_section 2020-09-04 19:29:02 +09:30
elfcore.h
elflink.c bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym 2020-11-20 13:34:07 +00:00
elfn32-mips.c
elfnn-aarch64.c aarch64: Return an error on conditional branch to an undefined symbol 2020-09-10 21:42:37 +05:30
elfnn-ia64.c PR26459 UBSAN: elfnn-ia64.c:1945 null pointer bsearch 2020-08-29 13:16:42 +09:30
elfnn-riscv.c RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous. 2020-11-21 09:41:58 +08:00
elfxx-aarch64.c
elfxx-aarch64.h
elfxx-ia64.c PR26461 UBSAN: elfxx-ia64.c:747 cannot be represented 2020-08-31 20:28:10 +09:30
elfxx-ia64.h
elfxx-mips.c PR26476, PR26477 UBSAN: elfxx-mips.c:2695,5370 cannot be represented 2020-08-31 20:28:10 +09:30
elfxx-mips.h
elfxx-riscv.c RISC-V: Support GNU indirect functions. 2020-10-16 10:11:18 +08:00
elfxx-riscv.h
elfxx-sparc.c Skip IFUNC relocations in debug sections ignored by ld.so. Fixes some ld test failures on sparc-linux-gnu. 2020-09-17 10:45:39 +01:00
elfxx-sparc.h
elfxx-target.h
elfxx-tilegx.c
elfxx-tilegx.h
elfxx-x86.c x86: Support GNU_PROPERTY_X86_ISA_1_BASELINE marker 2020-10-30 06:50:10 -07:00
elfxx-x86.h
format.c
gen-aout.c
genlink.h
go32stub.h
hash.c
host-aout.c
hppabsd-core.c
hpux-core.c
i386aout.c
i386bsd.c
i386lynx.c
i386msdos.c
ihex.c
init.c
irix-core.c
libaout.h
libbfd-in.h Re: MSP430: Support relocations for subtract expressions in .uleb128 directives 2020-09-09 08:41:28 +09:30
libbfd.c MSP430: Support relocations for subtract expressions in .uleb128 directives 2020-09-08 16:18:38 +01:00
libbfd.h Re: MSP430: Support relocations for subtract expressions in .uleb128 directives 2020-09-09 08:41:28 +09:30
libcoff-in.h
libcoff.h
libecoff.h
libhppa.h
libpei.h
libxcoff.h
linker.c Prevent the linker from overestimating the alignment requirement of common symbols on targets with octets that are larger than one byte. 2020-08-28 13:27:16 +01:00
lynx-core.c
mach-o-aarch64.c
mach-o-arm.c
mach-o-i386.c
mach-o-target.c
mach-o-x86-64.c
mach-o.c
mach-o.h
MAINTAINERS
Makefile.am
Makefile.in
makefile.vms
mep-relocs.pl PR26466 UBSAN: elf32-mep.c:300 left shift of negative value 2020-08-31 20:28:10 +09:30
merge.c
mmo.c
netbsd-core.c
netbsd.h
ns32k.h
ns32knetbsd.c
opncls.c
osf-core.c
pc532-mach.c
pdp11.c
pe-arm-wince.c
pe-arm.c
pe-i386.c
pe-mcore.c
pe-sh.c
pe-x86_64.c
pef-traceback.h
pef.c
pef.h
pei-arm-wince.c
pei-arm.c
pei-i386.c
pei-ia64.c
pei-mcore.c
pei-sh.c
pei-x86_64.c
peicode.h
peXXigen.c
plugin.c Stop the plugin handler from ignoring unknown symbol types when conanicalizing weak definitions. 2020-09-08 09:49:15 +01:00
plugin.h
PORTING
ppcboot.c
ptrace-core.c
README
reloc16.c
reloc.c elf/x86-64: Adjust relocation for PE/x86-64 inputs 2020-09-16 07:11:31 -07:00
rs6000-core.c
sco5-core.c
section.c
simple.c
som.c Fix PR binutils/26356 on hppa*-*-hpux*. 2020-08-27 15:25:03 +00:00
som.h
srec.c Fix a potential illegal memory access when creating an srec format file. 2020-10-28 11:07:02 +00:00
stab-syms.c
stabs.c
stamp-h.in
syms.c
sysdep.h Fix Windows-x-PPC build 2020-11-11 06:38:43 -07:00
targets.c PR26667, Add powerpc64le-*-freebsd* support 2020-10-06 17:09:27 +10:30
targmatch.sed
tekhex.c
TODO
trad-core.c
vax1knetbsd.c
vaxnetbsd.c
verilog.c Oops - failed to commit change to verilog.c. Trying again. 2020-09-16 16:19:53 +01:00
version.h Automatic date update in version.in 2020-11-21 00:00:17 +00:00
version.m4
vms-alpha.c asan: vms-alpha: stack buffer overflow 2020-11-09 23:27:46 +10:30
vms-lib.c
vms-misc.c asan: alpha-vms: buffer overflow 2020-10-25 22:25:45 +10:30
vms.h
warning.m4
wasm-module.c
wasm-module.h
xcofflink.c heap use after free in xcoff_archive_info_eq 2020-09-03 11:04:46 +09:30
xcofflink.h
xsym.c
xsym.h
xtensa-isa.c
xtensa-modules.c

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.

BFD is an object file library.  It permits applications to use the
same routines to process object files regardless of their format.

BFD is used by the GNU debugger, assembler, linker, and the binary
utilities.

The documentation on using BFD is scanty and may be occasionally
incorrect.  Pointers to documentation problems, or an entirely
rewritten manual, would be appreciated.

There is some BFD internals documentation in doc/bfdint.texi which may
help programmers who want to modify BFD.

BFD is normally built as part of another package.  See the build
instructions for that package, probably in a README file in the
appropriate directory.

BFD supports the following configure options:

  --target=TARGET
	The default target for which to build the library.  TARGET is
	a configuration target triplet, such as sparc-sun-solaris.
  --enable-targets=TARGET,TARGET,TARGET...
	Additional targets the library should support.  To include
	support for all known targets, use --enable-targets=all.
  --enable-64-bit-bfd
	Include support for 64 bit targets.  This is automatically
	turned on if you explicitly request a 64 bit target, but not
	for --enable-targets=all.  This requires a compiler with a 64
	bit integer type, such as gcc.
  --enable-shared
	Build BFD as a shared library.
  --with-mmap
	Use mmap when accessing files.  This is faster on some hosts,
	but slower on others.  It may not work on all hosts.

Report bugs with BFD to bug-binutils@gnu.org.

Patches are encouraged.  When sending patches, always send the output
of diff -u or diff -c from the original file to the new file.  Do not
send default diff output.  Do not make the diff from the new file to
the original file.  Remember that any patch must not break other
systems.  Remember that BFD must support cross compilation from any
host to any target, so patches which use ``#ifdef HOST'' are not
acceptable.  Please also read the ``Reporting Bugs'' section of the
gcc manual.

Bug reports without patches will be remembered, but they may never get
fixed until somebody volunteers to fix them.

Copyright (C) 2012-2020 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.