From 1a18ab420b6098b92f3a16db68e482682a506688 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 11 Aug 2020 16:46:27 +0000 Subject: [PATCH] Allow overriding the tool used for stripping binaries Since the make variable STRIP is already used for other purposes, this uses STRIPBIN (which is also used for the same purpose by install(1). This allows using LLVM objcopy to strip binaries instead of the in-tree elftoolchain objcopy. We make use of this in CheriBSD since passing binaries generated by our toolchain to elftoolchain strip sometimes results in assertion failures. This allows working around https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=248516 by specifying STRIPBIN=/path/to/llvm-strip Obtained from: CheriBSD Reviewed By: emaste, brooks Differential Revision: https://reviews.freebsd.org/D25988 --- Makefile.inc1 | 4 ++-- share/mk/sys.mk | 1 + stand/i386/loader/Makefile | 2 +- sys/modules/linux/Makefile | 4 ++-- sys/modules/linux64/Makefile | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 313adf85cb9..f85f0326da2 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -180,7 +180,7 @@ MK_SYSTEM_LINKER= no .if defined(CROSS_TOOLCHAIN_PREFIX) CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX} .endif -XBINUTILS= AS AR LD NM OBJCOPY RANLIB SIZE STRINGS +XBINUTILS= AS AR LD NM OBJCOPY RANLIB SIZE STRINGS STRIPBIN .for BINUTIL in ${XBINUTILS} .if defined(CROSS_BINUTILS_PREFIX) && \ exists(${CROSS_BINUTILS_PREFIX}/${${BINUTIL}}) @@ -755,7 +755,7 @@ CROSSENV+= CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \ AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \ NM=${XNM} OBJCOPY="${XOBJCOPY}" \ RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \ - SIZE="${XSIZE}" + SIZE="${XSIZE}" STRIPBIN="${XSTRIPBIN}" .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX}) # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a diff --git a/share/mk/sys.mk b/share/mk/sys.mk index 2248d64f658..215b04563e2 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -275,6 +275,7 @@ SHELL ?= sh .if !defined(%POSIX) SIZE ?= size +STRIPBIN ?= strip .endif YACC ?= yacc diff --git a/stand/i386/loader/Makefile b/stand/i386/loader/Makefile index b74ef9007d9..3c0357b7b7a 100644 --- a/stand/i386/loader/Makefile +++ b/stand/i386/loader/Makefile @@ -64,7 +64,7 @@ ${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN} -b ${BTXKERN} ${LOADER}.bin ${LOADER}.bin: ${LOADER}.sym - strip -R .comment -R .note -o ${.TARGET} ${.ALLSRC} + ${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC} .if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/zfsloader diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile index 7065c1f0f6c..c91dfbdaf38 100644 --- a/sys/modules/linux/Makefile +++ b/sys/modules/linux/Makefile @@ -69,12 +69,12 @@ linux${SFX}_support.o: linux${SFX}_assym.h assym.inc ${VDSO}.so: linux${SFX}_locore.o ${OBJCOPY} --input-target binary --output-target elf64-x86-64-freebsd \ --binary-architecture i386 linux${SFX}_locore.o ${.TARGET} - strip -N _binary_linux${SFX}_locore_o_size ${.TARGET} + ${STRIPBIN} -N _binary_linux${SFX}_locore_o_size ${.TARGET} .else ${VDSO}.so: linux${SFX}_locore.o ${OBJCOPY} --input-target binary --output-target elf32-i386-freebsd \ --binary-architecture i386 linux${SFX}_locore.o ${.TARGET} - strip -N _binary_linux_locore_o_size ${.TARGET} + ${STRIPBIN} -N _binary_linux_locore_o_size ${.TARGET} .endif linux${SFX}_genassym.o: offset.inc diff --git a/sys/modules/linux64/Makefile b/sys/modules/linux64/Makefile index 046eeeda30f..33dccc90770 100644 --- a/sys/modules/linux64/Makefile +++ b/sys/modules/linux64/Makefile @@ -46,7 +46,7 @@ OBJCOPY_TARGET=--output-target elf64-x86-64 --binary-architecture i386:x86-64 ${VDSO}.so: linux_locore.o ${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} -S -g \ linux_locore.o ${.TARGET} - strip -N _binary_linux_locore_o_size ${.TARGET} + ${STRIPBIN} -N _binary_linux_locore_o_size ${.TARGET} linux_support.o: assym.inc linux_assym.h ${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \