[binutils-gdb] bfd: avoid elf-properties.c for ELF-free targets
Jan Beulich
jbeulich@sourceware.org
Fri Jan 9 07:48:46 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=65aa9c74478c6080b77fd5960fb148bf1a8d2763
commit 65aa9c74478c6080b77fd5960fb148bf1a8d2763
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri Jan 9 08:43:38 2026 +0100
bfd: avoid elf-properties.c for ELF-free targets
It is absurd to build this file when it's not possibly used. Move its
references to where other elf-*.* are and introduce a compiler define
(paralleling what gas uses, as having the same purpose) to isolate out
ELF-specific pieces in compress.c (which is where the references into
elf-properties.c are coming from).
Diff:
---
bfd/Makefile.am | 6 ++++--
bfd/Makefile.in | 14 ++++++++------
bfd/compress.c | 47 ++++++++++++++++++++++++++++++++++-------------
bfd/configure | 9 ++++++++-
bfd/configure.ac | 9 ++++++++-
5 files changed, 62 insertions(+), 23 deletions(-)
diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index cdd4bb63766..deee8b95e07 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -76,7 +76,7 @@ BFD_H = bfd.h
# debugger).
BFD32_LIBS = \
archive.lo archures.lo bfd.lo bfdio.lo cache.lo \
- coff-bfd.lo compress.lo corefile.lo elf-properties.lo format.lo \
+ coff-bfd.lo compress.lo corefile.lo format.lo \
hash.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \
section.lo simple.lo stab-syms.lo stabs.lo syms.lo targets.lo \
binary.lo ihex.lo srec.lo tekhex.lo verilog.lo
@@ -85,7 +85,7 @@ BFD64_LIBS = archive64.lo
BFD32_LIBS_CFILES = \
archive.c archures.c bfd.c bfdio.c cache.c coff-bfd.c \
- compress.c corefile.c elf-properties.c format.c hash.c \
+ compress.c corefile.c format.c hash.c \
libbfd.c linker.c merge.c opncls.c reloc.c \
section.c simple.c stab-syms.c stabs.c syms.c targets.c \
binary.c ihex.c srec.c tekhex.c verilog.c
@@ -289,6 +289,7 @@ BFD32_BACKENDS = \
elf-ifunc.lo \
elf-m10200.lo \
elf-m10300.lo \
+ elf-properties.lo \
elf-sframe.lo \
elf-strtab.lo \
elf-vxworks.lo \
@@ -422,6 +423,7 @@ BFD32_BACKENDS_CFILES = \
elf-ifunc.c \
elf-m10200.c \
elf-m10300.c \
+ elf-properties.c \
elf-sframe.c \
elf-strtab.c \
elf-vxworks.c \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index 6ef28568ed7..f6863225332 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -181,10 +181,10 @@ am__installdirs = "$(DESTDIR)$(bfdlibdir)" "$(DESTDIR)$(infodir)" \
LTLIBRARIES = $(bfdlib_LTLIBRARIES) $(noinst_LTLIBRARIES)
am__DEPENDENCIES_1 =
am__objects_1 = archive.lo archures.lo bfd.lo bfdio.lo cache.lo \
- coff-bfd.lo compress.lo corefile.lo elf-properties.lo \
- format.lo hash.lo libbfd.lo linker.lo merge.lo opncls.lo \
- reloc.lo section.lo simple.lo stab-syms.lo stabs.lo syms.lo \
- targets.lo binary.lo ihex.lo srec.lo tekhex.lo verilog.lo
+ coff-bfd.lo compress.lo corefile.lo format.lo hash.lo \
+ libbfd.lo linker.lo merge.lo opncls.lo reloc.lo section.lo \
+ simple.lo stab-syms.lo stabs.lo syms.lo targets.lo binary.lo \
+ ihex.lo srec.lo tekhex.lo verilog.lo
am_libbfd_la_OBJECTS = $(am__objects_1)
libbfd_la_OBJECTS = $(am_libbfd_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
@@ -545,7 +545,7 @@ BFD_H = bfd.h
# debugger).
BFD32_LIBS = \
archive.lo archures.lo bfd.lo bfdio.lo cache.lo \
- coff-bfd.lo compress.lo corefile.lo elf-properties.lo format.lo \
+ coff-bfd.lo compress.lo corefile.lo format.lo \
hash.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \
section.lo simple.lo stab-syms.lo stabs.lo syms.lo targets.lo \
binary.lo ihex.lo srec.lo tekhex.lo verilog.lo
@@ -553,7 +553,7 @@ BFD32_LIBS = \
BFD64_LIBS = archive64.lo
BFD32_LIBS_CFILES = \
archive.c archures.c bfd.c bfdio.c cache.c coff-bfd.c \
- compress.c corefile.c elf-properties.c format.c hash.c \
+ compress.c corefile.c format.c hash.c \
libbfd.c linker.c merge.c opncls.c reloc.c \
section.c simple.c stab-syms.c stabs.c syms.c targets.c \
binary.c ihex.c srec.c tekhex.c verilog.c
@@ -758,6 +758,7 @@ BFD32_BACKENDS = \
elf-ifunc.lo \
elf-m10200.lo \
elf-m10300.lo \
+ elf-properties.lo \
elf-sframe.lo \
elf-strtab.lo \
elf-vxworks.lo \
@@ -891,6 +892,7 @@ BFD32_BACKENDS_CFILES = \
elf-ifunc.c \
elf-m10200.c \
elf-m10300.c \
+ elf-properties.c \
elf-sframe.c \
elf-strtab.c \
elf-vxworks.c \
diff --git a/bfd/compress.c b/bfd/compress.c
index 48bf221baca..c9710178f39 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -24,7 +24,9 @@
#include <zstd.h>
#endif
#include "bfd.h"
+#ifdef OBJ_MAYBE_ELF
#include "elf-bfd.h"
+#endif
#include "libbfd.h"
#include "safe-ctype.h"
#include "libiberty.h"
@@ -155,6 +157,7 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
switch (bfd_get_flavour (abfd))
{
+#ifdef OBJ_MAYBE_ELF
case bfd_target_elf_flavour:
if ((abfd->flags & BFD_COMPRESS_GABI) != 0)
{
@@ -195,6 +198,7 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
/* Clear the SHF_COMPRESSED bit. */
elf_section_flags (sec) &= ~SHF_COMPRESSED;
+#endif /* OBJ_MAYBE_ELF */
/* Fall through. */
default:
@@ -215,12 +219,14 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
compression header is valid. */
static bool
-bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
- asection *sec,
- enum compression_type *ch_type,
- bfd_size_type *uncompressed_size,
- unsigned int *uncompressed_alignment_power)
+bfd_check_compression_header (bfd *abfd ATTRIBUTE_UNUSED,
+ bfd_byte *contents ATTRIBUTE_UNUSED,
+ asection *sec ATTRIBUTE_UNUSED,
+ enum compression_type *ch_type ATTRIBUTE_UNUSED,
+ bfd_size_type *uncompressed_size ATTRIBUTE_UNUSED,
+ unsigned int *uncompressed_alignment_power ATTRIBUTE_UNUSED)
{
+#ifdef OBJ_MAYBE_ELF
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
&& (elf_section_flags (sec) & SHF_COMPRESSED) != 0)
{
@@ -250,6 +256,7 @@ bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
return true;
}
}
+#endif /* OBJ_MAYBE_ELF */
return false;
}
@@ -266,8 +273,10 @@ DESCRIPTION
*/
int
-bfd_get_compression_header_size (bfd *abfd, asection *sec)
+bfd_get_compression_header_size (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sec ATTRIBUTE_UNUSED)
{
+#ifdef OBJ_MAYBE_ELF
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
{
if (sec == NULL)
@@ -283,6 +292,7 @@ bfd_get_compression_header_size (bfd *abfd, asection *sec)
else
return sizeof (Elf64_External_Chdr);
}
+#endif /* OBJ_MAYBE_ELF */
return 0;
}
@@ -303,11 +313,10 @@ DESCRIPTION
*/
bool
-bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd,
- const char **new_name, bfd_size_type *new_size)
+bfd_convert_section_setup (bfd *ibfd ATTRIBUTE_UNUSED, asection *isec,
+ bfd *obfd, const char **new_name,
+ bfd_size_type *new_size)
{
- bfd_size_type hdr_size;
-
if ((isec->flags & SEC_DEBUGGING) != 0
&& (isec->flags & SEC_HAS_CONTENTS) != 0)
{
@@ -340,6 +349,7 @@ bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd,
}
*new_size = bfd_section_size (isec);
+#ifdef OBJ_MAYBE_ELF
/* Do nothing if either input or output aren't ELF. */
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -362,7 +372,7 @@ bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd,
return true;
/* Do nothing if the input section isn't a SHF_COMPRESSED section. */
- hdr_size = bfd_get_compression_header_size (ibfd, isec);
+ bfd_size_type hdr_size = bfd_get_compression_header_size (ibfd, isec);
if (hdr_size == 0)
return true;
@@ -371,6 +381,9 @@ bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd,
*new_size += sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr);
else
*new_size -= sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr);
+
+#endif /* OBJ_MAYBE_ELF */
+
return true;
}
@@ -392,9 +405,13 @@ DESCRIPTION
*/
bool
-bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
- bfd_byte **ptr, bfd_size_type *ptr_size)
+bfd_convert_section_contents (bfd *ibfd ATTRIBUTE_UNUSED,
+ sec_ptr isec ATTRIBUTE_UNUSED,
+ bfd *obfd ATTRIBUTE_UNUSED,
+ bfd_byte **ptr ATTRIBUTE_UNUSED,
+ bfd_size_type *ptr_size ATTRIBUTE_UNUSED)
{
+#ifdef OBJ_MAYBE_ELF
bfd_byte *contents;
bfd_size_type ihdr_size, ohdr_size, size;
Elf_Internal_Chdr chdr;
@@ -499,6 +516,8 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
}
*ptr_size = size;
+#endif /* OBJ_MAYBE_ELF */
+
return true;
}
@@ -666,8 +685,10 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec)
if (compressed_size >= uncompressed_size)
{
memcpy (buffer, input_buffer, uncompressed_size);
+#ifdef OBJ_MAYBE_ELF
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
elf_section_flags (sec) &= ~SHF_COMPRESSED;
+#endif
sec->compress_status = COMPRESS_SECTION_NONE;
}
else
diff --git a/bfd/configure b/bfd/configure
index 0caff54a9e0..fc36a79f184 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -15829,7 +15829,7 @@ selarchs="$f"
tb=
elf="elf.lo elflink.lo elf-attrs.lo elf-strtab.lo elf-eh-frame.lo
- elf-sframe.lo dwarf1.lo dwarf2.lo"
+ elf-properties.lo elf-sframe.lo dwarf1.lo dwarf2.lo"
coffgen="coffgen.lo dwarf2.lo"
coff="cofflink.lo $coffgen"
ecoff="ecofflink.lo $coffgen"
@@ -16176,6 +16176,7 @@ if test x${all_targets} = xtrue ; then
esac
done
assocvecs=$f
+ TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF"
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
@@ -16186,6 +16187,12 @@ else # all_targets is true
selvecs=`echo $selvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
test -n "$selarchs" &&
selarchs=`echo $selarchs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
+
+ for i in $bfd_backends ; do
+ case "$i" in
+ elf.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF" ;;
+ esac
+ done
fi # all_targets is true
# 64-bit archives need a 64-bit bfd_vma.
diff --git a/bfd/configure.ac b/bfd/configure.ac
index a390761faeb..c5e24545dc9 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -370,7 +370,7 @@ selarchs="$f"
tb=
elf="elf.lo elflink.lo elf-attrs.lo elf-strtab.lo elf-eh-frame.lo
- elf-sframe.lo dwarf1.lo dwarf2.lo"
+ elf-properties.lo elf-sframe.lo dwarf1.lo dwarf2.lo"
coffgen="coffgen.lo dwarf2.lo"
coff="cofflink.lo $coffgen"
ecoff="ecofflink.lo $coffgen"
@@ -717,6 +717,7 @@ if test x${all_targets} = xtrue ; then
esac
done
assocvecs=$f
+ TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF"
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
@@ -727,6 +728,12 @@ else # all_targets is true
selvecs=`echo $selvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
test -n "$selarchs" &&
selarchs=`echo $selarchs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
+
+ for i in $bfd_backends ; do
+ case "$i" in
+ elf.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF" ;;
+ esac
+ done
fi # all_targets is true
# 64-bit archives need a 64-bit bfd_vma.
More information about the Binutils-cvs
mailing list