public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@ds2.pg.gda.pl>
To: binutils@sourceware.cygnus.com
Subject: R_MIPS_PC16 relocation handling, a proposal
Date: Tue, 12 Oct 1999 09:41:00 -0000	[thread overview]
Message-ID: <Pine.GSO.3.96.991011194026.10449G-100000@delta.DS2.net> (raw)

Hi,

 Guessing from MIPS ISA and ABI documents it seems there is no much use of
R_MIPS_PC16 relocations.  On the other hand, the b* branch opcode family
uses a shifted by two bits 16-bit PC-relative field that is not handled by
any of MIPS relocations.  I think the authors of ABI might just missed the
fact of the shift when documenting R_MIPS_PC16.

 Anyway, I propose using R_MIPS_PC16 for BFD_RELOC_16_PCREL_S2 relocations
which would allow object modules to contain external references from b*
opcodes.  As R_MIPS_PC16 is pretty unusable at the moment, nothing should
break.  Otherwise, we might create a BFD-specific extension (just like
e.g. R_386_PC8 for i386).

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

Mon Oct 11 1999  Maciej W. Rozycki  <macro@ds2.pg.gda.pl>

        * elf32-mips.c (elf_mips_howto_table): Fix rightshift
        and pcrel_offset for R_MIPS_PC16.
        (mips_reloc_map): Replace BFD_RELOC_16_PCREL with
        BFD_RELOC_16_PCREL_S2.
        (mips_elf_calculate_relocation): Handle R_MIPS_PC16
        properly.
        (mips_elf_perform_relocation): Fix typos in the comment.

        * elf64-mips.c (mips_elf64_howto_table_rel): Fix
        rightshift and pcrel_offset for R_MIPS_PC16.
        (mips_elf64_howto_table_rela): Likewise.
        (mips_reloc_map): Replace BFD_RELOC_16_PCREL with
        BFD_RELOC_16_PCREL_S2.

diff -u --recursive --new-file binutils.macro/bfd/elf32-mips.c binutils/bfd/elf32-mips.c
--- binutils.macro/bfd/elf32-mips.c	Mon Oct  4 16:31:22 1999
+++ binutils/bfd/elf32-mips.c	Fri Oct  8 13:29:48 1999
@@ -601,7 +601,7 @@
 
   /* 16 bit PC relative reference.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 true,			/* pc_relative */
@@ -612,7 +612,7 @@
 	 true,			/* partial_inplace */
 	 0xffff,		/* src_mask */
 	 0xffff,		/* dst_mask */
-	 false),		/* pcrel_offset */
+	 true),			/* pcrel_offset */
 
   /* 16 bit call through global offset table.  */
   HOWTO (R_MIPS_CALL16,		/* type */
@@ -1829,7 +1829,7 @@
   { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
-  { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
+  { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
   { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
@@ -6101,7 +6101,8 @@
       break;
 
     case R_MIPS_PC16:
-      value = mips_elf_sign_extend (addend, 16) + symbol - p;
+      value = (bfd_signed_vma) (mips_elf_sign_extend (addend << 2, 18)
+				+ symbol - p) >> 2;
       overflowed_p = mips_elf_overflow_p (value, 16);
       break;
 
@@ -6294,9 +6295,9 @@
 	 ((sub1 << 16) | sub2)).
 	 
 	 When producing a relocateable object file, the calculation is
-	 (((A < 2) | (P & 0xf0000000) + S) >> 2)
+	 (((A << 2) | (P & 0xf0000000) + S) >> 2)
 	 When producing a fully linked file, the calculation is
-	 let R = (((A < 2) | (P & 0xf0000000) + S) >> 2)
+	 let R = (((A << 2) | (P & 0xf0000000) + S) >> 2)
 	 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)  */
 
       if (!info->relocateable)
diff -u --recursive --new-file binutils.macro/bfd/elf64-mips.c binutils/bfd/elf64-mips.c
--- binutils.macro/bfd/elf64-mips.c	Tue Aug 10 13:16:42 1999
+++ binutils/bfd/elf64-mips.c	Fri Oct  8 13:55:04 1999
@@ -246,7 +246,7 @@
 
   /* 16 bit PC relative reference.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 true,			/* pc_relative */
@@ -257,7 +257,7 @@
 	 true,			/* partial_inplace */
 	 0xffff,		/* src_mask */
 	 0xffff,		/* dst_mask */
-	 false),		/* pcrel_offset */
+	 true),			/* pcrel_offset */
 
   /* 16 bit call through global offset table.  */
   /* FIXME: This is not handled correctly.  */
@@ -800,7 +800,7 @@
 
   /* 16 bit PC relative reference.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 true,			/* pc_relative */
@@ -811,7 +811,7 @@
 	 true,			/* partial_inplace */
 	 0,			/* src_mask */
 	 0xffff,		/* dst_mask */
-	 false),		/* pcrel_offset */
+	 true),			/* pcrel_offset */
 
   /* 16 bit call through global offset table.  */
   /* FIXME: This is not handled correctly.  */
@@ -1372,7 +1372,7 @@
   { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
-  { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
+  { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
   { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },



             reply	other threads:[~1999-10-12  9:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-12  9:41 Maciej W. Rozycki [this message]
1999-10-12 22:34 ` Geoff Keating
1999-10-14  8:59   ` Maciej W. Rozycki
1999-10-14 20:21     ` Geoff Keating
1999-10-15  2:28       ` Maciej W. Rozycki
1999-10-13  6:04 ` Ian Lance Taylor
1999-10-14  8:44   ` Maciej W. Rozycki
1999-10-14 12:07     ` Ian Lance Taylor
1999-10-15  2:21       ` Maciej W. Rozycki

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=Pine.GSO.3.96.991011194026.10449G-100000@delta.DS2.net \
    --to=macro@ds2.pg.gda.pl \
    --cc=binutils@sourceware.cygnus.com \
    /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).