aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2025-04-04 10:19:51 +0200
committerJan Beulich <jbeulich@suse.com>2025-04-04 10:19:51 +0200
commit2fb3d389d83f0ea1ac9a8d346884ffdb41e4fbb8 (patch)
tree1972f07c46481ec75f0a2358d217393d31888e17
parentc619da1a22fcc67654b6c7860272aa2ce5deadaa (diff)
downloadbinutils-2fb3d389d83f0ea1ac9a8d346884ffdb41e4fbb8.zip
binutils-2fb3d389d83f0ea1ac9a8d346884ffdb41e4fbb8.tar.gz
binutils-2fb3d389d83f0ea1ac9a8d346884ffdb41e4fbb8.tar.bz2
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.
-rw-r--r--binutils/Makefile.am4
-rw-r--r--binutils/Makefile.in12
-rw-r--r--binutils/is-strip.c6
-rw-r--r--binutils/not-strip.c6
-rw-r--r--binutils/objcopy.c4
5 files changed, 16 insertions, 16 deletions
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index 20c711a..243b38c 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 8029bc2..c2c31bf 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 26aeaf0..4ac1035 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 5c72848..9e39da4 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 572f22c..1cc4fe4 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);