From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dellerweb.de (unknown [IPv6:2a02:c207:3003:236::1]) by sourceware.org (Postfix) with ESMTPS id 0D62B3858D20 for ; Mon, 1 Apr 2024 18:10:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D62B3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=parisc-linux.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=parisc-linux.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0D62B3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a02:c207:3003:236::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711995045; cv=none; b=LnIw+rw+Bt4Sdu2s4DtftHdrjTu6kXZ3bkIwYJdsw7oQpEU3M2UJNBSP0ZaGfxF6lHGh4iUh0Y8MJQhnae0if+5tZYFPg/yhP/WyUn/itm69HLcAD7wPup/SD3RZP0Z22I36EgI5cmxIdfPmJc8pIV7oqJ1QTEWy+WE9ztSWf0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711995045; c=relaxed/simple; bh=OYPgCyZIEUR7uL1SMyp7fdh2OWRBry53KX5p66WyUsE=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=ZRU0Tn77m0uX2MuI/2XyWJIira1f0dx8WWMXRwhWTGcgYNBUQTpmjztRHEGun3+s10mrIQXYAsprHcPp1M1oBgDmpDp0FM46lf9yLOt1G2xIuSYCWKeQH1Rg+gmimYbnvmj0TkO9VCEiH7SsAdhJN4lvZo5TH0XK1N63JN1QJfU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mx3210.localdomain (unknown [142.126.188.251]) by dellerweb.de (Postfix) with ESMTPSA id 15EE4160001B; Mon, 1 Apr 2024 20:10:41 +0200 (CEST) Received: by mx3210.localdomain (Postfix, from userid 1000) id 03E4722012D; Mon, 1 Apr 2024 18:10:38 +0000 (UTC) Date: Mon, 1 Apr 2024 18:10:38 +0000 From: John David Anglin To: Binutils Cc: Alan Modra Subject: [PATCH] hppa: Implement PA 2.0 symbolic relocations for long displacements Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="k+mbVuBA+7eOTTfQ" Content-Disposition: inline X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --k+mbVuBA+7eOTTfQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Tested on hppa-unknown-linux-gnu. There are no regressions in all the binutils suites. I also tested with a modified version of gcc which allowed symbolic floating point loads and stores. There were no regressions in the gcc tests. Okay for trunk? Dave --- hppa: Implement PA 2.0 symbolic relocations for long displacements 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. 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. 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. 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. 2024-04-01 John David Anglin PR ld/31503 bfd/ChangeLog: * elf32-hppa.c (final_link_relocate): Output ld/ChangeLog: * emulparams/hppalinux.sh (DATA_SECTION_ALIGNMENT): Define. * scripttempl/elf.sc: Align .data section to DATA_SECTION_ALIGNMENT when relocating. diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index bb4bfdc00b8..e9b3ce24359 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 <