[1/2] x86: conditionally hide object-format-specific functions

Message ID 1fbad9f6-107f-4a36-91ac-839b69887c5d@suse.com
State Accepted
Headers
Series x86: object format checking |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Jan Beulich Nov. 6, 2023, 2:03 p.m. UTC
  ELF-only functions don't need to be built when dealing with a non-ELF
target. md_section_align() also doesn't need to be a function when
dealing with non-AOUT targets. Similarly tc_fix_adjustable() can be a
simple macro when building non-ELF targets.

Furthermore x86_elf_abi is already used in ELF-only code sections, with
one exception. By adjusting that, the otherwise bogusly named variable
can also be confined to just ELF builds.
---
Do we actually need to retain all those uses of OBJ_MAYBE_*? Only cris
actually permits obj-multi to be used. Not having them would not only
improve readability, but would also eliminate anomalies like
elf_symbol_resolved_in_segment_p() not actually checking IS_ELF (or
OUTPUT_FLAVOR).
  

Patch

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -587,9 +587,7 @@  static int use_rela_relocations = 0;
 /* __tls_get_addr/___tls_get_addr symbol for TLS.  */
 static const char *tls_get_addr;
 
-#if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
-     || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
-     || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
 
 /* The ELF ABI to use.  */
 enum x86_elf_abi
@@ -3520,15 +3518,15 @@  reloc (unsigned int size,
   return NO_RELOC;
 }
 
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
 /* Here we decide which fixups can be adjusted to make them relative to
    the beginning of the section instead of the symbol.  Basically we need
    to make sure that the dynamic relocations are done correctly, so in
    some cases we force the original symbol to be used.  */
 
 int
-tc_i386_fix_adjustable (fixS *fixP ATTRIBUTE_UNUSED)
+tc_i386_fix_adjustable (fixS *fixP)
 {
-#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
   if (!IS_ELF)
     return 1;
 
@@ -3579,9 +3577,9 @@  tc_i386_fix_adjustable (fixS *fixP ATTRI
       || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
     return 0;
-#endif
   return 1;
 }
+#endif
 
 static INLINE bool
 want_disp32 (const insn_template *t)
@@ -15273,10 +15271,12 @@  i386_target_format (void)
   if (startswith (default_arch, "x86_64"))
     {
       update_code_flag (CODE_64BIT, 1);
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
       if (default_arch[6] == '\0')
 	x86_elf_abi = X86_64_ABI;
       else
 	x86_elf_abi = X86_64_X32_ABI;
+#endif
     }
   else if (!strcmp (default_arch, "i386"))
     update_code_flag (CODE_32BIT, 1);
@@ -15408,12 +15408,12 @@  md_undefined_symbol (char *name)
   return 0;
 }
 
+#if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
 /* Round up a section size to the appropriate boundary.  */
 
 valueT
-md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
+md_section_align (segT segment, valueT size)
 {
-#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
   if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
     {
       /* For a.out, force the section size to be aligned.  If we don't do
@@ -15426,10 +15426,10 @@  md_section_align (segT segment ATTRIBUTE
       align = bfd_section_alignment (segment);
       size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
     }
-#endif
 
   return size;
 }
+#endif
 
 /* On the i386, PC-relative offsets are relative to the start of the
    next instruction.  That is, the address of the offset, plus its
@@ -15873,6 +15873,20 @@  x86_dwarf2_addr_size (void)
   return bfd_arch_bits_per_address (stdoutput) / 8;
 }
 
+#ifdef TE_PE
+void
+tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
+{
+  expressionS exp;
+
+  exp.X_op = O_secrel;
+  exp.X_add_symbol = symbol;
+  exp.X_add_number = 0;
+  emit_expr (&exp, size);
+}
+#endif
+
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
 int
 i386_elf_section_type (const char *str, size_t len)
 {
@@ -15893,20 +15907,6 @@  i386_solaris_fix_up_eh_frame (segT sec)
 }
 #endif
 
-#ifdef TE_PE
-void
-tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
-{
-  expressionS exp;
-
-  exp.X_op = O_secrel;
-  exp.X_add_symbol = symbol;
-  exp.X_add_number = 0;
-  emit_expr (&exp, size);
-}
-#endif
-
-#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
 /* For ELF on x86-64, add support for SHF_X86_64_LARGE.  */
 
 bfd_vma
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -141,8 +141,12 @@  int i386_validate_fix (struct fix *);
     if (!i386_validate_fix(FIX)) goto SKIP;      \
   } while (0)
 
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
 #define tc_fix_adjustable(X)  tc_i386_fix_adjustable(X)
 extern int tc_i386_fix_adjustable (struct fix *);
+#else
+#define tc_fix_adjustable(X)  ((void)(X), 1)
+#endif
 
 /* Values passed to md_apply_fix don't include the symbol value.  */
 #define MD_APPLY_SYM_VALUE(FIX) 0
@@ -219,6 +223,10 @@  if ((n)									\
 extern void i386_cons_align (int);
 #define md_cons_align(nbytes) i386_cons_align (nbytes)
 
+#if !defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT)
+#define md_section_align(seg, value) ((void)(seg), (value))
+#endif
+
 void i386_print_statistics (FILE *);
 #define tc_print_statistics i386_print_statistics