]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 1)
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 14 Nov 2024 16:41:05 +0000 (16:41 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Mon, 2 Dec 2024 15:18:40 +0000 (15:18 +0000)
Exposing the output GNU property as a parameter of
_bfd_aarch64_elf_link_setup_gnu_properties seems to break the
encapsulation. The output GNU property update should be part of the
function that sets up the GNU properties.
This patch removes the parameter, and perform the update of the GNU
property on the output object inside the function.

bfd/elfnn-aarch64.c
bfd/elfxx-aarch64.c
bfd/elfxx-aarch64.h

index ae7105af2a566771cc873a3c8f03cdc44dc82a2c..482ce6aac24ad4448f83d6d8b39e4f0e8f0c6e28 100644 (file)
@@ -2526,29 +2526,6 @@ struct elf_aarch64_local_symbol
   bfd_vma tlsdesc_got_jump_table_offset;
 };
 
-struct elf_aarch64_obj_tdata
-{
-  struct elf_obj_tdata root;
-
-  /* local symbol descriptors */
-  struct elf_aarch64_local_symbol *locals;
-
-  /* Zero to warn when linking objects with incompatible enum sizes.  */
-  int no_enum_size_warning;
-
-  /* Zero to warn when linking objects with incompatible wchar_t sizes.  */
-  int no_wchar_size_warning;
-
-  /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties.  */
-  uint32_t gnu_property_aarch64_feature_1_and;
-
-  /* Software protections options.  */
-  struct aarch64_protection_opts sw_protections;
-};
-
-#define elf_aarch64_tdata(bfd)                         \
-  ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
-
 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
 
 #define is_aarch64_elf(bfd)                            \
@@ -10615,12 +10592,19 @@ elfNN_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym)
 static bfd *
 elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info *info)
 {
+  bfd *pbfd = _bfd_aarch64_elf_link_setup_gnu_properties (info);
+
+  /* When BTI is forced on the command line, information flows from plt_type to
+     outprop, so plt_type has already been set and outprop don't have any effect
+     on plt_type.
+     Whereas if BTI is inferred from the input bfds, information flows from
+     outprop to plt_type.  If the property GNU_PROPERTY_AARCH64_FEATURE_1_BTI
+     has been set on all the input bfds, then BTI is set on the output bfd and
+     plt_type is updated accordingly.  */
   struct elf_aarch64_obj_tdata * tdata = elf_aarch64_tdata (info->output_bfd);
   uint32_t outprop = tdata->gnu_property_aarch64_feature_1_and;
-  bfd *pbfd = _bfd_aarch64_elf_link_setup_gnu_properties (info, &outprop);
-  tdata->gnu_property_aarch64_feature_1_and = outprop;
-  tdata->sw_protections.plt_type
-    |= (outprop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ? PLT_BTI : 0;
+  if (outprop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
+    tdata->sw_protections.plt_type |= PLT_BTI;
   setup_plt_values (info, tdata->sw_protections.plt_type);
   return pbfd;
 }
index 2c0afb5a21d44718eafa1418feb8b7ac6e9c0f01..5d2c9e9d30c471e034b9b0b8352db5730e693f0a 100644 (file)
@@ -701,8 +701,7 @@ _bfd_aarch64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_ty
    such input is found, add it to a new section at the last input.  Update
    GPROP accordingly.  */
 bfd *
-_bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
-                                           uint32_t *gprop)
+_bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 {
   asection *sec;
   bfd *pbfd;
@@ -710,7 +709,8 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
   elf_property *prop;
   unsigned align;
 
-  uint32_t outprop = *gprop;
+  struct elf_aarch64_obj_tdata *tdata = elf_aarch64_tdata (info->output_bfd);
+  uint32_t outprop = tdata->gnu_property_aarch64_feature_1_and;
 
   /* Find a normal input file with GNU property note.  */
   for (pbfd = info->input_bfds;
@@ -792,7 +792,8 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
            break;
        }
     }
-  *gprop = outprop;
+
+  tdata->gnu_property_aarch64_feature_1_and = outprop;
   return pbfd;
 }
 
index 43db992d8d180a5aca7d94f3508854bec639186f..8302654eeffd2ea37babc59d008882556102fae4 100644 (file)
@@ -65,6 +65,30 @@ struct aarch64_protection_opts
 };
 typedef struct aarch64_protection_opts aarch64_protection_opts;
 
+struct elf_aarch64_local_symbol;
+struct elf_aarch64_obj_tdata
+{
+  struct elf_obj_tdata root;
+
+  /* local symbol descriptors */
+  struct elf_aarch64_local_symbol *locals;
+
+  /* Zero to warn when linking objects with incompatible enum sizes.  */
+  int no_enum_size_warning;
+
+  /* Zero to warn when linking objects with incompatible wchar_t sizes.  */
+  int no_wchar_size_warning;
+
+  /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties.  */
+  uint32_t gnu_property_aarch64_feature_1_and;
+
+  /* Software protections options.  */
+  struct aarch64_protection_opts sw_protections;
+};
+
+#define elf_aarch64_tdata(bfd)                         \
+  ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
+
 /* An enum to define what kind of erratum fixes we should apply.  This gives the
    user a bit more control over the sequences we generate.  */
 typedef enum
@@ -155,8 +179,7 @@ _bfd_aarch64_elf_write_core_note (bfd *, char *, int *, int, ...);
 #define elf_backend_write_core_note    _bfd_aarch64_elf_write_core_note
 
 extern bfd *
-_bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *,
-                                           uint32_t *);
+_bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *);
 
 extern enum elf_property_kind
 _bfd_aarch64_elf_parse_gnu_properties (bfd *, unsigned int,