[binutils-gdb] bfd: avoid elf-solaris2.c for non-Solaris targets
Jan Beulich
jbeulich@sourceware.org
Fri Mar 13 06:53:22 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=83846f34e2745726312f4319deb65aed380f4b03
commit 83846f34e2745726312f4319deb65aed380f4b03
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri Mar 13 07:52:08 2026 +0100
bfd: avoid elf-solaris2.c for non-Solaris targets
Even if small, it is wasteful to build this file when it's not actually
used. Limit it to Solaris targets and introduce a compiler define
(paralleling OBJ_MAYBE_ELF, as having similar purpose) to guard internals.
Diff:
---
bfd/configure | 14 ++++++++------
bfd/configure.ac | 14 ++++++++------
bfd/elf-solaris2.h | 18 ++++++++++++++++++
bfd/elf32-i386.c | 4 ++++
bfd/elf32-sparc.c | 4 ++++
bfd/elf64-sparc.c | 4 ++++
bfd/elf64-x86-64.c | 4 ++++
7 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/bfd/configure b/bfd/configure
index 0d55a4128e1..73037b7f671 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -15848,8 +15848,8 @@ elf64_powerpc="elf64-ppc.lo elf64-gen.lo elf64.lo elf-attrs.lo"
elf32_riscv="elf32-riscv.lo elfxx-riscv.lo elf-ifunc.lo elf32.lo elf-attrs.lo"
elf64_riscv="elf64-riscv.lo elf64.lo elfxx-riscv.lo elf-ifunc.lo elf32.lo elf-attrs.lo"
elf_tic6x="elf32-tic6x.lo elf32.lo elf-attrs.lo"
-elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-solaris2.lo elf-vxworks.lo"
-elfxx_sparc="elfxx-sparc.lo elf-solaris2.lo elf-vxworks.lo elf-attrs.lo $elf"
+elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-vxworks.lo"
+elfxx_sparc="elfxx-sparc.lo elf-vxworks.lo elf-attrs.lo $elf"
for vec in $selvecs
do
target_size=32
@@ -15932,7 +15932,7 @@ do
i386_coff_lynx_vec) tb="$tb cf-i386lynx.lo lynx-core.lo $coff" ;;
i386_elf32_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
i386_elf32_fbsd_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
- i386_elf32_sol2_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
+ i386_elf32_sol2_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf-solaris2.lo elf32.lo $elf" ;;
i386_elf32_vxworks_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
i386_mach_o_vec) tb="$tb mach-o-i386.lo" ;;
i386_msdos_vec) tb="$tb i386msdos.lo" ;;
@@ -16070,11 +16070,11 @@ do
sh_pe_le_vec) tb="$tb pe-sh.lo coff-sh.lo peigen.lo $coff" ;;
sh_pei_le_vec) tb="$tb pei-sh.lo coff-sh.lo peigen.lo $coff" ;;
sparc_elf32_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
- sparc_elf32_sol2_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+ sparc_elf32_sol2_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc elf-solaris2.lo" ;;
sparc_elf32_vxworks_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
sparc_elf64_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
sparc_elf64_fbsd_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
- sparc_elf64_sol2_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
+ sparc_elf64_sol2_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc elf-solaris2.lo"; target_size=64 ;;
spu_elf32_vec) tb="$tb elf32-spu.lo elf32.lo $elf" ;;
sym_vec) tb="$tb xsym.lo" ;;
tic30_coff_vec) tb="$tb coff-tic30.lo $coffgen" ;;
@@ -16114,7 +16114,7 @@ do
x86_64_elf32_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf32.lo $elf"; target_size=64 ;;
x86_64_elf64_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
x86_64_elf64_fbsd_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
- x86_64_elf64_sol2_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
+ x86_64_elf64_sol2_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf-solaris2.lo elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
x86_64_mach_o_vec) tb="$tb mach-o-x86-64.lo" ;;
x86_64_pe_vec) tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
x86_64_pe_big_vec) tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
@@ -16192,6 +16192,7 @@ if test x${all_targets} = xtrue ; then
done
assocvecs=$f
TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF -DOBJ_MAYBE_ELF_ATTRIBUTES -DOBJ_MAYBE_ELF_SFRAME"
+ TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SOLARIS2"
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
@@ -16208,6 +16209,7 @@ else # all_targets is true
elf.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF" ;;
elf-attrs.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_ATTRIBUTES" ;;
elf-sframe.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SFRAME" ;;
+ elf-solaris2.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SOLARIS2" ;;
esac
done
fi # all_targets is true
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 06e02a2d507..2883645c74e 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -389,8 +389,8 @@ elf64_powerpc="elf64-ppc.lo elf64-gen.lo elf64.lo elf-attrs.lo"
elf32_riscv="elf32-riscv.lo elfxx-riscv.lo elf-ifunc.lo elf32.lo elf-attrs.lo"
elf64_riscv="elf64-riscv.lo elf64.lo elfxx-riscv.lo elf-ifunc.lo elf32.lo elf-attrs.lo"
elf_tic6x="elf32-tic6x.lo elf32.lo elf-attrs.lo"
-elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-solaris2.lo elf-vxworks.lo"
-elfxx_sparc="elfxx-sparc.lo elf-solaris2.lo elf-vxworks.lo elf-attrs.lo $elf"
+elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-vxworks.lo"
+elfxx_sparc="elfxx-sparc.lo elf-vxworks.lo elf-attrs.lo $elf"
for vec in $selvecs
do
target_size=32
@@ -473,7 +473,7 @@ do
i386_coff_lynx_vec) tb="$tb cf-i386lynx.lo lynx-core.lo $coff" ;;
i386_elf32_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
i386_elf32_fbsd_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
- i386_elf32_sol2_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
+ i386_elf32_sol2_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf-solaris2.lo elf32.lo $elf" ;;
i386_elf32_vxworks_vec) tb="$tb elf32-i386.lo $elfxx_x86 elf32.lo $elf" ;;
i386_mach_o_vec) tb="$tb mach-o-i386.lo" ;;
i386_msdos_vec) tb="$tb i386msdos.lo" ;;
@@ -611,11 +611,11 @@ do
sh_pe_le_vec) tb="$tb pe-sh.lo coff-sh.lo peigen.lo $coff" ;;
sh_pei_le_vec) tb="$tb pei-sh.lo coff-sh.lo peigen.lo $coff" ;;
sparc_elf32_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
- sparc_elf32_sol2_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+ sparc_elf32_sol2_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc elf-solaris2.lo" ;;
sparc_elf32_vxworks_vec) tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
sparc_elf64_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
sparc_elf64_fbsd_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
- sparc_elf64_sol2_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
+ sparc_elf64_sol2_vec) tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc elf-solaris2.lo"; target_size=64 ;;
spu_elf32_vec) tb="$tb elf32-spu.lo elf32.lo $elf" ;;
sym_vec) tb="$tb xsym.lo" ;;
tic30_coff_vec) tb="$tb coff-tic30.lo $coffgen" ;;
@@ -655,7 +655,7 @@ do
x86_64_elf32_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf32.lo $elf"; target_size=64 ;;
x86_64_elf64_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
x86_64_elf64_fbsd_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
- x86_64_elf64_sol2_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
+ x86_64_elf64_sol2_vec) tb="$tb elf64-x86-64.lo $elfxx_x86 elf-solaris2.lo elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
x86_64_mach_o_vec) tb="$tb mach-o-x86-64.lo" ;;
x86_64_pe_vec) tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
x86_64_pe_big_vec) tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
@@ -733,6 +733,7 @@ if test x${all_targets} = xtrue ; then
done
assocvecs=$f
TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF -DOBJ_MAYBE_ELF_ATTRIBUTES -DOBJ_MAYBE_ELF_SFRAME"
+ TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SOLARIS2"
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
@@ -749,6 +750,7 @@ else # all_targets is true
elf.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF" ;;
elf-attrs.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_ATTRIBUTES" ;;
elf-sframe.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SFRAME" ;;
+ elf-solaris2.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SOLARIS2" ;;
esac
done
fi # all_targets is true
diff --git a/bfd/elf-solaris2.h b/bfd/elf-solaris2.h
index 0c7b1897c8f..4df430ba347 100644
--- a/bfd/elf-solaris2.h
+++ b/bfd/elf-solaris2.h
@@ -20,6 +20,8 @@
extern const char *const elf_solaris2_global_syms[];
+#ifdef OBJ_MAYBE_ELF_SOLARIS2
+
extern bool elf_solaris2_add_symbol_hook
(bfd *, struct bfd_link_info *, Elf_Internal_Sym *, const char **,
flagword *, asection **, bfd_vma *) ATTRIBUTE_HIDDEN;
@@ -32,3 +34,19 @@ is_solaris2_abi_global_sym (const char *name)
return true;
return false;
}
+
+#else /* !OBJ_MAYBE_ELF_SOLARIS2 */
+
+static inline bool
+elf_solaris2_add_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ Elf_Internal_Sym *isym ATTRIBUTE_UNUSED,
+ const char **name ATTRIBUTE_UNUSED,
+ flagword *flags ATTRIBUTE_UNUSED,
+ asection **sec ATTRIBUTE_UNUSED,
+ bfd_vma *value ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+#endif /* OBJ_MAYBE_ELF_SOLARIS2 */
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 8c7d7a74021..40759d07676 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -4651,6 +4651,8 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
#undef elf_backend_init_file_header
+#ifdef OBJ_MAYBE_ELF_SOLARIS2
+
/* Solaris 2. */
#undef TARGET_LITTLE_SYM
@@ -4688,6 +4690,8 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
#include "elf32-target.h"
+#endif /* OBJ_MAYBE_ELF_SOLARIS2 */
+
/* Intel MCU support. */
static bool
diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c
index ad18e734d18..b2aa5a4785a 100644
--- a/bfd/elf32-sparc.c
+++ b/bfd/elf32-sparc.c
@@ -275,6 +275,8 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
#include "elf32-target.h"
+#ifdef OBJ_MAYBE_ELF_SOLARIS2
+
/* Solaris 2. */
#undef TARGET_BIG_SYM
@@ -315,6 +317,8 @@ elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSE
#include "elf32-target.h"
+#endif /* OBJ_MAYBE_ELF_SOLARIS2 */
+
/* A final_write_processing hook that does both the SPARC- and VxWorks-
specific handling. */
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index bb83ccdf20e..1aea5aa8114 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -1005,6 +1005,8 @@ static const struct elf_size_info elf64_sparc_size_info =
#include "elf64-target.h"
+#ifdef OBJ_MAYBE_ELF_SOLARIS2
+
/* Solaris 2. */
static bool
@@ -1059,3 +1061,5 @@ elf64_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSE
#define elf_backend_copy_special_section_fields elf64_sparc_copy_solaris_special_section_fields
#include "elf64-target.h"
+
+#endif /* OBJ_MAYBE_ELF_SOLARIS2 */
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 9ce487ca05e..ea9a21934ea 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -6435,6 +6435,8 @@ elf_x86_64_special_sections[]=
#include "elf64-target.h"
+#ifdef OBJ_MAYBE_ELF_SOLARIS2
+
/* Solaris 2 support. */
static bool
@@ -6487,6 +6489,8 @@ elf_x86_64_solaris2_add_symbol_hook (bfd *abfd,
#include "elf64-target.h"
+#endif /* OBJ_MAYBE_ELF_SOLARIS2 */
+
/* Restore defaults. */
#undef ELF_OSABI
#undef ELF_OSABI_EXACT
More information about the Binutils-cvs
mailing list