]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd/ELF: loongarch_{larch_reloc_name_lookup,adjust_reloc_bitsfield}() are exposed...
authorJan Beulich <jbeulich@suse.com>
Fri, 14 Nov 2025 08:03:06 +0000 (09:03 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 14 Nov 2025 08:03:06 +0000 (09:03 +0100)
As non-private functions, they should come with full disambiguating
prefixes - add bfd_elf_ to both. Hence commit 2903d813fcc2 ("bfd/ELF: mark
internal LoongArch functions hidden") also wrongly added ATTRIBUTE_HIDDEN
to them.

While loongarch_get_uleb128_length() also falls in the same category,
having it live in libbfd, when outside of gas there's hardly any use to be
expected, isn't very useful. Drop the function altogether and simplify the
clearing of the ULEB128 in md_apply_fix().

For loongarch_larch_reloc_name_lookup() drop gas'es custom declaration;
the libbfd one ought to be used, for producer and consumer to "see" the
same one. Also drop ATTRIBUTE_UNUSED there, as that makes sense only for
parameters in function definitions.

bfd/elfnn-loongarch.c
bfd/elfxx-loongarch.c
bfd/elfxx-loongarch.h
gas/config/loongarch-lex.h
gas/config/loongarch-parse.y
gas/config/tc-loongarch.c

index 1eff3b134ee765dfc6381197bf8e49c7ecafcfd7..bac9bf6849c52ca5294b53fbaa288726c2c62da7 100644 (file)
@@ -2758,7 +2758,7 @@ loongarch_reloc_rewrite_imm_insn (const Elf_Internal_Rela *rel,
 {
   /* Adjust the immediate based on alignment and
      its position in the instruction.  */
-  if (!loongarch_adjust_reloc_bitsfield (input_bfd, howto, &reloc_val))
+  if (!bfd_elf_loongarch_adjust_reloc_bitsfield (input_bfd, howto, &reloc_val))
     return bfd_reloc_overflow;
 
   int bits = bfd_get_reloc_size (howto) * 8;
index 0b030d39aa9dd8e01d6ea846abe1dbeae8b6c5f9..ce1032f30e98c1992ce460d9dfbf251efca98289 100644 (file)
@@ -1943,8 +1943,8 @@ loongarch_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
 }
 
 bfd_reloc_code_real_type
-loongarch_larch_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
-                                  const char *l_r_name)
+bfd_elf_loongarch_larch_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                                          const char *l_r_name)
 {
   for (size_t i = 0; i < ARRAY_SIZE (loongarch_howto_table); i++)
     {
@@ -2081,8 +2081,8 @@ reloc_unsign_bits (bfd *abfd, reloc_howto_type *howto, bfd_vma *fix_val)
 }
 
 bool
-loongarch_adjust_reloc_bitsfield (bfd *abfd, reloc_howto_type *howto,
-                                 bfd_vma *fix_val)
+bfd_elf_loongarch_adjust_reloc_bitsfield (bfd *abfd, reloc_howto_type *howto,
+                                         bfd_vma *fix_val)
 {
   BFD_ASSERT (((loongarch_reloc_howto_type *)howto)->adjust_reloc_bits);
   return ((loongarch_reloc_howto_type *)
@@ -2223,10 +2223,3 @@ loongarch_write_unsigned_leb128 (bfd_byte *p, unsigned int len, bfd_vma value)
   while (len);
   return p;
 }
-
-int loongarch_get_uleb128_length (bfd_byte *buf)
-{
-  unsigned int len = 0;
-  _bfd_read_unsigned_leb128 (NULL, buf, &len);
-  return len;
-}
index 9210df7ad628f0bd5a03e634b1374729acba9653..64bf3892ae8f727bce9961b629b05c706aac2765 100644 (file)
@@ -33,12 +33,10 @@ loongarch_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
   ATTRIBUTE_HIDDEN;
 
 extern bfd_reloc_code_real_type
-loongarch_larch_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
-                                  const char *l_r_name) ATTRIBUTE_HIDDEN;
+bfd_elf_loongarch_larch_reloc_name_lookup (bfd *abfd, const char *l_r_name);
 
 bool
-loongarch_adjust_reloc_bitsfield (bfd *, reloc_howto_type *, bfd_vma *)
-  ATTRIBUTE_HIDDEN;
+bfd_elf_loongarch_adjust_reloc_bitsfield (bfd *, reloc_howto_type *, bfd_vma *);
 void
 bfd_elf32_loongarch_set_data_segment_info (struct bfd_link_info *, int *);
 void
@@ -48,8 +46,6 @@ bfd_byte *
 loongarch_write_unsigned_leb128 (bfd_byte *p, unsigned int len, bfd_vma value)
   ATTRIBUTE_HIDDEN;
 
-int loongarch_get_uleb128_length (bfd_byte *buf) ATTRIBUTE_HIDDEN;
-
 /* TRUE if this is a PLT reference to a local IFUNC.  */
 #define PLT_LOCAL_IFUNC_P(INFO, H) \
   ((H)->dynindx == -1 \
index 5d730ecca90d149e612094270be55c87106c1990..e54360dccd09ed2f0a803eb3a4300598d218320e 100644 (file)
@@ -32,6 +32,3 @@ loongarch_parse_expr (const char *expr,
                      size_t max_reloc_num,
                      size_t *reloc_num,
                      offsetT *imm);
-bfd_reloc_code_real_type
-loongarch_larch_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
-                                  const char *l_r_name);
index d575748d3d2ef478a895302312eb024c3409f3c9..e24e6746a9e8900d86e55571a6ff5430a5b2ca0b 100644 (file)
@@ -20,6 +20,7 @@
 #include "as.h"
 #include "loongarch-lex.h"
 #include "loongarch-parse.h"
+#include "bfd/elfxx-loongarch.h"
 static void yyerror (const char *s ATTRIBUTE_UNUSED)
 {
 };
@@ -133,7 +134,7 @@ reloc (const char *op_c_str, const char *id_c_str, offsetT addend)
     btype = BFD_RELOC_LARCH_B26;
   else
     {
-      btype = loongarch_larch_reloc_name_lookup (NULL, op_c_str);
+      btype = bfd_elf_loongarch_larch_reloc_name_lookup (NULL, op_c_str);
       if (btype == BFD_RELOC_NONE)
        as_fatal (_("unsupported modifier %s"), op_c_str);
     }
index 7b53b6f6a52554d487053024094532e6024dd005..b006c6e6451b6bf87a52477fffe1b15215b520df 100644 (file)
@@ -1530,7 +1530,7 @@ static void fix_reloc_insn (fixS *fixP, bfd_vma reloc_val, char *buf)
 
   insn = bfd_getl32 (buf);
 
-  if (!loongarch_adjust_reloc_bitsfield (NULL, howto, &reloc_val))
+  if (!bfd_elf_loongarch_adjust_reloc_bitsfield (NULL, howto, &reloc_val))
     as_bad_where (fixP->fx_file, fixP->fx_line, "Reloc overflow");
 
   insn = (insn & (insn_t)howto->src_mask)
@@ -1832,12 +1832,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_LARCH_ADD_ULEB128:  */
     case BFD_RELOC_LARCH_SUB_ULEB128:
       {
-       unsigned int len = 0;
-       len = loongarch_get_uleb128_length ((bfd_byte *)buf);
-       bfd_byte *endp = (bfd_byte*) buf + len -1;
        /* Clean the uleb128 value to 0. Do not reduce the length.  */
-       memset (buf, 0x80, len - 1);
-       *endp = 0;
+       for (bfd_byte *ptr = (bfd_byte *)buf; *ptr &= 0x80; ++ptr)
+         /* Nothing.  */;
        break;
       }