From: Matthieu Longo Date: Thu, 22 Jan 2026 18:53:34 +0000 (+0000) Subject: bfd/ELF: fix BFD library build --enable-shared X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a69b049d74216b4f24dd10d76b1b461481a58a49;p=thirdparty%2Fbinutils-gdb.git bfd/ELF: fix BFD library build --enable-shared 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. --- diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c index cfb43bb3cb8..7160bd4d284 100644 --- a/bfd/elf-attrs.c +++ b/bfd/elf-attrs.c @@ -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. */ diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index c7ef031979e..2f67dce4617 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -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); diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 78bab74c197..08077fb74f8 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -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; diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 8458579cd81..69ef148bf9c 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -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; diff --git a/gas/config/obj-elf-attr.c b/gas/config/obj-elf-attr.c index 7a4493d673c..7ed781d367c 100644 --- a/gas/config/obj-elf-attr.c +++ b/gas/config/obj-elf-attr.c @@ -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; }