tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: disabling the LTO without command-line flags?



At Wed, 12 Jul 2017 13:20:06 -0700, "Greg A. Woods" <woods%planix.ca@localhost> wrote:
Subject: disabling the LTO without command-line flags?
> 
> So, I need to disable the link-time optimizer in LD (and ideally disable
> it in GCC too, to avoid unusable bloat in the generated object files).
> 
> I also need to do this without use of any command-line flags anywhere.

So, I took the obvious path and wrote a wrapper script for 'cc' et al:

	#!/bin/sh
	
	exec /usr/bin/$(basename ${0})-ORIG -fno-lto -fno-use-linker-plugin ${1+"${@}"}

(it's needed for cc, gcc, c++, and g++)

(the basename tom-foolery seems to be needed with pkgsrc's own wrapper)

The following patch fixes the problem I noted before, i.e. it prevents
'ld' itself from barfing on the "-fno-lto" option which GCC
oh-so-helpfully passes on to it, thus making the wrapper an effective
solution.

Index: external/gpl3/binutils/dist/ld/lexsup.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/external/gpl3/binutils/dist/ld/lexsup.c,v
retrieving revision 1.5
diff -u -r1.5 lexsup.c
--- external/gpl3/binutils/dist/ld/lexsup.c	29 Jan 2016 14:42:47 -0000	1.5
+++ external/gpl3/binutils/dist/ld/lexsup.c	12 Jul 2017 20:31:46 -0000
@@ -172,6 +172,9 @@
   { {"flto", optional_argument, NULL, OPTION_IGNORE},
     '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
     ONE_DASH },
+  { {"fno-lto", optional_argument, NULL, OPTION_IGNORE},
+    '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
+    ONE_DASH },
   { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
     '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
     ONE_DASH },


So far I have been able to re-run "nbmake native-binutils" with
additions to turn of LTO and I think my changes have had effect.
(ldgram.y and ldlex.l were rebuilt with yacc & lex, but so far that
seems to be OK)

However I've been unsuccessful so far at re-configuring GCC itself.  Its
configure script seems to ignore "--disable-lto", at least in the way
that "make native-gcc" hands it to it.

Here's more or less where I'm at:

Index: tools/Makefile.gnuhost
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/tools/Makefile.gnuhost,v
retrieving revision 1.44
diff -u -r1.44 Makefile.gnuhost
--- tools/Makefile.gnuhost	16 Jan 2016 18:38:53 -0000	1.44
+++ tools/Makefile.gnuhost	8 Aug 2017 04:39:29 -0000
@@ -49,6 +49,14 @@
 .MAKEOVERRIDES+= _GNU_CFGSRC
 .endif
 
+.if defined(HOST_LDFLAGS) && defined(HOST_LDSTATIC)
+. if empty(HOST_LDFLAGS:M*${HOST_LDSTATIC}*)
+HOST_LDFLAGS+=		${HOST_LDSTATIC}
+. endif
+.elif !defined(HOST_LDFLAGS) && defined(HOST_LDSTATIC)
+HOST_LDFLAGS=		${HOST_LDSTATIC}
+.endif
+
 CONFIGURE_ENV+= \
 		AR=${HOST_AR:Q} \
 		AWK=${TOOL_AWK:Q} \
@@ -60,6 +68,7 @@
 		CXXFLAGS=${HOST_CXXFLAGS:Q} \
 		INSTALL=${HOST_INSTALL_FILE:Q} \
 		LDFLAGS=${HOST_LDFLAGS:Q} \
+		LDSTATIC=${HOST_LDSTATIC:Q} \
 		LEX=${LEX:Q} \
 		M4=${TOOL_M4:Q} \
 		MAKE=${MAKE_PROGRAM:Q} \
@@ -71,7 +80,22 @@
 
 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
 .if ${MKPIC} == "no"
-CONFIGURE_ARGS+=--disable-shared
+CONFIGURE_ARGS+= --disable-shared
+.endif
+
+.if defined(HOST_LDSTATIC) && !empty(HOST_LDSTATIC)
+CONFIGURE_ARGS+= --enable-static
+.endif
+
+MAKE_ENV+=		CFLAGS=${HOST_CFLAGS:Q}
+MAKE_ENV+=		CPPFLAGS=${HOST_CPPFLAGS:Q}
+MAKE_ENV+=		LDFLAGS=${HOST_LDFLAGS:Q}
+MAKE_ENV+=		LDSTATIC=${HOST_LDLDSTATIC:Q}
+
+.if defined(HOST_LDSTATIC) && !empty(HOST_LDSTATIC) && defined(USE_LIBTOOL)
+# work around libtool brain-damage
+# xxx this doesn't always work very well....  (see also src/tools/binutils/Makefile which uses "--static", two hyphens)
+MAKE_ARGS+=	LDFLAGS="${HOST_LDSTATIC} -all-static"
 .endif
 
 .if ${MAKE_PROGRAM} == ${MAKE}


Index: tools/binutils/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/tools/binutils/Makefile,v
retrieving revision 1.25
diff -u -r1.25 Makefile
--- tools/binutils/Makefile	26 Jan 2016 17:47:57 -0000	1.25
+++ tools/binutils/Makefile	8 Aug 2017 04:39:48 -0000
@@ -11,7 +11,15 @@
 	--with-bugurl="http://www.NetBSD.org/support/send-pr.html"; \
 	--with-lib-path="=/usr/lib" --with-sysroot
 
-CONFIGURE_ARGS=	--target=${MACHINE_GNU_PLATFORM} --disable-nls \
+# xxx hmmmm.....  this would be correct except it doesn't work for sub-dir configure
+#USE_LIBTOOL =	yes
+
+.if defined(HOST_LDSTATIC) && !empty(HOST_LDSTATIC)
+# obviously the LTO plugin can't be loaded if the 'ld' binary is static-linked!
+CONFIGURE_ARGS+= --disable-lto
+.endif
+
+CONFIGURE_ARGS+= --target=${MACHINE_GNU_PLATFORM} --disable-nls \
 		--program-transform-name="s,^,${MACHINE_GNU_PLATFORM}-," \
 		--disable-werror \
 		${BRANDING}
@@ -34,6 +42,11 @@
 
 .include "${.CURDIR}/../Makefile.gnuhost"
 
+.if defined(HOST_LDSTATIC) && !empty(HOST_LDSTATIC)
+# xxx try to fool libtool, but note that -all-static won't work here!
+MAKE_ARGS+=	LDFLAGS="${HOST_LDSTATIC} --static"
+.endif
+
 CCADDFLAGS=	-I${DESTDIR}/usr/include -L${DESTDIR}/lib -L${DESTDIR}/usr/lib -B${DESTDIR}/usr/lib/
 
 # Force avoiding possibly non-executable install-sh.
@@ -42,11 +55,16 @@
 NEWCONFIGDIR?=	${.CURDIR}/../..
 MKNATIVE?=	${.CURDIR}/mknative-binutils
 
+.if defined(LDSTATIC) && !empty(LDSTATIC)
+NATIVE_CONFIGURE_ARGS+= --disable-lto
+.endif
+
 native-binutils: .native/.configure_done
 	@echo 'Extracting GNU binutils configury for a native toolchain.'
 	MAKE=${MAKE:Q} ${HOST_SH} ${MKNATIVE} binutils \
 		${.OBJDIR}/.native ${NEWCONFIGDIR} ${MACHINE_GNU_PLATFORM}
 
+# XXX hmmm....  not passing *FLAGS, LDFLAGS in particular, is worrying
 .native/.configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile
 	mkdir .native 2>/dev/null || true
 	PATH=${TOOLDIR}/bin:$$PATH; export PATH; \
@@ -65,6 +83,7 @@
 			--build=`${GNUHOSTDIST}/config.guess` \
 			--host=${MACHINE_GNU_PLATFORM} \
 			--target=${MACHINE_GNU_PLATFORM} \
+			${NATIVE_CONFIGURE_ARGS} \
 			${BRANDING} \
 		)
 	PATH=${TOOLDIR}/bin:$$PATH; export PATH; \



Index: tools/gcc/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/tools/gcc/Makefile,v
retrieving revision 1.80
diff -u -r1.80 Makefile
--- tools/gcc/Makefile	26 Mar 2016 09:02:56 -0000	1.80
+++ tools/gcc/Makefile	8 Aug 2017 22:33:13 -0000
@@ -13,7 +13,7 @@
 .endif
 
 # Defaults
-CC_FOR_BUILD=		${HOST_CXX:Q}
+CC_FOR_BUILD=		${HOST_CC:Q}
 MKNATIVE?=		${.CURDIR}/mknative-gcc
 
 .if ${MACHINE_ARCH} == "x86_64" || ${MACHINE_ARCH} == "sparc64"
@@ -45,10 +45,6 @@
 COMMON_CONFIGURE_ARGS+=	--with-tune=${GCC_CONFIG_TUNE.${MACHINE_ARCH}}
 .endif
 
-.if ${HAVE_GCC} == 48
-COMMON_CONFIGURE_ARGS+= --enable-lto
-.endif
-
 .if ${HAVE_GCC} == 53
 # Turn on colour output only if GCC_COLORS env is set
 COMMON_CONFIGURE_ARGS+= --with-diagnostics-color=auto-if-env
@@ -66,6 +62,14 @@
 		--program-transform-name="s,^,${MACHINE_GNU_PLATFORM}-," \
 		--enable-languages="${GCC_LANGUAGES}"
 
+.if ${HAVE_GCC} == 48
+.if !defined(HOST_LDSTATIC) || empty(HOST_LDSTATIC))
+CONFIGURE_ARGS+= --enable-lto
+.else
+CONFIGURE_ARGS+= --disable-lto
+.endif
+.endif
+
 GCC_CPPFLAGS=	-DNETBSD_TOOLS -DTARGET_SYSTEM_ROOT=0 \
 		-DTARGET_SYSTEM_ROOT_RELOCATABLE
 
@@ -163,6 +168,14 @@
 
 GMP_MACHINE_ARCH?=	${MACHINE_ARCH:S/earmv4/arm/:C/armv[5-7]/arm/}
 
+.if ${HAVE_GCC} == 48
+.if !defined(LDSTATIC) || empty(LDSTATIC)
+NATIVE_CONFIGURE_ARGS+= --enable-lto
+.else
+NATIVE_CONFIGURE_ARGS+= --disable-lto
+.endif
+.endif
+
 NATIVE_CONFIGURE_ARGS+=	\
 			--with-mpc-lib=${MPCOBJ} \
 			--with-mpfr-lib=${MPFROBJ} \


-- 
					Greg A. Woods <gwoods%acm.org@localhost>

+1 250 762-7675                           RoboHack <woods%robohack.ca@localhost>
Planix, Inc. <woods%planix.com@localhost>     Avoncote Farms <woods%avoncote.ca@localhost>

Attachment: pgpzvs1YJpwIB.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index