[PATCH 1/4] bfd: avoid elf-properties.c for ELF-free targets
Jan Beulich
jbeulich@suse.com
Mon Dec 15 10:54:06 GMT 2025
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).
---
Unlike elf-attrs-c or elf-sframe.c, elf-properties.c looks to be needed
for ELF in all cases, as per e.g. testcases in ld's testsuite. Why is
this, when most targets don't have any actual use of/for this? Only Arm64,
RISC-V, and x86 have GNU_PROPERTY_<arch>_* definitions in elf/common.h.
Whether it is useful to build compress.c when only ELF and (in a very
limited fashion) COFF use it is also questionable.
coff-bfd.* looks misplaced too, just that binutils/rdcoff.c is built
unconditionally, and hence references to the symbols are unconditionally
present.
--- 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 \
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -181,10 +181,10 @@ am__installdirs = "$(DESTDIR)$(bfdlibdir
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 \
--- 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
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
/* 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
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,
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 *ab
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, as
}
*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, as
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, as
*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,
}
*ptr_size = size;
+#endif /* OBJ_MAYBE_ELF */
+
return true;
}
@@ -666,8 +685,10 @@ bfd_compress_section_contents (bfd *abfd
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
--- a/bfd/configure
+++ b/bfd/configure
@@ -15831,7 +15831,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"
@@ -16172,6 +16172,7 @@ if test x${all_targets} = xtrue ; then
selarchs=
test -n "$assocvecs" &&
assocvecs=`echo $assocvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
+ TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF"
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
@@ -16182,6 +16183,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.
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -382,7 +382,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"
@@ -723,6 +723,7 @@ if test x${all_targets} = xtrue ; then
selarchs=
test -n "$assocvecs" &&
assocvecs=`echo $assocvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
+ TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF"
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
@@ -733,6 +734,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
mailing list