Skip to contentSkip to conversation

poison TARGET_CFLAGS etc for native builds

PATCH In review Andre McCurdy 3 participants 7 messages Feb 27, 2016

lore
Share & tools
lore
#0 lore raw

cover poison TARGET_CFLAGS etc for native builds

The first patch fixes known problems with grub-efi-native incorrectly leaking target flags into the native build.

The second and third patches fix related grub2.inc issues.

The final patch is the important change. It doesn't highlight and new problems (ie apart from grub-efi-native) for my typical builds, but needs wider testing.

Andre McCurdy (4):
grub2.inc: dont export TARGET_CFLAGS etc to grub2 configure grub2.inc: avoid passing -isystem to native builds grub2.inc: drop bogus dependency on xz native.bbclass: poison TARGET_CFLAGS etc for native builds

 meta/classes/native.bbclass     | 16 ++++++++++++----
 meta/recipes-bsp/grub/grub2.inc | 19 +++++++++++++++++--
 2 files changed, 29 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 grub2.inc: dont export TARGET_CFLAGS etc to grub2 configure

The grub2 configure script uses variables such as TARGET_CFLAGS etc for its own purposes. Remove the OE versions from the configure environment to avoid conflicts.

---
 meta/recipes-bsp/grub/grub2.inc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
meta/recipes-bsp/grub/grub2.inc +7 -1
index 84a4727..5a12563 100644
@@ -44,10 +44,16 @@ PACKAGECONFIG ??= ""
 PACKAGECONFIG[grub-mount] = "--enable-grub-mount,--disable-grub-mount,fuse"
 PACKAGECONFIG[device-mapper] = "--enable-device-mapper,--disable-device-mapper,lvm2"
 
+do_configure_prepend() {
+	# The grub2 configure script uses variables such as TARGET_CFLAGS etc
+	# for its own purposes. Remove the OE versions from the environment to
+	# avoid conflicts.
+	unset TARGET_CPPFLAGS TARGET_CFLAGS TARGET_CXXFLAGS TARGET_LDFLAGS
+}
+
 # grub and grub-efi's sysroot/${datadir}/grub/grub-mkconfig_lib are
 # conflicted, remove it since no one uses it.
 SYSROOT_PREPROCESS_FUNCS_class-target += "remove_sysroot_mkconfig_lib"
 remove_sysroot_mkconfig_lib() {
     rm -r "${SYSROOT_DESTDIR}${datadir}/grub/grub-mkconfig_lib"
 }
-
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 grub2.inc: avoid passing -isystem to native builds

In reply to Andre McCurdy

grub2 creates its own set of -nostdinc / -isystem / -ffreestanding CFLAGS and OE's default BUILD_CFLAGS (assigned to CFLAGS for native builds) etc, conflict with that.

---
 meta/recipes-bsp/grub/grub2.inc | 9 +++++++++
 1 file changed, 9 insertions(+)
meta/recipes-bsp/grub/grub2.inc +9 -0
index 5a12563..0fdafd5 100644
@@ -44,6 +44,15 @@ PACKAGECONFIG ??= ""
 PACKAGECONFIG[grub-mount] = "--enable-grub-mount,--disable-grub-mount,fuse"
 PACKAGECONFIG[device-mapper] = "--enable-device-mapper,--disable-device-mapper,lvm2"
 
+# grub2 creates its own set of -nostdinc / -isystem / -ffreestanding CFLAGS and
+# OE's default BUILD_CFLAGS (assigned to CFLAGS for native builds) etc, conflict
+# with that. Note that since BUILD_CFLAGS etc are not used by grub2 target
+# builds, it's safe to clear them unconditionally for both target and native.
+BUILD_CPPFLAGS = ""
+BUILD_CFLAGS = ""
+BUILD_CXXFLAGS = ""
+BUILD_LDFLAGS = ""
+
 do_configure_prepend() {
 	# The grub2 configure script uses variables such as TARGET_CFLAGS etc
 	# for its own purposes. Remove the OE versions from the environment to
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/4 grub2.inc: drop bogus dependency on xz

In reply to Andre McCurdy

grub contains it's own internal lzma library. Attempting to build grub against the system liblzma shared library or header files is not likely to end well.

This change does not cause a floating dependency since all grub2.inc based recipes pass "--enable-liblzma=no" to configure.

---
 meta/recipes-bsp/grub/grub2.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-bsp/grub/grub2.inc +1 -1
index 0fdafd5..12cff4f 100644
@@ -31,7 +31,7 @@ SRC_URI = "ftp://ftp.gnu.org/gnu/grub/grub-${PV}.tar.gz \
            file://0001-Remove-direct-_llseek-code-and-require-long-filesyst.patch \
             "
 
-DEPENDS = "flex-native bison-native xz"
+DEPENDS = "flex-native bison-native"
 
 SRC_URI[md5sum] = "e927540b6eda8b024fb0391eeaa4091c"
 SRC_URI[sha256sum] = "65b39a0558f8c802209c574f4d02ca263a804e8a564bc6caf1cd0fd3b3cc11e3"
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/4 native.bbclass: poison TARGET_CFLAGS etc for native builds

In reply to Andre McCurdy

TARGET_* FLAGS are never passed to the native toolchain. However, they are exported so their values affect the checksum of every task.

Replace with fixed values to both avoid any unnecessary rebuilding of native packages when target flags are changed (as before) and now also to poison any accidental use of target flags with the native toolchain.

---
 meta/classes/native.bbclass | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
meta/classes/native.bbclass +12 -4
index f67ef00..34c08b2 100644
@@ -26,10 +26,18 @@ TARGET_PREFIX = "${BUILD_PREFIX}"
 TARGET_CC_ARCH = "${BUILD_CC_ARCH}"
 TARGET_LD_ARCH = "${BUILD_LD_ARCH}"
 TARGET_AS_ARCH = "${BUILD_AS_ARCH}"
-TARGET_CPPFLAGS = "${BUILD_CPPFLAGS}"
-TARGET_CFLAGS = "${BUILD_CFLAGS}"
-TARGET_CXXFLAGS = "${BUILD_CXXFLAGS}"
-TARGET_LDFLAGS = "${BUILD_LDFLAGS}"
+
+# TARGET_* FLAGS are never passed to the native toolchain. However, they are
+# exported so their values affect the checksum of every task. Replace with fixed
+# values to both avoid any unnecessary rebuilding of native packages when target
+# flags are changed and to poison any accidental use of target flags with the
+# native toolchain.
+TARGET_CPPFLAGS = "--target-cppflag-never-passed-to-the-native-toolchain"
+TARGET_CFLAGS = "--target-cflag-never-passed-to-the-native-toolchain"
+TARGET_CXXFLAGS = "--target-cxxflag-never-passed-to-the-native-toolchain"
+TARGET_LDFLAGS = "--target-ldflag-never-passed-to-the-native-toolchain"
+
+# Hardcoding is OK since native always implies x86 or x86-64.
 TARGET_FPU = ""
 
 HOST_ARCH = "${BUILD_ARCH}"
Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH 4/4] native.bbclass: poison TARGET_CFLAGS etc for native builds

Quoted 35 lines · Andre McCurdy

TARGET_* FLAGS are never passed to the native toolchain. However, they are exported so their values affect the checksum of every task.

Replace with fixed values to both avoid any unnecessary rebuilding of native packages when target flags are changed (as before) and now also to poison any accidental use of target flags with the native toolchain.

---
 meta/classes/native.bbclass | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
meta/classes/native.bbclass +2 -4
index f67ef00..34c08b2 100644
@@ -26,10 +26,18 @@ TARGET_PREFIX = "${BUILD_PREFIX}"
 TARGET_CC_ARCH = "${BUILD_CC_ARCH}"
 TARGET_LD_ARCH = "${BUILD_LD_ARCH}"
 TARGET_AS_ARCH = "${BUILD_AS_ARCH}"
-TARGET_CPPFLAGS = "${BUILD_CPPFLAGS}"
-TARGET_CFLAGS = "${BUILD_CFLAGS}"
-TARGET_CXXFLAGS = "${BUILD_CXXFLAGS}"
-TARGET_LDFLAGS = "${BUILD_LDFLAGS}"
+
+# TARGET_* FLAGS are never passed to the native toolchain. However,

they are
+# exported so their values affect the checksum of every task. Replace with fixed
+# values to both avoid any unnecessary rebuilding of native packages when target
+# flags are changed and to poison any accidental use of target flags with the

meta/classes/native.bbclass

Quoted 9 lines
meta/classes/native.bbclass +5 -4
+# native toolchain.
+TARGET_CPPFLAGS = "--target-cppflag-never-passed-to-the-native
-toolchain"
+TARGET_CFLAGS = "--target-cflag-never-passed-to-the-native
-toolchain"
+TARGET_CXXFLAGS = "--target-cxxflag-never-passed-to-the-native
-toolchain"
+TARGET_LDFLAGS = "--target-ldflag-never-passed-to-the-native
-toolchain"

Wouldn't it perhaps be nicer just to unexport these?

I think

TARGET_CPPFLAGS[unexport] = "1"

might do it or we could do:

delvarFlag("TARGET_CPPFLAGS", "export")

?

Regardless of approach, this is likely going to need some extensive testing.

Cheers,

Richard

#6 lore raw

Re: [PATCH 4/4] native.bbclass: poison TARGET_CFLAGS etc for native builds

Quoted 6 lines · Richard Purdie

Wouldn't it perhaps be nicer just to unexport these?

I think

TARGET_CPPFLAGS[unexport] = "1"

Quoted 9 lines

might do it or we could do:

delvarFlag("TARGET_CPPFLAGS", "export")

?

Regardless of approach, this is likely going to need some extensive testing.

Unexporting is certainly neater, but a world build with poisoned flags would certainly catch anything that's doing it wrong (openjdk for example appears to be passing build cflags to host g++).

Ross