Gentoo Archives: gentoo-dev

From: Gavin <gavin@××××.com>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] RFC: factoring logic for selection of "safe" gcc -O flags in ebuilds (uclibc users take note)
Date: Thu, 22 Jul 2004 20:47:34
Message-Id: 011801c4702d$1c4c2cd0$0500a8c0@EPOX2
In Reply to: Re: [gentoo-dev] Kernel sources thread by Mike Frysinger
1 Problem
2 ===========
3 Many ebuilds force gcc to use "-O2" instead of other, possibly viable values. For example, "-Os" does work in some circumstances for certain ebuilds that currently force the use of "-O2". Those using uclibc and/or CPUs with small caches might prefer "-Os". However, maintaining a clone of an ebuild in a portage overlay directory for the sole purpose of changing "replace-flags -O? -O2" to "replace-flags -O? -Os" present users with an unecessary hassle.
4
5 Proposed Solution
6 ====================
7 Are ebuilds the best place to make the decision regarding which optimization is "safe" for the target system? Perhaps we can factor and encapsulate the logic into flag-o-matic?
8
9 As a first step, what if we add 'SAFE_GCC_O_FLAG="-O2"' to /etc/make.globals? It might be a long time before we could expect everyone using new ebuilds to have a make.global with SAFE_GCC_O_FLAG defined. Ideally, an appropriate default might be automatically determined, but I want a super simple, first step solution.
10
11 /usr/portage/eclass/flag-o-matic.eclass:
12 # credits to Martin Schlemmer's input (see http://bugs.gentoo.org/show_bug.cgi?id=57223)
13 replace-with-safe-gcc-o-flag() {
14 [ -z "${SAFE_GCC_O_FLAG}" ] && SAFE_GCC_O_FLAG="-O2"
15 CFLAGS="${CFLAGS//-O?/ } ${SAFE_GCC_O_FLAG}"
16 CXXFLAGS="${CXXFLAGS//-O?/ } ${SAFE_GCC_O_FLAG}"
17 export CFLAGS CXXFLAGS
18 return 0
19 }
20
21 Alternative (less efficient, but less code):
22 replace-with-safe-gcc-o-flag() {
23 [ -z "${SAFE_GCC_O_FLAG}" ] && SAFE_GCC_O_FLAG="-O2"
24 replace-flags -O? ${SAFE_GCC_O_FLAG}"
25 return 0
26 }
27
28 # appends SAFE_GCC_O_FLAG to "emerge info" results:
29 --- /usr/lib/portage/bin/emerge.orig 2004-07-17 09:13:48.690078831 -0700
30 +++ /usr/lib/portage/bin/emerge 2004-07-17 09:14:08.067093698 -0700
31 @@ -2314,7 +2314,7 @@
32 myvars=['GENTOO_MIRRORS', 'CONFIG_PROTECT', 'CONFIG_PROTECT_MASK',
33 'PORTDIR', 'DISTDIR', 'PKGDIR', 'PORTAGE_TMPDIR', 'PORTDIR_OVERLAY',
34 'USE', 'COMPILER', 'CHOST', 'CFLAGS', 'CXXFLAGS','ACCEPT_KEYWORDS',
35 - 'MAKEOPTS', 'AUTOCLEAN', 'SYNC', 'FEATURES']
36 + 'MAKEOPTS', 'AUTOCLEAN', 'SYNC', 'FEATURES', 'SAFE_GCC_O_FLAG']
37 myvars.sort()
38 for x in myvars:
39 print x+'="'+portage.settings[x]+'"'
40
41
42 --
43 gentoo-dev@g.o mailing list

Replies