[PATCH v2 23/28] gnu directives: parse gnu_attribute and gnu_subsection in BAv2 context

Matthieu Longo matthieu.longo@arm.com
Fri May 2 10:32:55 GMT 2025


This patch exposes the support for OAv2 via GNU directives:
gnu_attribute and gnu_subsection. Those new directives work exactly
as the AEABI ones, but are usable by any backends.
Since the GNU namespace was already used by "gnu-testing" and was
defaulting to a private scope, it also changes the recognition of
the scope so that the usage of "gnu" for testing (which
is private) and others use cases (which are public) can be correctly
identified.
---
 gas/config/obj-elf.c | 18 ++++++++++++++++++
 gas/obj-attr.c       |  9 +++++----
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 8db8d1d6bc8..d7d044a7a35 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -73,6 +73,7 @@ static void obj_elf_symver (int);
 static void obj_elf_subsection (int);
 static void obj_elf_popsection (int);
 static void obj_elf_gnu_attribute (int);
+static void obj_elf_gnu_subsection (int);
 static void obj_elf_tls_common (int);
 static void obj_elf_lcomm (int);
 static void obj_elf_struct (int);
@@ -117,6 +118,7 @@ static const pseudo_typeS elf_pseudo_table[] =
   {"vtable_entry", obj_elf_vtable_entry, 0},
 
   /* A GNU extension for object attributes.  */
+  {"gnu_subsection", obj_elf_gnu_subsection, 0},
   {"gnu_attribute", obj_elf_gnu_attribute, 0},
 
   /* These are used for dwarf2.  */
@@ -2065,6 +2067,22 @@ obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
   obj_attr_process_attribute (OBJ_ATTR_GNU);
 }
 
+/* Parse a .gnu_subsection directive.  */
+
+static void
+obj_elf_gnu_subsection (int ignored ATTRIBUTE_UNUSED)
+{
+  obj_attr_version_t version = elf_obj_attr_version (stdoutput);
+  if (version < OBJ_ATTR_V2)
+    {
+      as_bad (("gnu_subsection is only available with object attributes v2, and"
+	      " the current target only supports object attributes v1"));
+      ignore_rest_of_line ();
+      return;
+    }
+  obj_attr_process_subsection ();
+}
+
 void
 elf_obj_read_begin_hook (void)
 {
diff --git a/gas/obj-attr.c b/gas/obj-attr.c
index 91d3693f090..2206d86765d 100644
--- a/gas/obj-attr.c
+++ b/gas/obj-attr.c
@@ -905,10 +905,11 @@ obj_attr_v2_subsection_record (const char *name,
     {
       const char *vendor_name =
 	get_elf_backend_data (stdoutput)->obj_attrs_vendor;
-      obj_attr_subsection_scope_v2 scope =
-	(strncmp (name, vendor_name, strlen (vendor_name)) == 0)
-	? OA_SUBSEC_PUBLIC
-	: OA_SUBSEC_PRIVATE;
+      obj_attr_subsection_scope_v2 scope = OA_SUBSEC_PRIVATE;
+      if (strncmp (name, vendor_name, strlen (vendor_name)) == 0
+	  || (strncmp (name, "gnu", 3) == 0
+	      && strncmp (name + 3, "-testing", 8) != 0))
+	scope = OA_SUBSEC_PUBLIC;
 
       obj_attr_subsection_v2 *new_subsection =
 	_bfd_elf_obj_attr_subsection_v2_init (name, scope, optional, encoding);
-- 
2.49.0



More information about the Binutils mailing list