From d32e20f0bf7dcafd712e532e1274f64f613088e6 Mon Sep 17 00:00:00 2001 From: Andreas Krebbel Date: Mon, 3 Jul 2023 19:51:51 +0200 Subject: IBM Z: Fix pcrel relocs for symA-symB expressions The code in md_apply_fix which tries to deduce from the operand type which reloc to apply currently does the wrong thing for absolute relocs which have been re-written by fixup_segment as pc-relative to implement a subtraction of a local and an external symbol. In all these cases we wrongly emit an absolute reloc because we ignore the fx_pcrel flag in md_apply_fix. However, only for the last one we actually support a pc relative relocation of the proper size and can implement it accordingly. For the other 3 we have to issue an error. foo: cli 0(%r2),undef-foo la %r2,undef-foo(%r2) lay %r2,undef-foo(%r2) lhi %r2,undef-foo --- gas/config/tc-s390.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'gas/config') diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c index 9558519..765a9a2 100644 --- a/gas/config/tc-s390.c +++ b/gas/config/tc-s390.c @@ -2291,25 +2291,25 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) We are only prepared to turn a few of the operands into relocs. */ fixP->fx_offset = value; - if (operand->bits == 12 && operand->shift == 20) + if (operand->bits == 12 && operand->shift == 20 && !fixP->fx_pcrel) { fixP->fx_size = 2; fixP->fx_where += 2; fixP->fx_r_type = BFD_RELOC_390_12; } - else if (operand->bits == 12 && operand->shift == 36) + else if (operand->bits == 12 && operand->shift == 36 && !fixP->fx_pcrel) { fixP->fx_size = 2; fixP->fx_where += 4; fixP->fx_r_type = BFD_RELOC_390_12; } - else if (operand->bits == 20 && operand->shift == 20) + else if (operand->bits == 20 && operand->shift == 20 && !fixP->fx_pcrel) { fixP->fx_size = 4; fixP->fx_where += 2; fixP->fx_r_type = BFD_RELOC_390_20; } - else if (operand->bits == 8 && operand->shift == 8) + else if (operand->bits == 8 && operand->shift == 8 && !fixP->fx_pcrel) { fixP->fx_size = 1; fixP->fx_where += 1; @@ -2334,6 +2334,12 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) fixP->fx_offset += 2; fixP->fx_pcrel_adjust = 2; } + else if (fixP->fx_pcrel) + { + fixP->fx_r_type = BFD_RELOC_16_PCREL; + fixP->fx_offset += 2; + fixP->fx_pcrel_adjust = 2; + } else fixP->fx_r_type = BFD_RELOC_16; } -- cgit v1.1