[COMMITTED] hppa: Handle dynamic relocations for ldil/addl instruction sequences
Checks
Commit Message
With the LRA register allocator, some packages fail to build because
LRA is unable to find a register to spill (GCC PR rtl-optimization/127142).
We need to allocate register %r1 for the addil instruction. It is used
for DT and DP relative loads. Old reload did a better job in handling
single register classes. The HP HP-UX linkers only support fixups for
addil instructions, so we still are limited to using addil on HP-UX.
However, this change opens up the possibility of using ldil/addl sequences
instead. While this sequence is longer, it can use any general register
and potentially it may be just as efficient when %r1 spills are needed.
Tested on hppa-unknown-linux-gnu. Committed to trunk.
Dave
---
hppa: Handle dynamic relocations for ldil/addl instruction sequences
When linking a PIC object into a non-shared executable, the linker
replaces the PIC register (%r19) with the DP register (%r27). Currently,
final_link_relocate only supports doing this conversion for literal
'addil' instructions, which requires the use of the highly constrained
%r1 register and can lead to LRA register spill failures in GCC.
This patch extends the relocation support to handle 'ldil/addl'
sequences. Since GCC emits the 'addl' instruction immediately following
the 'ldil', we can inspect the subsequent word to verify the opcode,
check for register matching, and safely rewrite the general register
to %dp (or clear it to %r0 for DP-relative expansions).
2026-10-26 John David Anglin <danglin@gcc.gnu.org>
bfd/ChangeLog:
PR rtl-optimization/127142
* elf32-hppa.c (final_link_relocate): Support converting
R_PARISC_DLTIND21L and R_PARISC_DPREL21L relocations for
ldil/addl instruction sequences where addl immediately
follows the ldil instruction.
@@ -3226,18 +3226,34 @@ final_link_relocate (asection *input_section,
if ((insn & 0xfc000000) == OP_ADDIL << 26)
insn = ADDIL_DP;
else
- /* We must have a ldil instruction. It's too hard to find
- and convert the associated add instruction, so issue an
- error. */
- _bfd_error_handler
- /* xgettext:c-format */
- (_("%pB(%pA+%#" PRIx64 "): %s fixup for insn %#x "
- "is not supported in a non-shared link"),
- input_bfd,
- input_section,
- (uint64_t) offset,
- howto->name,
- insn);
+ {
+ /* We must have a ldil instruction. In general, it's
+ hard to find and convert the associated add instruction.
+ However, gcc emits the addl immediately after the ldil.
+ So if the next instruction is an r19 addl, convert it
+ to use dp. Otherwise, issue an error. */
+ unsigned int next = bfd_get_32 (input_bfd, hit_data + 4);
+
+ /* Check for "addl %r0,%r19,%r0" and ldil/addl
+ target/input register match. */
+ if ((next & 0xffe0ffe0) == 0x0a600a00
+ && ((next >> 16) & 0x1f) == (insn & 0x1f))
+ {
+ /* Change register to dp. */
+ next = (next & 0xfc1fffff) | (27 << 21);
+ bfd_put_32 (input_bfd, (bfd_vma) next, hit_data + 4);
+ }
+ else
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB(%pA+%#" PRIx64 "): %s fixup for insn %#x "
+ "is not supported in a non-shared link"),
+ input_bfd,
+ input_section,
+ (uint64_t) offset,
+ howto->name,
+ insn);
+ }
}
else if (r_type == R_PARISC_DPREL14F)
{
@@ -3260,10 +3276,26 @@ final_link_relocate (asection *input_section,
if ((insn & ((0x3fu << 26) | (0x1f << 21)))
== ((OP_ADDIL << 26) | (27 << 21)))
{
+ /* We have a dp relative addil. */
insn &= ~ (0x1f << 21);
}
- /* Now try to make things easy for the dynamic linker. */
+ else if ((insn & (0x3fu << 26)) == (OP_LDIL << 26))
+ {
+ /* We have an ldil. */
+ unsigned int next = bfd_get_32 (input_bfd, hit_data + 4);
+ /* Check for "addl %r0,%dp,%r0" and ldil/addl
+ target/input register match. */
+ if ((next & 0xffe0ffe0) == 0x0b600a00
+ && ((next >> 16) & 0x1f) == (insn & 0x1f))
+ {
+ /* Change dp register in addl to r0. */
+ next &= ~ (0x1f << 21);
+ bfd_put_32 (input_bfd, (bfd_vma) next, hit_data + 4);
+ }
+ }
+
+ /* Now try to make things easy for the dynamic linker. */
break;
}
/* Fall thru. */