LoongArch: Fix ld "undefined reference" error with --enable-shared
authormengqinggang <mengqinggang@loongson.cn>
Tue, 13 Jun 2023 08:07:12 +0000 (16:07 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Fri, 16 Jun 2023 09:32:02 +0000 (17:32 +0800)
  Because _bfd_read_unsigned_leb128 is hidden visibility, so it can't
  be referenced out of shared object.

  The new function loongarch_get_uleb128_length just used to call
  _bfd_read_unsigned_leb128.

bfd/ChangeLog:

* elfxx-loongarch.c (loongarch_get_uleb128_length): New function.
* elfxx-loongarch.h (loongarch_get_uleb128_length): New function.

gas/ChangeLog:

* config/tc-loongarch.c (md_apply_fix): Use
loongarch_get_uleb128_length.

bfd/elfxx-loongarch.c
bfd/elfxx-loongarch.h
gas/config/tc-loongarch.c

index ac644fff2f61b9e2e38f213db13fd2c7e9c87f58..cb312c46bb210ab6b7cad9d376030ebf5190c6da 100644 (file)
@@ -1944,3 +1944,10 @@ 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 cb02af4fe73d99bb91e803421d90010cd29da5ca..627c5db7bcca6536aab60db4d1fbcb5912d82f58 100644 (file)
@@ -44,6 +44,8 @@ bfd_elf64_loongarch_set_data_segment_info (struct bfd_link_info *, int *);
 bfd_byte *
 loongarch_write_unsigned_leb128 (bfd_byte *p, unsigned int len, bfd_vma value);
 
+int loongarch_get_uleb128_length (bfd_byte *buf);
+
 /* TRUE if this is a PLT reference to a local IFUNC.  */
 #define PLT_LOCAL_IFUNC_P(INFO, H) \
   ((H)->dynindx == -1 \
index 5ca9de47629491bfb799f6b71eb58abd1279baea..d1c5ce287e4e4f6692cb2a3411cc31ecdf48043c 100644 (file)
@@ -1382,7 +1382,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_LARCH_SUB_ULEB128:
       {
        unsigned int len = 0;
-       _bfd_read_unsigned_leb128 (NULL, (bfd_byte *)buf, &len);
+       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);