This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH v2 2/2] MIPS/gas: Fix misaligned address errors to disregard ISA mode bit
- From: Faraz Shahbazker <fshahbazker at wavecomp dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Cc: Faraz Shahbazker <fshahbazker at wavecomp dot com>, Paul Hua <paul dot hua dot gm at gmail dot com>
- Date: Tue, 13 Aug 2019 05:32:20 +0000
- Subject: [PATCH v2 2/2] MIPS/gas: Fix misaligned address errors to disregard ISA mode bit
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=wavecomp.com; dkim=pass header.d=wavecomp.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lS7i+spofEX7Iy4FThCGmOZIsnRUj9pkx+2Pm1901M8=; b=Un96BhMgY1oybrkDAJY4Fszgan9TZRP7Q13hQWxCNj1IyfG41lZbArVSvXAGiqMDd/wVXdw1yRloNIHiDAZhHgxhagplvlq8ffdAZuYbLhOes1jM+J3m82zqrq97cfVMSlvGDx/WEQJOEmB+/OZVKmqnneP2s3NywF+Uf0w9Vj1SorNnq6497TrLOpopUZqFabDRqs2a/AenpoJXsBO0Obd14pbpLtQqrh7AvNGjHcwSvSlkH8wWKvqqtJE5jbgWyhYsv6PHR7Ux5M7gmvfiQlbvjwpnOCAQkVqZTqonwjGQv3sf0srjO63Lrb5nsa7ZdOXd0WfE3sgmO18CQeaDxw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MaZLEv3Q8vmmA4GrBv4yHUqwv8+HGRjm8wBXRp3VFeW7mcYdqy2MInKcYv40HyeEuVtNtXWX1mogKOqGhnVChZVhN6nWep9qVzWWPoEsTaNrm2FNcU1mw+yPYk+jdnE+ZEbsVH1Xfxil30PKVT1GVF+4WX4ZUHf2gyYo4yFztnsIO2QcdoIRokBrMFLLLviF+xxQV2PMBAAYISGGKocDVVWO4M6G9lsW+nqnXljl8p8/uP7v2H0JLHNfJoBJAmXf4v2KJ5PVMPcZ91c5ZMmyZ0we30QDQ3pzDFm0/jrSSMN7c4FIoFhaHMjX8XwvH/zuV6NyGyXOGA0yu1J68R7/IQ==
- References: <CAKjxQH=jw3BhibJwcwwpG5iy6Y49Jt6BadLp8KKCU1Acc=oW3Q@mail.gmail.com>
gas/
* config/tc-mips.c (fix_bad_misaligned_address): New function.
(fix_validate_branch): Call fix_bad_misaligned address_to
calculate the target address.
(md_apply_fix): Likewise.
(md_convert_frag): Update misaligned address calculation to
disregard ISA mode bit.
---
Notes:
v2 of the patch fixes build warnings for gcc7
gas/config/tc-mips.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 38a1b8c..a386d11 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -15743,6 +15743,24 @@ fix_bad_misaligned_branch_p (fixS *fixP)
return (val & 0x3) != isa_bit;
}
+/* Calculate the relocation target by masking off ISA mode bit before
+ combining symbol and addend. */
+
+static valueT
+fix_bad_misaligned_address (fixS *fixP)
+{
+ valueT val;
+ valueT off;
+ unsigned isa_mode;
+ gas_assert (fixP != NULL && fixP->fx_addsy != NULL);
+ val = S_GET_VALUE (fixP->fx_addsy);
+ off = fixP->fx_offset;
+ isa_mode = (ELF_ST_IS_COMPRESSED (S_GET_OTHER (fixP->fx_addsy))
+ ? 1 : 0);
+
+ return ((val & ~isa_mode) + off);
+}
+
/* Make the necessary checks on a regular MIPS branch pointed to by FIXP
and its calculated value VAL. */
@@ -15759,7 +15777,7 @@ fix_validate_branch (fixS *fixP, valueT val)
else if (fix_bad_misaligned_branch_p (fixP))
as_bad_where (fixP->fx_file, fixP->fx_line,
_("branch to misaligned address (0x%lx)"),
- (long) (S_GET_VALUE (fixP->fx_addsy) + fixP->fx_offset));
+ (long) fix_bad_misaligned_address (fixP));
else if (HAVE_IN_PLACE_ADDENDS && (fixP->fx_offset & 0x3) != 0)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("cannot encode misaligned addend "
@@ -15898,8 +15916,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
else if (fix_bad_misaligned_jump_p (fixP, shift))
as_bad_where (fixP->fx_file, fixP->fx_line,
_("jump to misaligned address (0x%lx)"),
- (long) (S_GET_VALUE (fixP->fx_addsy)
- + fixP->fx_offset));
+ (long) fix_bad_misaligned_address (fixP));
else if (HAVE_IN_PLACE_ADDENDS
&& (fixP->fx_offset & ((1 << shift) - 1)) != 0)
as_bad_where (fixP->fx_file, fixP->fx_line,
@@ -16153,7 +16170,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
&& (fixP->fx_offset & 0x1) != 0)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("branch to misaligned address (0x%lx)"),
- (long) (S_GET_VALUE (fixP->fx_addsy) + fixP->fx_offset));
+ (long) fix_bad_misaligned_address (fixP));
else if (HAVE_IN_PLACE_ADDENDS && (fixP->fx_offset & 0x1) != 0)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("cannot encode misaligned addend "
@@ -19000,7 +19017,8 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
else if ((fragp->fr_offset & 0x1) != 0)
as_bad_where (fragp->fr_file, fragp->fr_line,
_("branch to misaligned address (0x%lx)"),
- (long) val);
+ (long) (resolve_symbol_value (fragp->fr_symbol)
+ + (fragp->fr_offset & ~1)));
}
val = mips16_pcrel_val (fragp, pcrel_op, val, 0);
--
2.9.5