From: Jan Beulich Date: Fri, 4 Apr 2025 08:19:51 +0000 (+0200) Subject: binutils: properly split objcopy and strip X-Git-Tag: binutils-2_45~972 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fb3d389d83f0ea1ac9a8d346884ffdb41e4fbb8;p=thirdparty%2Fbinutils-gdb.git binutils: properly split objcopy and strip By not linking the exact same object file twice, in particular strip can benefit quite a bit from the compiler eliminating dead code. --- diff --git a/binutils/Makefile.am b/binutils/Makefile.am index 20c711aca92..243b38c145b 100644 --- a/binutils/Makefile.am +++ b/binutils/Makefile.am @@ -255,7 +255,7 @@ LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) size_SOURCES = size.c $(BULIBS) -objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) +objcopy_SOURCES = not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) strings_SOURCES = strings.c $(BULIBS) @@ -265,7 +265,7 @@ readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(ZSTD_LIBS) $ elfedit_SOURCES = elfedit.c version.c $(ELFLIBS) elfedit_LDADD = $(LIBINTL) $(LIBIBERTY) -strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) +strip_new_SOURCES = is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) nm_new_SOURCES = nm.c demanguse.c $(BULIBS) diff --git a/binutils/Makefile.in b/binutils/Makefile.in index 8029bc29d57..c2c31bf2ae2 100644 --- a/binutils/Makefile.in +++ b/binutils/Makefile.in @@ -240,8 +240,8 @@ nm_new_LDADD = $(LDADD) am__objects_3 = rddbg.$(OBJEXT) debug.$(OBJEXT) stabs.$(OBJEXT) \ rdcoff.$(OBJEXT) am__objects_4 = $(am__objects_3) wrstabs.$(OBJEXT) -am_objcopy_OBJECTS = objcopy.$(OBJEXT) not-strip.$(OBJEXT) \ - rename.$(OBJEXT) $(am__objects_4) $(am__objects_1) +am_objcopy_OBJECTS = not-strip.$(OBJEXT) rename.$(OBJEXT) \ + $(am__objects_4) $(am__objects_1) objcopy_OBJECTS = $(am_objcopy_OBJECTS) objcopy_LDADD = $(LDADD) am_objdump_OBJECTS = objdump.$(OBJEXT) dwarf.$(OBJEXT) prdbg.$(OBJEXT) \ @@ -268,8 +268,8 @@ srconv_LDADD = $(LDADD) am_strings_OBJECTS = strings.$(OBJEXT) $(am__objects_1) strings_OBJECTS = $(am_strings_OBJECTS) strings_LDADD = $(LDADD) -am_strip_new_OBJECTS = objcopy.$(OBJEXT) is-strip.$(OBJEXT) \ - rename.$(OBJEXT) $(am__objects_4) $(am__objects_1) +am_strip_new_OBJECTS = is-strip.$(OBJEXT) rename.$(OBJEXT) \ + $(am__objects_4) $(am__objects_1) strip_new_OBJECTS = $(am_strip_new_OBJECTS) strip_new_LDADD = $(LDADD) am_sysdump_OBJECTS = sysdump.$(OBJEXT) $(am__objects_1) @@ -793,13 +793,13 @@ bfdtest1_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) bfdtest2_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) size_SOURCES = size.c $(BULIBS) -objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) +objcopy_SOURCES = not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) strings_SOURCES = strings.c $(BULIBS) readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c demanguse.c $(ELFLIBS) readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(ZSTD_LIBS) $(DEBUGINFOD_LIBS) $(MSGPACK_LIBS) $(LIBSFRAME) elfedit_SOURCES = elfedit.c version.c $(ELFLIBS) elfedit_LDADD = $(LIBINTL) $(LIBIBERTY) -strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) +strip_new_SOURCES = is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) nm_new_SOURCES = nm.c demanguse.c $(BULIBS) objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) EXTRA_objdump_SOURCES = od-elf32_avr.c od-macho.c od-xcoff.c od-pe.c diff --git a/binutils/is-strip.c b/binutils/is-strip.c index 26aeaf0ccb9..4ac10359ef6 100644 --- a/binutils/is-strip.c +++ b/binutils/is-strip.c @@ -17,7 +17,5 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -/* Linked with objcopy.o to flag that this program is 'strip' (not - 'objcopy'). */ - -int is_strip = 1; +#define is_strip 1 +#include "objcopy.c" diff --git a/binutils/not-strip.c b/binutils/not-strip.c index 5c7284852ad..9e39da42564 100644 --- a/binutils/not-strip.c +++ b/binutils/not-strip.c @@ -17,7 +17,5 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -/* Linked with objcopy.o to flag that this program is 'objcopy' (not - 'strip'). */ - -int is_strip = 0; +#define is_strip 0 +#include "objcopy.c" diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 572f22c9d36..1cc4fe4876f 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -533,7 +533,9 @@ extern char *program_name; /* This flag distinguishes between strip and objcopy: 1 means this is 'strip'; 0 means this is 'objcopy'. -1 means if we should use argv[0] to decide. */ +#ifndef is_strip extern int is_strip; +#endif /* The maximum length of an S record. This variable is defined in srec.c and can be modified by the --srec-len parameter. */ @@ -6222,6 +6224,7 @@ main (int argc, char *argv[]) fatal (_("fatal error: libbfd ABI mismatch")); set_default_bfd_target (); +#ifndef is_strip if (is_strip < 0) { int i = strlen (program_name); @@ -6235,6 +6238,7 @@ main (int argc, char *argv[]) #endif is_strip = (i >= 5 && FILENAME_CMP (program_name + i - 5, "strip") == 0); } +#endif /* is_strip */ create_symbol_htabs (); xatexit (delete_symbol_htabs);