[RFC PATCH 02/17] nds32: give position markers no relocation field

Harshit Kumar harshit7kr@gmail.com
Mon Nov 16 18:43:18 GMT 2026


R_NDS32_RELAX_ENTRY, R_NDS32_LABEL and R_NDS32_RELAX_REGION_BEGIN and
_END mark a position for relaxation, not a field, but have a 4-octet
howto with a dst_mask.  The assembler puts RELAX_ENTRY at offset 0 of a
section of any size, and LABEL may be at its end, so a relocation
offset check that took their howto size would reject valid objects.
Give them a field size of 0 through elf_backend_reloc_field_size.  The
other hints keep their howto size: relaxation reads and rewrites the
instruction or value at their r_offset (LONGCALL*, DIFF8 to DIFF32).

bfd/
	* elf32-nds32.c (nds32_elf_reloc_field_size): New function.
	(elf_backend_reloc_field_size): Define.

Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
 bfd/elf32-nds32.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 3792701cf1..0da8ee3806 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -3314,6 +3314,30 @@ bfd_elf32_bfd_reloc_type_table_lookup (unsigned int code)
   return NULL;
 }
 
+/* R_NDS32_RELAX_ENTRY, R_NDS32_LABEL and R_NDS32_RELAX_REGION_BEGIN and
+   _END mark a position for relaxation rather than a field, but have a
+   4-octet howto with a dst_mask.  The assembler puts RELAX_ENTRY at
+   offset 0 of a section of any size, and LABEL may be at its end.  */
+
+static bool
+nds32_elf_reloc_field_size (const bfd *abfd ATTRIBUTE_UNUSED,
+			    unsigned int r_type,
+			    bool rel_p ATTRIBUTE_UNUSED,
+			    unsigned int *size)
+{
+  switch (r_type)
+    {
+    case R_NDS32_RELAX_ENTRY:
+    case R_NDS32_LABEL:
+    case R_NDS32_RELAX_REGION_BEGIN:
+    case R_NDS32_RELAX_REGION_END:
+      *size = 0;
+      return true;
+    default:
+      return false;
+    }
+}
+
 static reloc_howto_type *
 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
 				 bfd_reloc_code_real_type code)
@@ -14013,6 +14037,7 @@ nds32_elf_unify_tls_model (bfd *inbfd, asection *insec, bfd_byte *incontents,
 
 #define elf_info_to_howto			nds32_info_to_howto
 #define elf_info_to_howto_rel			nds32_info_to_howto_rel
+#define elf_backend_reloc_field_size		nds32_elf_reloc_field_size
 
 #define bfd_elf32_bfd_link_hash_table_create	nds32_elf_link_hash_table_create
 #define bfd_elf32_bfd_merge_private_bfd_data	nds32_elf_merge_private_bfd_data
-- 
2.55.0




More information about the Binutils mailing list