Skip to contentSkip to conversation

gcc: explicitly use C{XX}FLAGS_FOR_TARGET instead of --enable-target-optspace

PATCH Superseded Alexey Brodkin 2 participants 3 messages Aug 28, 2014 – Sep 1, 2014

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gcc: explicitly use C{XX}FLAGS_FOR_TARGET instead of --enable-target-optspace

The gcc.mk file is passing --enable-target-optspace to gcc configure script, to ask for space-optimized (-Os) target libraries. However, passing this option has the effect of overriding any custom CFLAGS_FOR_TARGET or CXXFLAGS_FOR_TARGET values that may be passed.

These are some situations when it is required to pass custom flags on buildong of libgcc:
* Default flags "-g -Os" lead to build isses as with PowerPC on gcc 4.5
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43810)
* Particular CPU requires specific instructions for HW support
* Deep optimizations

Cc Anton Kolesov <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Gustavo Zacarias <[email protected]>

---
Compared to v1:
1) All changes are implemented in common part so applicable to all stages.
2) Comments doesn't contain separators that confuse Patchwork
3) Use TARGET_C{XX}FLAGS instead of pre-defined -O2 or -Os

---
 package/gcc/gcc.mk | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
package/gcc/gcc.mk +6 -3
index b344a14..95c15e2 100644
@@ -111,12 +111,15 @@ HOST_GCC_COMMON_CONF_ENV = \
 # Workaround until it's fixed in 4.5.4 or later
 ifeq ($(ARCH),powerpc)
 ifeq ($(findstring x4.5.,x$(GCC_VERSION)),x4.5.)
-HOST_GCC_COMMON_CONF_OPT += --disable-target-optspace
+TARGET_CFLAGS := $(subst -Os,,$(TARGET_CFLAGS))
+TARGET_CXXFLAGS := $(subst -Os,,$(TARGET_CXXFLAGS))
 endif
-else
-HOST_GCC_COMMON_CONF_OPT += --enable-target-optspace
 endif
 
+# Propagate options used for target software building to GCC target libs
+HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
+HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(TARGET_CXXFLAGS)"
+
 # gcc 4.6.x quadmath requires wchar
 ifneq ($(BR2_TOOLCHAIN_BUILDROOT_WCHAR),y)
 HOST_GCC_COMMON_CONF_OPT += --disable-libquadmath
Signature · 1 line
1.9.3
#1 lore raw

PATCH v2 1/1 gcc: explicitly use C{XX}FLAGS_FOR_TARGET instead of --enable-target-optspace

Dear Alexey Brodkin,

package/gcc/gcc.mk HOST_GCC_COMMON_CONF_ENV = \ · line 115

Quoted 7 lines · Alexey Brodkin
package/gcc/gcc.mk +2 -1
@@ -111,12 +111,15 @@ HOST_GCC_COMMON_CONF_ENV = \
 # Workaround until it's fixed in 4.5.4 or later
 ifeq ($(ARCH),powerpc)
 ifeq ($(findstring x4.5.,x$(GCC_VERSION)),x4.5.)
-HOST_GCC_COMMON_CONF_OPT += --disable-target-optspace
+TARGET_CFLAGS := $(subst -Os,,$(TARGET_CFLAGS))
+TARGET_CXXFLAGS := $(subst -Os,,$(TARGET_CXXFLAGS))

No. Remember that the namespace of variables is global in Buildroot. A given package is clearly *not* allowed to change global variables such as TARGET_CFLAGS and TARGET_CXXFLAGS. If you want to remove -Os just for gcc, you should do:

GCC_TARGET_CFLAGS = $(TARGET_CFLAGS)

ifeq (powerpc ... your condition ...) GCC_TARGET_CFLAGS = $(filter-out -Os,$(GCC_TARGET_CFLAGS)) endif

HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_TARGET_CFLAGS)"

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH v2 1/1 gcc: explicitly use C{XX}FLAGS_FOR_TARGET instead of --enable-target-optspace

Hi Thomas,

Quoted 4 lines · Thomas Petazzoni

Dear Alexey Brodkin,

On Thu, 28 Aug 2014 16:59:18 +0400, Alexey Brodkin wrote:

Quoted 12 lines

package/gcc/gcc.mk HOST_GCC_COMMON_CONF_ENV = \ · line 115

Quoted 7 lines
package/gcc/gcc.mk +2 -1
@@ -111,12 +111,15 @@ HOST_GCC_COMMON_CONF_ENV = \
 # Workaround until it's fixed in 4.5.4 or later
 ifeq ($(ARCH),powerpc)
 ifeq ($(findstring x4.5.,x$(GCC_VERSION)),x4.5.)
-HOST_GCC_COMMON_CONF_OPT += --disable-target-optspace
+TARGET_CFLAGS := $(subst -Os,,$(TARGET_CFLAGS))
+TARGET_CXXFLAGS := $(subst -Os,,$(TARGET_CXXFLAGS))

No. Remember that the namespace of variables is global in Buildroot. A given package is clearly *not* allowed to change global variables such as TARGET_CFLAGS and TARGET_CXXFLAGS. If you want to remove -Os just for gcc, you should do:

Hm, I was under impression that variables are visible only within "package/name" and according to hierarchy.

Now it's clear they are all global - will keep it in mind then.

Already smoke-testing v3 and will send it to the list shortly.

-Alexey