public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: liuzhensong <liuzhensong@loongson.cn>
To: binutils@sourceware.org
Cc: xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com,
	xuchenghua@loongson.cn, mengqinggang@loongson.cn,
	huangpei@loongson.cn, chenglulu@loongson.cn,
	caiyinyu@loongson.cn, liuzhensong <liuzhensong@loongson.cn>
Subject: [PATCH v2 5/6] bfd: Delete R_LARCH_NONE from dyn info of LoongArch.
Date: Thu, 21 Jul 2022 09:37:51 +0800	[thread overview]
Message-ID: <20220721013751.466014-6-liuzhensong@loongson.cn> (raw)
In-Reply-To: <20220721013751.466014-1-liuzhensong@loongson.cn>

  Some R_LARCH_64 in section .eh_frame will to generate
  R_LARCH_NONE, we change relocation to R_LARCH_32_PCREL
  from R_LARCH_64 in setction .eh_frame and not generate
  dynamic relocation for R_LARCH_32_PCREL.

  Add New relocate type R_LARCH_32_PCREL for .eh_frame.

  include/elf/
    loongarch.h

  bfd/
    bfd/bfd-in2.h
    libbfd.h
    reloc.c
    elfxx-loongarch.c
    elfnn-loongarch.c

  gas/config/
    tc-loongarch.c

  binutils/
    readelf.c

  ld/testsuite/ld-elf/
    eh5.d
---
 bfd/bfd-in2.h             |  1 +
 bfd/elfnn-loongarch.c     | 11 +++++++++++
 bfd/elfxx-loongarch.c     | 19 ++++++++++++++++++-
 bfd/libbfd.h              |  1 +
 bfd/reloc.c               |  3 +++
 binutils/readelf.c        |  2 ++
 include/elf/loongarch.h   |  5 ++++-
 ld/testsuite/ld-elf/eh5.d |  2 +-
 8 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 91e6ad76b9a..2d6e1bbc0b0 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -6309,6 +6309,7 @@ assembler and not (currently) written to any object files.  */
   BFD_RELOC_LARCH_TLS_LD_HI20,
   BFD_RELOC_LARCH_TLS_GD_PC_HI20,
   BFD_RELOC_LARCH_TLS_GD_HI20,
+  BFD_RELOC_LARCH_32_PCREL,
   BFD_RELOC_LARCH_RELAX,
   BFD_RELOC_UNUSED };
 
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 3d86e1422af..4efe3d9370c 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -2010,6 +2010,17 @@ perform_relocation (const Elf_Internal_Rela *rel, asection *input_section,
       bfd_put (bits, input_bfd, opr1 - value, contents + rel->r_offset);
       break;
 
+    /* For eh_frame and debug info.  */
+    case R_LARCH_32_PCREL:
+      value -= sec_addr (input_section) + rel->r_offset;
+      value += rel->r_addend;
+      bfd_vma word = bfd_get (howto->bitsize, input_bfd,
+			      contents + rel->r_offset);
+      word = (word & ~howto->dst_mask) | (value & howto->dst_mask);
+      bfd_put (howto->bitsize, input_bfd, word, contents + rel->r_offset);
+      r = bfd_reloc_ok;
+      break;
+
     /* New reloc type.
        R_LARCH_B16 ~ R_LARCH_TLS_GD_HI20.  */
     case R_LARCH_B16:
diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c
index f059f1a0c05..0b00df556b7 100644
--- a/bfd/elfxx-loongarch.c
+++ b/bfd/elfxx-loongarch.c
@@ -1327,7 +1327,24 @@ static loongarch_reloc_howto_type loongarch_howto_table[] =
 	 reloc_bits,				/* adjust_reloc_bits */
 	 "gd_hi20"),				/* larch_reloc_type_name */
 
-  LOONGARCH_HOWTO (R_LARCH_RELAX,		/* type (99).  */
+  LOONGARCH_HOWTO (R_LARCH_32_PCREL,		/* type (99).  */
+	 0,					/* rightshift.  */
+	 4,					/* size.  */
+	 32,					/* bitsize.  */
+	 true,					/* pc_relative.  */
+	 0,					/* bitpos.  */
+	 complain_overflow_dont,		/* complain_on_overflow.  */
+	 bfd_elf_generic_reloc,			/* special_function.  */
+	 "R_LARCH_32_PCREL",			/* name.  */
+	 false,					/* partial_inplace.  */
+	 0,					/* src_mask */
+	 0xffffffff,				/* dst_mask */
+	 false,					/* pcrel_offset */
+	 BFD_RELOC_LARCH_32_PCREL,		/* bfd_reloc_code_real_type */
+	 NULL,					/* adjust_reloc_bits */
+	 NULL),					/* larch_reloc_type_name */
+
+  LOONGARCH_HOWTO (R_LARCH_RELAX,		/* type (100).  */
 	 0,					/* rightshift */
 	 1,					/* size */
 	 0,					/* bitsize */
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 7eaa75ad11e..c766722efb0 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -3492,6 +3492,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_LARCH_TLS_LD_HI20",
   "BFD_RELOC_LARCH_TLS_GD_PC_HI20",
   "BFD_RELOC_LARCH_TLS_GD_HI20",
+  "BFD_RELOC_LARCH_32_PCREL",
   "BFD_RELOC_LARCH_RELAX",
  "@@overflow: BFD_RELOC_UNUSED@@",
 };
diff --git a/bfd/reloc.c b/bfd/reloc.c
index 59c2aaa0d31..268e4b13049 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -8304,6 +8304,9 @@ ENUMX
 ENUMX
   BFD_RELOC_LARCH_TLS_GD_HI20
 
+ENUMX
+  BFD_RELOC_LARCH_32_PCREL
+
 ENUMX
   BFD_RELOC_LARCH_RELAX
 
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 6b7692d9dd5..4a3e448e30d 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -14389,6 +14389,8 @@ is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
     case EM_AVR_OLD:
     case EM_AVR:
       return reloc_type == 36; /* R_AVR_32_PCREL.  */
+    case EM_LOONGARCH:
+      return reloc_type == 99;  /* R_LARCH_32_PCREL.  */
     case EM_MICROBLAZE:
       return reloc_type == 2;  /* R_MICROBLAZE_32_PCREL.  */
     case EM_OR1K:
diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h
index 2d2bb6a5161..74757b82ca8 100644
--- a/include/elf/loongarch.h
+++ b/include/elf/loongarch.h
@@ -223,8 +223,11 @@ RELOC_NUMBER (R_LARCH_TLS_GD_PC_HI20, 97)
    %gd_hi20 (sym).  */
 RELOC_NUMBER (R_LARCH_TLS_GD_HI20, 98)
 
+/* For eh_frame and debug info.  */
+RELOC_NUMBER (R_LARCH_32_PCREL, 99)
+
 /* RELAX.  */
-RELOC_NUMBER (R_LARCH_RELAX, 99)
+RELOC_NUMBER (R_LARCH_RELAX, 100)
 
 END_RELOC_NUMBERS (R_LARCH_count)
 
diff --git a/ld/testsuite/ld-elf/eh5.d b/ld/testsuite/ld-elf/eh5.d
index d614251587c..4a697482355 100644
--- a/ld/testsuite/ld-elf/eh5.d
+++ b/ld/testsuite/ld-elf/eh5.d
@@ -4,7 +4,7 @@
 #ld:
 #readelf: -wf
 #target: [check_as_cfi]
-#xfail: alpha-*-*ecoff hppa64-*-* tile*-*-* visium-*-* loongarch64-*-*
+#xfail: alpha-*-*ecoff hppa64-*-* tile*-*-* visium-*-*
 
 Contents of the .eh_frame section:
 
-- 
2.31.1


      parent reply	other threads:[~2022-07-21  1:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21  1:37 [PATCH v2 0/6] Add new relocations for LoongArch liuzhensong
2022-07-21  1:37 ` [PATCH v2 1/6] bfd: Add supported for LoongArch new relocations liuzhensong
2022-07-21  1:37 ` [PATCH v2 2/6] LoongArch:opcodes: Add new reloc types liuzhensong
2022-07-21  2:30   ` Xi Ruoyao
2022-07-21  6:02     ` liuzhensong
2022-07-21  7:51       ` Xi Ruoyao
2022-07-21  8:26         ` liuzhensong
2022-07-21  1:37 ` [PATCH v2 3/6] LoongArch: gas: " liuzhensong
2022-07-21  1:37 ` [PATCH v2 4/6] LoongArch: Move ifunc info to rela.dyn from rela.plt liuzhensong
2022-07-21  1:37 ` liuzhensong [this message]

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=20220721013751.466014-6-liuzhensong@loongson.cn \
    --to=liuzhensong@loongson.cn \
    --cc=binutils@sourceware.org \
    --cc=caiyinyu@loongson.cn \
    --cc=chenglulu@loongson.cn \
    --cc=huangpei@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=maskray@google.com \
    --cc=mengqinggang@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /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).