]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd/ELF: fix BFD library build --enable-shared
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 22 Jan 2026 18:53:34 +0000 (18:53 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Mon, 26 Jan 2026 09:59:50 +0000 (09:59 +0000)
The patch series that added support for Object Attributes v2 introduced
regressions when building the BFD library as a shared object.

Incorrect usages of ATTRIBUTE_HIDDEN caused the following link-time errors:

/usr/bin/ld: config/obj-elf-attr.o: in function `obj_attr_v2_record':
obj-elf-attr.c: undefined reference to `bfd_elf_obj_attr_v2_init'
obj-elf-attr.c: undefined reference to `_bfd_obj_attr_v2_find_by_tag'
obj-elf-attr.c: undefined reference to `obj_attr_v2_t_append'
/usr/bin/ld: config/obj-elf-attr.o: in function `obj_attr_v2_subsection_record':
obj-elf-attr.c: undefined reference to `obj_attr_subsection_v2_t_append'
obj-elf-attr.c: undefined reference to `obj_attr_subsection_v2_t_remove'
obj-elf-attr.c: undefined reference to `obj_attr_subsection_v2_t_append'

This patch fixes the symbols visibility so that the BFD library links
correctly when built with --enable-shared.
The ATTRIBUTE_HIDDEN annotations were removed from bfd_elf_obj_attr_v2_init
and _bfd_obj_attr_v2_find_by_tag, and _bfd_obj_attr_v2_find_by_tag was renamed
to reflect the belonging to the public BFD API using the 'bfd_' prefix. The
doubly linked list helpers remain hidden and are instead exposed through wrapper
functions.

bfd/elf-attrs.c
bfd/elf-bfd.h
bfd/elfnn-aarch64.c
bfd/elfxx-aarch64.c
gas/config/obj-elf-attr.c

index cfb43bb3cb83bd07b1a574206d306dad47ee7268..7160bd4d2843581a27f76df90b838dddc6556832 100644 (file)
@@ -3192,7 +3192,7 @@ _bfd_elf_obj_attr_v2_cmp (const obj_attr_v2_t *a1, const obj_attr_v2_t *a2)
    This allows an early return if we find a higher numbered tag.  */
 
 obj_attr_v2_t *
-_bfd_obj_attr_v2_find_by_tag (const obj_attr_subsection_v2_t *subsec,
+bfd_obj_attr_v2_find_by_tag (const obj_attr_subsection_v2_t *subsec,
                              obj_attr_tag_t tag,
                              bool sorted)
 {
@@ -3218,6 +3218,14 @@ LINKED_LIST_MUTATIVE_OPS_DECL (obj_attr_subsection_v2_t,
 LINKED_LIST_MERGE_SORT_DECL (obj_attr_subsection_v2_t,
                             obj_attr_v2_t, /* extern */)
 
+/* Public API wrapper for LINKED_LIST_APPEND (obj_attr_v2_t).  */
+
+void bfd_obj_attr_subsection_v2_append (obj_attr_subsection_v2_t *subsec,
+                                       obj_attr_v2_t *attr)
+{
+  LINKED_LIST_APPEND (obj_attr_v2_t) (subsec, attr);
+}
+
 /* Create a new object attribute subsection with the following properties:
    - NAME: the name of the subsection.  Note: this parameter never holds a
      string literal, so the value has to be freeable.
@@ -3364,6 +3372,24 @@ LINKED_LIST_MUTATIVE_OPS_DECL (obj_attr_subsection_list_t,
 LINKED_LIST_MERGE_SORT_DECL (obj_attr_subsection_list_t,
                             obj_attr_subsection_v2_t, /* extern */)
 
+/* Public API wrapper for LINKED_LIST_APPEND (obj_attr_subsection_v2_t).  */
+
+void
+bfd_obj_attr_subsection_v2_list_append (obj_attr_subsection_list_t *l,
+                                       obj_attr_subsection_v2_t *subsec)
+{
+  LINKED_LIST_APPEND (obj_attr_subsection_v2_t) (l, subsec);
+}
+
+/* Public API wrapper for LINKED_LIST_REMOVE (obj_attr_subsection_v2_t).  */
+
+obj_attr_subsection_v2_t *
+bfd_obj_attr_subsection_v2_list_remove (obj_attr_subsection_list_t *l,
+                                       obj_attr_subsection_v2_t *subsec)
+{
+  return LINKED_LIST_REMOVE (obj_attr_subsection_v2_t) (l, subsec);
+}
+
 /* Serialize the object attributes in ABFD into the vendor section of
    OUTPUT_BFD.  */
 
index c7ef031979e309ed25c780fc61c191f55aecfe0e..2f67dce461733b9cee54c8f8ee0e21f029b1524c 100644 (file)
@@ -3216,15 +3216,17 @@ extern bool _bfd_elf_read_notes
   (bfd *, file_ptr, bfd_size_type, size_t) ATTRIBUTE_HIDDEN;
 
 extern obj_attr_v2_t *bfd_elf_obj_attr_v2_init (obj_attr_tag_t,
-  union obj_attr_value_v2) ATTRIBUTE_HIDDEN;
+  union obj_attr_value_v2);
 extern void _bfd_elf_obj_attr_v2_free (obj_attr_v2_t *, obj_attr_encoding_v2_t)
   ATTRIBUTE_HIDDEN;
 extern obj_attr_v2_t *_bfd_elf_obj_attr_v2_copy (const obj_attr_v2_t *,
   obj_attr_encoding_v2_t) ATTRIBUTE_HIDDEN;
 extern int _bfd_elf_obj_attr_v2_cmp (const obj_attr_v2_t *,
   const obj_attr_v2_t *) ATTRIBUTE_HIDDEN;
-extern obj_attr_v2_t * _bfd_obj_attr_v2_find_by_tag
-  (const obj_attr_subsection_v2_t *, obj_attr_tag_t, bool) ATTRIBUTE_HIDDEN;
+extern obj_attr_v2_t *bfd_obj_attr_v2_find_by_tag
+  (const obj_attr_subsection_v2_t *, obj_attr_tag_t, bool);
+extern void bfd_obj_attr_subsection_v2_append
+  (obj_attr_subsection_v2_t *, obj_attr_v2_t *);
 LINKED_LIST_MUTATIVE_OPS_PROTOTYPE (obj_attr_subsection_v2_t,
                                    obj_attr_v2_t, ATTRIBUTE_HIDDEN);
 LINKED_LIST_MERGE_SORT_PROTOTYPE_ (obj_attr_v2_t, ATTRIBUTE_HIDDEN);
@@ -3241,6 +3243,10 @@ extern obj_attr_subsection_v2_t *bfd_obj_attr_subsection_v2_find_by_name
   (obj_attr_subsection_v2_t *, const char *, bool);
 extern obj_attr_subsection_scope_v2_t bfd_elf_obj_attr_subsection_v2_scope
   (const bfd *, const char *);
+extern void bfd_obj_attr_subsection_v2_list_append
+  (obj_attr_subsection_list_t *, obj_attr_subsection_v2_t *);
+extern obj_attr_subsection_v2_t *bfd_obj_attr_subsection_v2_list_remove
+  (obj_attr_subsection_list_t *, obj_attr_subsection_v2_t *);
 LINKED_LIST_MUTATIVE_OPS_PROTOTYPE (obj_attr_subsection_list_t,
                                    obj_attr_subsection_v2_t,
                                    ATTRIBUTE_HIDDEN);
index 78bab74c197d6c85f6488fae1f7266f872d1b09b..08077fb74f84412e1b2c6e7b75e2e4d546ad8473 100644 (file)
@@ -10632,7 +10632,7 @@ elfNN_aarch64_link_setup_object_attributes (struct bfd_link_info *info)
   if (aeabi_feature_and_bits_subsec != NULL)
     {
       const obj_attr_v2_t *attr_bti
-       = _bfd_obj_attr_v2_find_by_tag (aeabi_feature_and_bits_subsec,
+       = bfd_obj_attr_v2_find_by_tag (aeabi_feature_and_bits_subsec,
                                        Tag_Feature_BTI, true);
       if (attr_bti && attr_bti->val.uint == 1)
        tdata->sw_protections.plt_type |= PLT_BTI;
index 8458579cd8137be96b67f22db9347c063ee91943..69ef148bf9cf41bfd8aa26f978f70d32cb52c141 100644 (file)
@@ -956,7 +956,7 @@ obj_attr_v2_record_tag_value (obj_attr_subsection_v2_t *subsec,
                              bool value)
 {
   obj_attr_v2_t *attr;
-  attr = _bfd_obj_attr_v2_find_by_tag (subsec, tag, false);
+  attr = bfd_obj_attr_v2_find_by_tag (subsec, tag, false);
   if (attr != NULL)
     {
       if (attr->val.uint != value)
@@ -1175,11 +1175,11 @@ aarch64_check_pauthabi_attributes (const struct bfd_link_info *info)
   int version_id = 0;
 
   const obj_attr_v2_t *attr
-    = _bfd_obj_attr_v2_find_by_tag (subsec, Tag_PAuth_Platform, true);
+    = bfd_obj_attr_v2_find_by_tag (subsec, Tag_PAuth_Platform, true);
   if (attr != NULL)
     platform_id = attr->val.uint;
 
-  attr = _bfd_obj_attr_v2_find_by_tag (subsec, Tag_PAuth_Schema, true);
+  attr = bfd_obj_attr_v2_find_by_tag (subsec, Tag_PAuth_Schema, true);
   if (attr != NULL)
     version_id = attr->val.uint;
 
index 7a4493d673ceaa0867e88d86fea78838da52a34b..7ed781d367cfe4954ce43f89bf297f737cb07c64 100644 (file)
@@ -1063,7 +1063,7 @@ obj_attr_v2_record (obj_attr_tag_t key, arg_t *arg_val)
   /* Go over the list of already recorded attributes and check for
      redefinitions (which are forbidden).  */
   bool skip_recording = false;
-  obj_attr_v2_t *recorded_attr = _bfd_obj_attr_v2_find_by_tag
+  obj_attr_v2_t *recorded_attr = bfd_obj_attr_v2_find_by_tag
     (elf_obj_attr_subsections (stdoutput).last, obj_attr->tag, false);
   if (recorded_attr != NULL)
     {
@@ -1084,7 +1084,7 @@ obj_attr_v2_record (obj_attr_tag_t key, arg_t *arg_val)
       return;
     }
 
-  LINKED_LIST_APPEND (obj_attr_v2_t)
+  bfd_obj_attr_subsection_v2_append
     (elf_obj_attr_subsections (stdoutput).last, obj_attr);
 }
 
@@ -1133,9 +1133,9 @@ obj_attr_v2_subsection_record (const char *name,
        }
 
       /* Move the existing subsection to the last position.  */
-      LINKED_LIST_REMOVE (obj_attr_subsection_v2_t)
+      bfd_obj_attr_subsection_v2_list_remove
        (&elf_obj_attr_subsections (stdoutput), already_recorded_subsec);
-      LINKED_LIST_APPEND (obj_attr_subsection_v2_t)
+      bfd_obj_attr_subsection_v2_list_append
        (&elf_obj_attr_subsections (stdoutput), already_recorded_subsec);
       /* Note: 'name' was unused, and will be freed on exit.  */
     }
@@ -1158,7 +1158,7 @@ obj_attr_v2_subsection_record (const char *name,
        = bfd_elf_obj_attr_subsection_v2_init (name, scope,
                                               comprehension_optional,
                                               encoding);
-      LINKED_LIST_APPEND (obj_attr_subsection_v2_t)
+      bfd_obj_attr_subsection_v2_list_append
        (&elf_obj_attr_subsections (stdoutput), new_subsection);
       return;
     }