From: Andreas Krebbel <krebbel@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] IBM Z: Fix pcrel relocs for symA-symB expressions
Date: Mon, 3 Jul 2023 18:09:56 +0000 (GMT) [thread overview]
Message-ID: <20230703180956.D7DF03858D32@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d32e20f0bf7dcafd712e532e1274f64f613088e6
commit d32e20f0bf7dcafd712e532e1274f64f613088e6
Author: Andreas Krebbel <krebbel@linux.ibm.com>
Date: Mon Jul 3 19:51:51 2023 +0200
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
Diff:
---
gas/config/tc-s390.c | 14 ++++++++++----
gas/testsuite/gas/s390/esa-reloc.d | 2 +-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index 955851946f9..765a9a2e6bd 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;
}
diff --git a/gas/testsuite/gas/s390/esa-reloc.d b/gas/testsuite/gas/s390/esa-reloc.d
index c9da92870d5..0b13cb626a6 100644
--- a/gas/testsuite/gas/s390/esa-reloc.d
+++ b/gas/testsuite/gas/s390/esa-reloc.d
@@ -23,7 +23,7 @@ Disassembly of section .text:
22: a7 08 00 00 [ ]*lhi %r0,0
[ ]*24: R_390_GOT16 test_R_390_GOT16
26: a7 08 00 00 [ ]*lhi %r0,0
-[ ]*28: R_390_16 test_R_390_PC16\+0x26
+[ ]*28: R_390_PC16 test_R_390_PC16\+0x28
2a: a7 e5 00 00 [ ]*bras %r14,2a <foo\+0x2a>
[ ]*2c: R_390_PC16DBL test_R_390_PC16DBL\+0x2
2e: a7 e5 00 00 [ ]*bras %r14,2e <foo\+0x2e>
reply other threads:[~2023-07-03 18:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230703180956.D7DF03858D32@sourceware.org \
--to=krebbel@sourceware.org \
--cc=bfd-cvs@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).