From: Jan Beulich Date: Fri, 14 Nov 2025 08:03:06 +0000 (+0100) Subject: bfd/ELF: loongarch_{larch_reloc_name_lookup,adjust_reloc_bitsfield}() are exposed... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48808d7b6641bffd07d3e804ea906d13e20585f7;p=thirdparty%2Fbinutils-gdb.git bfd/ELF: loongarch_{larch_reloc_name_lookup,adjust_reloc_bitsfield}() are exposed to gas 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. --- diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 1eff3b134ee..bac9bf6849c 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -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; diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c index 0b030d39aa9..ce1032f30e9 100644 --- a/bfd/elfxx-loongarch.c +++ b/bfd/elfxx-loongarch.c @@ -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; -} diff --git a/bfd/elfxx-loongarch.h b/bfd/elfxx-loongarch.h index 9210df7ad62..64bf3892ae8 100644 --- a/bfd/elfxx-loongarch.h +++ b/bfd/elfxx-loongarch.h @@ -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 \ diff --git a/gas/config/loongarch-lex.h b/gas/config/loongarch-lex.h index 5d730ecca90..e54360dccd0 100644 --- a/gas/config/loongarch-lex.h +++ b/gas/config/loongarch-lex.h @@ -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); diff --git a/gas/config/loongarch-parse.y b/gas/config/loongarch-parse.y index d575748d3d2..e24e6746a9e 100644 --- a/gas/config/loongarch-parse.y +++ b/gas/config/loongarch-parse.y @@ -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); } diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 7b53b6f6a52..b006c6e6451 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -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; }