[9/9] gas: hide emulation struct format_ops instances when not needed

Message ID a99367ef-0501-48cb-8dd8-e737fd4659e9@suse.com
State New
Headers
Series gas: tidying of emulations |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Jan Beulich Sept. 27, 2024, 1:05 p.m. UTC
  Most targets don't even support emulations, so this data (and certain
functions) are entirely dead code for them.
---
No emulations exist (anymore) using the COFF and ECOFF struct instances.
They could therefore also be purged altogether.
  

Patch

--- a/gas/config/obj-aout.c
+++ b/gas/config/obj-aout.c
@@ -221,14 +221,16 @@  obj_aout_type (int ignore ATTRIBUTE_UNUS
   s_ignore (0);
 }
 
-/* Support for an AOUT emulation.  */
+static const pseudo_typeS aout_pseudo_table[];
 
-static void
+void
 aout_pop_insert (void)
 {
   pop_insert (aout_pseudo_table);
 }
 
+#ifdef USE_EMULATIONS /* Support for an AOUT emulation.  */
+
 static int
 obj_aout_s_get_other (symbolS *sym)
 {
@@ -327,7 +329,9 @@  const struct format_ops aout_format_ops
   0	/* adjust_symtab.  */
 };
 
-const pseudo_typeS aout_pseudo_table[] =
+#endif /* USE_EMULATIONS */
+
+static const pseudo_typeS aout_pseudo_table[] =
 {
   {"line", obj_aout_line, 0},	/* Source code line number.  */
   {"ln", obj_aout_line, 0},	/* COFF line number that we use anyway.  */
--- a/gas/config/obj-aout.h
+++ b/gas/config/obj-aout.h
@@ -27,10 +27,9 @@ 
 
 #define OUTPUT_FLAVOR bfd_target_aout_flavour
 
-extern const pseudo_typeS aout_pseudo_table[];
-
+extern void aout_pop_insert (void);
 #ifndef obj_pop_insert
-#define obj_pop_insert() pop_insert (aout_pseudo_table)
+#define obj_pop_insert() aout_pop_insert ()
 #endif
 
 /* Symbol table entry data type.  */
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -1856,7 +1856,7 @@  symbol_dump (void)
 
 #endif /* DEBUG */
 
-const pseudo_typeS coff_pseudo_table[] =
+static const pseudo_typeS coff_pseudo_table[] =
 {
   {"ABORT", s_abort, 0},
   /* We accept the .bss directive for backward compatibility with
@@ -1897,14 +1897,14 @@  const pseudo_typeS coff_pseudo_table[] =
 };
 
 
-/* Support for a COFF emulation.  */
-
-static void
+void
 coff_pop_insert (void)
 {
   pop_insert (coff_pseudo_table);
 }
 
+#ifdef USE_EMULATIONS /* Support for a COFF emulation.  */
+
 static int
 coff_separate_stab_sections (void)
 {
@@ -1947,3 +1947,5 @@  const struct format_ops coff_format_ops
   coff_obj_symbol_clone_hook,
   coff_adjust_symtab
 };
+
+#endif /* USE_EMULATIONS */
--- a/gas/config/obj-coff.h
+++ b/gas/config/obj-coff.h
@@ -270,12 +270,9 @@  extern symbolS *coff_last_function;
 #endif
 #endif
 
-/* Sanity check.  */
-
-extern const pseudo_typeS coff_pseudo_table[];
-
+extern void coff_pop_insert (void);
 #ifndef obj_pop_insert
-#define obj_pop_insert() pop_insert (coff_pseudo_table)
+#define obj_pop_insert() coff_pop_insert ()
 #endif
 
 /* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK
--- a/gas/config/obj-ecoff.c
+++ b/gas/config/obj-ecoff.c
@@ -195,30 +195,6 @@  obj_ecoff_set_ext (symbolS *sym, EXTR *e
   (*debug_swap->swap_ext_out) (stdoutput, ext, esym->native);
 }
 
-static int
-ecoff_sec_sym_ok_for_reloc (asection *sec ATTRIBUTE_UNUSED)
-{
-  return 1;
-}
-
-static void
-obj_ecoff_frob_symbol (symbolS *sym, int *puntp ATTRIBUTE_UNUSED)
-{
-  ecoff_frob_symbol (sym);
-}
-
-static void
-ecoff_pop_insert (void)
-{
-  pop_insert (obj_pseudo_table);
-}
-
-static int
-ecoff_separate_stab_sections (void)
-{
-  return 0;
-}
-
 /* These are the pseudo-ops we support in this file.  Only those
    relating to debugging information are supported here.
 
@@ -282,6 +258,32 @@  const pseudo_typeS obj_pseudo_table[] =
   { NULL,	s_ignore,		0 }
 };
 
+#ifdef USE_EMULATIONS
+
+static int
+ecoff_sec_sym_ok_for_reloc (asection *sec ATTRIBUTE_UNUSED)
+{
+  return 1;
+}
+
+static void
+obj_ecoff_frob_symbol (symbolS *sym, int *puntp ATTRIBUTE_UNUSED)
+{
+  ecoff_frob_symbol (sym);
+}
+
+static void
+ecoff_pop_insert (void)
+{
+  pop_insert (obj_pseudo_table);
+}
+
+static int
+ecoff_separate_stab_sections (void)
+{
+  return 0;
+}
+
 const struct format_ops ecoff_format_ops =
 {
   bfd_target_ecoff_flavour,
@@ -321,3 +323,5 @@  const struct format_ops ecoff_format_ops
   ecoff_symbol_clone_hook,
   0	/* adjust_symtab.  */
 };
+
+#endif /* USE_EMULATIONS */
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -199,48 +199,6 @@  elf_pop_insert (void)
     pop_insert (ecoff_debug_pseudo_table);
 }
 
-static bfd_vma
-elf_s_get_size (symbolS *sym)
-{
-  return S_GET_SIZE (sym);
-}
-
-static void
-elf_s_set_size (symbolS *sym, bfd_vma sz)
-{
-  S_SET_SIZE (sym, sz);
-}
-
-static bfd_vma
-elf_s_get_align (symbolS *sym)
-{
-  return S_GET_ALIGN (sym);
-}
-
-static void
-elf_s_set_align (symbolS *sym, bfd_vma align)
-{
-  S_SET_ALIGN (sym, align);
-}
-
-int
-elf_s_get_other (symbolS *sym)
-{
-  return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;
-}
-
-static void
-elf_s_set_other (symbolS *sym, int other)
-{
-  S_SET_OTHER (sym, other);
-}
-
-static int
-elf_sec_sym_ok_for_reloc (asection *sec)
-{
-  return obj_sec_sym_ok_for_reloc (sec);
-}
-
 void
 elf_file_symbol (const char *s)
 {
@@ -3190,38 +3148,6 @@  elf_frob_file_after_relocs (void)
 #endif /* NEED_ECOFF_DEBUG */
 }
 
-static void
-elf_process_stab (int what ATTRIBUTE_UNUSED,
-		  const char *string ATTRIBUTE_UNUSED,
-		  int type ATTRIBUTE_UNUSED,
-		  int other ATTRIBUTE_UNUSED,
-		  int desc ATTRIBUTE_UNUSED)
-{
-#ifdef NEED_ECOFF_DEBUG
-  if (ECOFF_DEBUGGING)
-    ecoff_stab (what, string, type, other, desc);
-#endif
-}
-
-static int
-elf_separate_stab_sections (void)
-{
-#ifdef NEED_ECOFF_DEBUG
-  return (!ECOFF_DEBUGGING);
-#else
-  return 1;
-#endif
-}
-
-static void
-elf_init_stab_section (segT stab, segT stabstr)
-{
-#ifdef NEED_ECOFF_DEBUG
-  if (!ECOFF_DEBUGGING)
-#endif
-    obj_elf_init_stab_section (stab, stabstr);
-}
-
 /* This is called when the assembler starts.  */
 
 void
@@ -3265,6 +3191,84 @@  elf_end (void)
     }
 }
 
+#ifdef USE_EMULATIONS
+
+static bfd_vma
+elf_s_get_size (symbolS *sym)
+{
+  return S_GET_SIZE (sym);
+}
+
+static void
+elf_s_set_size (symbolS *sym, bfd_vma sz)
+{
+  S_SET_SIZE (sym, sz);
+}
+
+static bfd_vma
+elf_s_get_align (symbolS *sym)
+{
+  return S_GET_ALIGN (sym);
+}
+
+static void
+elf_s_set_align (symbolS *sym, bfd_vma align)
+{
+  S_SET_ALIGN (sym, align);
+}
+
+int
+elf_s_get_other (symbolS *sym)
+{
+  return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;
+}
+
+static void
+elf_s_set_other (symbolS *sym, int other)
+{
+  S_SET_OTHER (sym, other);
+}
+
+static int
+elf_sec_sym_ok_for_reloc (asection *sec)
+{
+  return obj_sec_sym_ok_for_reloc (sec);
+}
+
+#ifdef NEED_ECOFF_DEBUG
+static void
+elf_process_stab (int what ATTRIBUTE_UNUSED,
+		  const char *string ATTRIBUTE_UNUSED,
+		  int type ATTRIBUTE_UNUSED,
+		  int other ATTRIBUTE_UNUSED,
+		  int desc ATTRIBUTE_UNUSED)
+{
+  if (ECOFF_DEBUGGING)
+    ecoff_stab (what, string, type, other, desc);
+}
+#else
+# define elf_process_stab NULL
+#endif
+
+static int
+elf_separate_stab_sections (void)
+{
+#ifdef NEED_ECOFF_DEBUG
+  return (!ECOFF_DEBUGGING);
+#else
+  return 1;
+#endif
+}
+
+#ifdef NEED_ECOFF_DEBUG
+static void
+elf_init_stab_section (segT stab, segT stabstr)
+{
+  if (!ECOFF_DEBUGGING)
+    obj_elf_init_stab_section (stab, stabstr);
+}
+#endif
+
 const struct format_ops elf_format_ops =
 {
   bfd_target_elf_flavour,
@@ -3290,7 +3294,11 @@  const struct format_ops elf_format_ops =
   elf_copy_symbol_attributes,
   elf_process_stab,
   elf_separate_stab_sections,
+#ifdef NEED_ECOFF_DEBUG
   elf_init_stab_section,
+#else
+  obj_elf_init_stab_section,
+#endif
   elf_sec_sym_ok_for_reloc,
   elf_pop_insert,
 #ifdef NEED_ECOFF_DEBUG
@@ -3303,3 +3311,5 @@  const struct format_ops elf_format_ops =
   elf_obj_symbol_clone_hook,
   elf_adjust_symtab
 };
+
+#endif /* USE_EMULATIONS */
--- a/gas/config/obj-elf.h
+++ b/gas/config/obj-elf.h
@@ -150,7 +150,8 @@  extern void elf_end (void);
 
 int elf_s_get_other (symbolS *);
 #ifndef S_GET_OTHER
-#define S_GET_OTHER(S)	(elf_s_get_other (S))
+#define S_GET_OTHER(S) \
+  (elf_symbol (symbol_get_bfdsym (S))->internal_elf_sym.st_other)
 #endif
 #ifndef S_SET_OTHER
 #define S_SET_OTHER(S,V) \