[PATCH v5 06/20] gas: use common code for object attribute v1 & v2 parsing

Matthieu Longo matthieu.longo@arm.com
Mon Jul 7 16:49:23 GMT 2025


Since the previous patch added all the code to be able to parse both
OAv1 and OAv2 directives, this patch switches OAv1 to use this common
code.
Additionally to the common code in obj-elf.c, the following backends
using a custom object attribute directive were impacted.
  - ARC
  - Arm
  - m68k
  - PowerPC
  - RISC-V
  - TI C6X
A parsing test for Arm had to be adapted to the error messages of the
new parser.

The gas and ld test suites were successfully run for the following
backends: S390, ARC, Arm, CSky, m68k, msp430, PowerPC, TI C6X, RISC-V,
AArch64, MIPS, SPARC.
---
 gas/config/obj-elf-attr.c           | 116 ----------------------------
 gas/config/obj-elf-attr.h           |   5 --
 gas/config/obj-elf.c                |   5 --
 gas/config/tc-arc.c                 |   2 +-
 gas/config/tc-arm.c                 |   2 +-
 gas/config/tc-m68k.c                |   2 +-
 gas/config/tc-ppc.c                 |   2 +-
 gas/config/tc-riscv.c               |   2 +-
 gas/config/tc-tic6x.c               |   2 +-
 gas/testsuite/gas/arm/attr-syntax.d |   6 +-
 10 files changed, 11 insertions(+), 133 deletions(-)

diff --git a/gas/config/obj-elf-attr.c b/gas/config/obj-elf-attr.c
index de5fcbfc191..710a93d6c74 100644
--- a/gas/config/obj-elf-attr.c
+++ b/gas/config/obj-elf-attr.c
@@ -1061,120 +1061,4 @@ obj_attr_process_subsection ()
 }
 #endif /* TC_OBJ_ATTR_v2 */
 
-#if (TC_OBJ_ATTR_v1)
-/* Parse an attribute directive for VENDOR.
-   Returns the attribute number read, or zero on error.  */
-
-obj_attr_tag_t
-obj_attr_v1_process_attribute (obj_attr_vendor_t vendor)
-{
-  expressionS exp;
-  int type;
-  int tag;
-  unsigned int i = 0;
-  char *s = NULL;
-
-  /* Read the first number or name.  */
-  skip_whitespace (input_line_pointer);
-  s = input_line_pointer;
-  if (ISDIGIT (*input_line_pointer))
-    {
-      expression (& exp);
-      if (exp.X_op != O_constant)
-	goto bad;
-      tag = exp.X_add_number;
-    }
-  else
-    {
-      char *name;
-
-      /* A name may contain '_', but no other punctuation.  */
-      for (; ISALNUM (*input_line_pointer) || *input_line_pointer == '_';
-	   ++input_line_pointer)
-	i++;
-      if (i == 0)
-	goto bad;
-
-      name = xmemdup0 (s, i);
-
-#ifndef CONVERT_SYMBOLIC_ATTRIBUTE
-#define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
-#endif
-
-      tag = CONVERT_SYMBOLIC_ATTRIBUTE (name);
-      if (tag == -1)
-	{
-	  as_bad (_("Attribute name not recognised: %s"), name);
-	  ignore_rest_of_line ();
-	  free (name);
-	  return 0;
-	}
-      free (name);
-    }
-
-  type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag);
-
-  if (! skip_past_comma (&input_line_pointer))
-    goto bad;
-  if (type & 1)
-    {
-      expression (& exp);
-      if (exp.X_op != O_constant)
-	{
-	  as_bad (_("expected numeric constant"));
-	  ignore_rest_of_line ();
-	  return 0;
-	}
-      i = exp.X_add_number;
-    }
-  if ((type & 3) == 3
-      && ! skip_past_comma (&input_line_pointer))
-    {
-      as_bad (_("expected comma"));
-      ignore_rest_of_line ();
-      return 0;
-    }
-  if (type & 2)
-    {
-      int len;
-
-      skip_whitespace (input_line_pointer);
-      if (*input_line_pointer != '"')
-	goto bad_string;
-      s = demand_copy_C_string (&len);
-    }
-
-  oav1_attr_record_seen (vendor, tag);
-  bool ok = false;
-  switch (type & 3)
-    {
-    case 3:
-      ok = bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);
-      break;
-    case 2:
-      ok = bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s);
-      break;
-    case 1:
-      ok = bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i);
-      break;
-    default:
-      abort ();
-    }
-  if (!ok)
-    as_fatal (_("error adding attribute: %s"),
-	      bfd_errmsg (bfd_get_error ()));
-
-  demand_empty_rest_of_line ();
-  return tag;
- bad_string:
-  as_bad (_("bad string constant"));
-  ignore_rest_of_line ();
-  return 0;
- bad:
-  as_bad (_("expected <tag> , <value>"));
-  ignore_rest_of_line ();
-  return 0;
-}
-#endif /* TC_OBJ_ATTR_v1 */
-
 #endif /* TC_OBJ_ATTR */
diff --git a/gas/config/obj-elf-attr.h b/gas/config/obj-elf-attr.h
index 0f95fa44be4..26abc53ea4f 100644
--- a/gas/config/obj-elf-attr.h
+++ b/gas/config/obj-elf-attr.h
@@ -66,12 +66,7 @@ extern bool oav1_attr_seen (obj_attr_vendor_t, obj_attr_tag_t);
 
 /* Object attributes parsers.  */
 
-#if (TC_OBJ_ATTR_v1)
-extern obj_attr_tag_t obj_attr_v1_process_attribute (obj_attr_vendor_t);
-#endif /* (TC_OBJ_ATTR_v1) */
-#if (TC_OBJ_ATTR_v1 || TC_OBJ_ATTR_v2)
 extern obj_attr_tag_t obj_attr_process_attribute (obj_attr_vendor_t);
-#endif /* (TC_OBJ_ATTR_v1 || TC_OBJ_ATTR_v2) */
 #if (TC_OBJ_ATTR_v2)
 extern void obj_attr_process_subsection (void);
 #endif /* (TC_OBJ_ATTR_v2) */
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 28e7e4efb92..bf34a52616d 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -2060,12 +2060,7 @@ obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED)
 static void
 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-#if (TC_OBJ_ATTR_v1)
-  obj_attr_v1_process_attribute (OBJ_ATTR_GNU);
-#endif /* TC_OBJ_ATTR_v1 */
-#if (TC_OBJ_ATTR_v2)
   obj_attr_process_attribute (OBJ_ATTR_GNU);
-#endif /* TC_OBJ_ATTR_v2 */
 }
 #endif /* (TC_OBJ_ATTR_v1 || TC_OBJ_ATTR_v2) */
 
diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c
index 5d78a284527..e0859ef1719 100644
--- a/gas/config/tc-arc.c
+++ b/gas/config/tc-arc.c
@@ -4928,7 +4928,7 @@ arc_extcorereg (int opertype)
 static void
 arc_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  obj_attr_tag_t tag = obj_attr_v1_process_attribute (OBJ_ATTR_PROC);
+  obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_PROC);
 
   if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
     attributes_set_explicitly[tag] = true;
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index 3f8f9f777a8..a900c117038 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -4972,7 +4972,7 @@ s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
 static void
 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  obj_attr_tag_t tag = obj_attr_v1_process_attribute (OBJ_ATTR_PROC);
+  obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_PROC);
 
   if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
     attributes_set_explicitly[tag] = 1;
diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c
index 70e993e3e55..d1a6fed39c1 100644
--- a/gas/config/tc-m68k.c
+++ b/gas/config/tc-m68k.c
@@ -7917,7 +7917,7 @@ m68k_elf_cons (int nbytes /* 4=.long */)
 static void
 m68k_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  obj_attr_tag_t tag = obj_attr_v1_process_attribute (OBJ_ATTR_GNU);
+  obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_GNU);
 
   /* Check validity of defined m68k tags.  */
   if (tag == Tag_GNU_M68K_ABI_FP)
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index ebd9da801a8..bf2bf906d80 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -2577,7 +2577,7 @@ ppc_elf_abiversion (int ignore ATTRIBUTE_UNUSED)
 static void
 ppc_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  obj_attr_tag_t tag = obj_attr_v1_process_attribute (OBJ_ATTR_GNU);
+  obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_GNU);
 
   /* Check validity of defined powerpc tags.  */
   if (tag == Tag_GNU_Power_ABI_FP
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index c5dca146b73..1f868e4a2c1 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -5824,7 +5824,7 @@ riscv_convert_symbolic_attribute (const char *name)
 static void
 s_riscv_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  obj_attr_tag_t tag = obj_attr_v1_process_attribute (OBJ_ATTR_PROC);
+  obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_PROC);
   unsigned old_xlen;
   obj_attribute *attr;
 
diff --git a/gas/config/tc-tic6x.c b/gas/config/tc-tic6x.c
index 61102f5e8d4..9ad5d511f16 100644
--- a/gas/config/tc-tic6x.c
+++ b/gas/config/tc-tic6x.c
@@ -689,7 +689,7 @@ static bool tic6x_attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
 static void
 s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  obj_attr_tag_t tag = obj_attr_v1_process_attribute (OBJ_ATTR_PROC);
+  obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_PROC);
 
   if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
     tic6x_attributes_set_explicitly[tag] = true;
diff --git a/gas/testsuite/gas/arm/attr-syntax.d b/gas/testsuite/gas/arm/attr-syntax.d
index b21e5eb61e5..cffbd682530 100644
--- a/gas/testsuite/gas/arm/attr-syntax.d
+++ b/gas/testsuite/gas/arm/attr-syntax.d
@@ -1,4 +1,8 @@
 #source: attr-syntax.s
 #notarget: *-*-pe
 #as:
-#error: :1: Error: Attribute name not recognised: made_up_tag.*:3: Error: expected <tag> , <value>.*:5: Error: expected <tag> , <value>
+#error: \A[^\n]*\.s: Assembler messages:\n
+#error: [^\n]*\.s:[0-9]+: Error: unknown identifier 'made_up_tag'\n
+#error: [^\n]*\.s:[0-9]+: Error: could not parse attribute tag\n
+#error: [^\n]*\.s:[0-9]+: Error: unexpected comma before parameter 1\n
+#error: [^\n]*\.s:[0-9]+: Error: missing comma after parameter 1
-- 
2.50.0



More information about the Binutils mailing list