]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: use common code for object attribute v1 & v2 parsing
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 17 Apr 2025 14:02:18 +0000 (15:02 +0100)
committerMatthieu Longo <matthieu.longo@arm.com>
Thu, 22 Jan 2026 10:11:16 +0000 (10:11 +0000)
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
gas/config/obj-elf-attr.h
gas/config/tc-arc.c
gas/config/tc-arm.c
gas/config/tc-m68k.c
gas/config/tc-ppc.c
gas/config/tc-riscv.c
gas/config/tc-tic6x.c
gas/testsuite/gas/arm/attr-syntax.d

index 505390002f0f7469fcf50c5c42fa7876ca43c0db..c200d428606450b149c50710a78abdb15fabb622 100644 (file)
@@ -1243,132 +1243,12 @@ obj_attr_process_subsection (void)
 }
 #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 */
-
 /* Parse a .gnu_attribute directive.  */
 
 void
 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-#if (TC_OBJ_ATTR_v1 && !TC_OBJ_ATTR_v2)
-  obj_attr_v1_process_attribute (OBJ_ATTR_GNU);
-#else
   obj_attr_process_attribute (OBJ_ATTR_GNU);
-#endif
 }
 
 #endif /* TC_OBJ_ATTR */
index b91edd4276c1eafdb4e64e7125fe452e4fd0cb8d..3c968fe683acfa6de7efe15a241c24e0d92e4a7d 100644 (file)
@@ -44,9 +44,6 @@ 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) */
 extern obj_attr_tag_t obj_attr_process_attribute (obj_attr_vendor_t);
 #if (TC_OBJ_ATTR_v2)
 extern void obj_attr_process_subsection (void);
index 7549189cad89bf4c770ea54137ef831184f28459..d1a5f7e40c6a79a045fb2c894ff442c6c232b8e2 100644 (file)
@@ -4917,7 +4917,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;
index 04bccaff430d423a40bb8f0f8da8f9270281f903..9a4bf4b544b3a67ca36df656cabe7281c9aab99f 100644 (file)
@@ -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;
index b679539dd27cea2b4674b932ca0d4b88b34570f8..1823bd0e15ff50c98f0e4a5326c571e4a54f2500 100644 (file)
@@ -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)
index 7c34948c463b8850c64458fbf647a111cd0502af..7ba6c1ffee8c91c0b3eed53efbd35c5d1824b4d8 100644 (file)
@@ -2540,7 +2540,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
index f1a48bfc0e45634c205739b7070466b0fbbe62f9..6bcf53832a07bb0500bfb9a5571e1b9ed4ad0775 100644 (file)
@@ -5835,7 +5835,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;
 
index c4d94435886e225d4497a312eeafa5b7dac12961..bfd45f056b492ee81de24125c1eee82dbbf65680 100644 (file)
@@ -688,7 +688,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;
index b21e5eb61e5e446531633aa41ee5f15472c984d1..752b00a60032fab2e9a3e095a72d30243c4b675e 100644 (file)
@@ -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]+: Assembler messages:
+#error: \n[^\n]+: Error: unknown identifier 'made_up_tag' in this context
+#error: \n[^\n]+: Error: could not parse attribute tag
+#error: \n[^\n]+: Error: syntax error, comma not expected here
+#error: \n[^\n]+: Error: syntax error, comma missing here\Z