From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1118) id 452E03847718; Wed, 3 Apr 2024 22:12:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 452E03847718 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712182356; bh=6Mvai8lzDZLTN8wsz4WIb7eAVjrxVWgNdl3WpOEKEZ0=; h=From:To:Subject:Date:From; b=cbJsJyGmr3ss5AMLcnb1NBrlnH8utGeP3rcPK9lOdvdx+lBARyQnPMUghC7FcHeBL ayBTbwYwErsITMPyYfuKLQ/cxv/BT+oHgd8vYEsmWD0vkcT8Y80FVzMCYUP9xkbC8m yzWbhSuFqbZe0ewkSYGevpd+c51Sebr8BWCJ3cEw= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: John David Anglin To: binutils-cvs@sourceware.org Subject: [binutils-gdb/binutils-2_42-branch] hppa: Implement PA 2.0 symbolic relocations for long displacements X-Act-Checkin: binutils-gdb X-Git-Author: John David Anglin X-Git-Refname: refs/heads/binutils-2_42-branch X-Git-Oldrev: 884fb5373a1463b97845f15d94abf6aaa911347b X-Git-Newrev: d125f9675372b1ae01ceb1893c06ccb27bc7bf22 Message-Id: <20240403221236.452E03847718@sourceware.org> Date: Wed, 3 Apr 2024 22:12:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd125f9675372= b1ae01ceb1893c06ccb27bc7bf22 commit d125f9675372b1ae01ceb1893c06ccb27bc7bf22 Author: John David Anglin Date: Mon Apr 1 23:00:52 2024 +0000 hppa: Implement PA 2.0 symbolic relocations for long displacements =20 The PA 2.0 architecture introduced several new load and store instructions with long displacements. These include floating point loads and stores for word mode, and integer and floating point loads and stores for double words. Currently, ld does not correctly support symbolic relocations for these instructions. =20 If these are used, ld applies the standard R_PARISC_DPREL14R relocation and corrupts the instruction. This change uses bfd_hppa_insn2fmt to determine the correct relocation format. =20 We need to check the computed displacement as the immediate value used in these instruction must be a multiple of 4 or 8 depending on whether the access is for a word or double word. =20 A misaligned offset can potentially occur if the symbol is not properly aligned or if $global$ (the global pointer) is not double word aligned. $global$ is provided as a .data section start symbol. The patch adjusts elf.sc and hppalinux.sh to align .data to a 8-byte boundary in non-shared and non-pie links. =20 2024-04-01 John David Anglin =20 PR ld/31503 =20 bfd/ChangeLog: =20 * elf32-hppa.c (final_link_relocate): Output =20 ld/ChangeLog: =20 * emulparams/hppalinux.sh (DATA_SECTION_ALIGNMENT): Define. * scripttempl/elf.sc: Align .data section to DATA_SECTION_ALIGN= MENT when relocating. Diff: --- bfd/elf32-hppa.c | 46 ++++++++++++++++++++++++++++++++++++++++++= +++- ld/emulparams/hppalinux.sh | 1 + ld/scripttempl/elf.sc | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index 28aadfb8f9c..99ec7890465 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -3110,7 +3110,7 @@ final_link_relocate (asection *input_section, unsigned int r_type =3D ELF32_R_TYPE (rela->r_info); unsigned int orig_r_type =3D r_type; reloc_howto_type *howto =3D elf_hppa_howto_table + r_type; - int r_format =3D howto->bitsize; + int r_format; enum hppa_reloc_field_selector_type_alt r_field; bfd *input_bfd =3D input_section->owner; bfd_vma offset =3D rela->r_offset; @@ -3432,6 +3432,50 @@ final_link_relocate (asection *input_section, break; } =20 + r_format =3D bfd_hppa_insn2fmt (input_bfd, insn); + switch (r_format) + { + case 10: + case -10: + if (val & 7) + { + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%pA+%#" PRIx64 "): displacement %#x for insn %#x " + "is not a multiple of 8 (gp %#x)"), + input_bfd, + input_section, + (uint64_t) offset, + val, + insn, + (unsigned int) elf_gp (input_section->output_section->owner)); + bfd_set_error (bfd_error_bad_value); + return bfd_reloc_notsupported; + } + break; + + case -11: + case -16: + if (val & 3) + { + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%pA+%#" PRIx64 "): displacement %#x for insn %#x " + "is not a multiple of 4 (gp %#x)"), + input_bfd, + input_section, + (uint64_t) offset, + val, + insn, + (unsigned int) elf_gp (input_section->output_section->owner)); + bfd_set_error (bfd_error_bad_value); + return bfd_reloc_notsupported; + } + break; + + default: + break; + } insn =3D hppa_rebuild_insn (insn, val, r_format); =20 /* Update the instruction word. */ diff --git a/ld/emulparams/hppalinux.sh b/ld/emulparams/hppalinux.sh index 7892df9130d..5a462119742 100644 --- a/ld/emulparams/hppalinux.sh +++ b/ld/emulparams/hppalinux.sh @@ -19,6 +19,7 @@ else DATA_SEGMENT_END=3D". =3D DATA_SEGMENT_END (.);" DATA_SEGMENT_RELRO_END=3D". =3D DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPL= T-0}, .);" fi +DATA_SECTION_ALIGNMENT=3D"${CREATE_SHLIB-${CREATE_PIE-ALIGN(8)}}" ARCH=3Dhppa MACHINE=3Dhppa1.1 # We use 1.1 specific features. NOP=3D0x08000240 diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index fae7c2ad71c..d5022fa502f 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -669,7 +669,7 @@ cat <