Skip to contentSkip to conversation

c-ares: use our compilation flags

PATCH In review [email protected] 3 participants 8 messages Jul 18, 2016 – Jul 21, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 c-ares: use our compilation flags

From: André Draszik <[email protected]>

If not requested otherwise as ./configure option, c-ares will strip any -g from CFLAGS / CPPFLAGS and add -g0 instead, disabling all debug info.
Similarly, it will try to enable optimisation (but bail out since in that case it honors an existing -O in CFLAGS / CPPFLAGS)

Since we want to control code generation, patch out the code mangling -g (and -O for consistency). Alternatively, if we were to pass --enable-debug to ./configure, c-ares would at the same time assume that we don't want optimisation anymore.

---
 ...configure.ac-don-t-override-passed-cflags.patch | 26 ++++++++++++++++++++++
 .../recipes-support/c-ares/c-ares_1.11.0.bb        |  4 +++-
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 meta-networking/recipes-support/c-ares/c-ares/0001-configure.ac-don-t-override-passed-cflags.patch
meta-networking/recipes-support/c-ares/c-ares/0001-configure.ac-don-t-override-passed-cflags.patch new file +26 -0
new file mode 100644
index 0000000..10fad4e
@@ -0,0 +1,26 @@
+From 2a7236d2a7bb9c3d3c3f44ebf59404bf7134fcb3 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andr=C3=A9=20Draszik?= <[email protected]>
+Date: Tue, 12 Apr 2016 11:37:28 +0100
+Subject: [PATCH] configure.ac: don't override passed cflags
+
+We are controlling debug and optimiser flags from OE
+---
+ configure.ac | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 5c02450..3cf9fcd 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -147,8 +147,6 @@ dnl **********************************************************************
+ 
+ CARES_CHECK_COMPILER
+ CARES_SET_COMPILER_BASIC_OPTS
+-CARES_SET_COMPILER_DEBUG_OPTS
+-CARES_SET_COMPILER_OPTIMIZE_OPTS
+ CARES_SET_COMPILER_WARNING_OPTS
+ 
+ if test "$compiler_id" = "INTEL_UNIX_C"; then
+-- 
+2.8.0.rc3
+
meta-networking/recipes-support/c-ares/c-ares_1.11.0.bb +3 -1
index 2f72ab4..c98be7d 100644
@@ -6,7 +6,9 @@ SECTION = "libs"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://ares_init.c;beginline=1;endline=3;md5=53f5ecf4c22c37cf1ddd1ef8f8eccce0"
 
-SRC_URI = "http://c-ares.haxx.se/download/${BP}.tar.gz"
+SRC_URI = "http://c-ares.haxx.se/download/${BP}.tar.gz \
+           file://0001-configure.ac-don-t-override-passed-cflags.patch \
+"
 SRC_URI[md5sum] = "d5c6d522cfc54bb6f215a0b7912d46be"
 SRC_URI[sha256sum] = "b3612e6617d9682928a1d50c1040de4db6519f977f0b25d40cf1b632900b3efd"
 
Signature · 1 line
2.8.1
#1 lore raw

PATCH v2 2/2 meta-networking: override SECURITY_CFLAGS for c-ares

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Fix this by providing an additional include file that is require'd from conf/layer.conf which for c-ares moves the defines added by security_flags.inc from CFLAGS to CPPFLAGS.

---
 .../conf/distro/include/meta_networking_security_flags.inc          | 6 ++++++
 meta-networking/conf/layer.conf                                     | 3 +++
 2 files changed, 9 insertions(+)
 create mode 100644 meta-networking/conf/distro/include/meta_networking_security_flags.inc
meta-networking/conf/distro/include/meta_networking_security_flags.inc new file +6 -0
new file mode 100644
index 0000000..06802d6
@@ -0,0 +1,6 @@
+# configure righteously complains:
+# | configure:3479: using CFLAGS:  -O2 -pipe -g -feliminate-unused-debug-types -fstack-protector-strong -pie -fpie -D_FORTIFY_SOURCE=2
+# | configure:3485: CFLAGS error: CFLAGS may only be used to specify C compiler flags, not macro definitions. Use CPPFLAGS for: -D_FORTIFY_SOURCE=2
+# | configure:3516: error: Can not continue. Fix errors mentioned immediately above this line.
+TARGET_CFLAGS_remove_pn-c-ares = "${lcl_maybe_fortify}"
+TARGET_CPPFLAGS_append_pn-c-ares = "${lcl_maybe_fortify}"
meta-networking/conf/layer.conf +3 -0
index 5fd636a..c09ba4a 100644
@@ -21,3 +21,6 @@ LICENSE_PATH += "${LAYERDIR}/licenses"
 
 # used by waf-samba.bbclass
 WAF_CROSS_ANSWERS_PATH = "${LAYERDIR}/files/waf-cross-answers"
+
+# Override security flags
+require conf/distro/include/meta_networking_security_flags.inc
Signature · 1 line
2.8.1
#2 lore raw

Re: [meta-networking][PATCH v2 2/2] meta-networking: override SECURITY_CFLAGS for c-ares

Quoted 39 lines · On Mon, Jul 18, 2016 at 1:03 AM <[email protected]> wrote:

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Fix this by providing an additional include file that is require'd from conf/layer.conf which for c-ares moves the defines added by security_flags.inc from CFLAGS to CPPFLAGS.

---
 .../conf/distro/include/meta_networking_security_flags.inc          | 6
++++++
 meta-networking/conf/layer.conf                                     | 3
+++
 2 files changed, 9 insertions(+)
 create mode 100644

meta-networking/conf/distro/include/meta_networking_security_flags.inc

diff --git a/meta-networking/conf/distro/include/meta_networking_security_flags.inc b/meta-networking/conf/distro/include/meta_networking_security_flags.inc new file mode 100644
index 0000000..06802d6
--- /dev/null
+++
b/meta-networking/conf/distro/include/meta_networking_security_flags.inc

(quoted diff) +3 -2
@@ -0,0 +1,6 @@
+# configure righteously complains:
+# | configure:3479: using CFLAGS:  -O2 -pipe -g
-feliminate-unused-debug-types -fstack-protector-strong -pie -fpie
-D_FORTIFY_SOURCE=2
+# | configure:3485: CFLAGS error: CFLAGS may only be used to specify C

compiler flags, not macro definitions. Use CPPFLAGS for: -D_FORTIFY_SOURCE=2 +# | configure:3516: error: Can not continue. Fix errors mentioned immediately above this line.

meta-networking/conf/distro/include/meta_networking_security_flags.inc line 6

Quoted 2 lines
meta-networking/conf/distro/include/meta_networking_security_flags.inc new file +2 -0
+TARGET_CFLAGS_remove_pn-c-ares = "${lcl_maybe_fortify}"
+TARGET_CPPFLAGS_append_pn-c-ares = "${lcl_maybe_fortify}"

will

lcl_maybe_fortify_pn-c-area = ""

work ?

Quoted 21 lines
meta-networking/conf/layer.conf +3 -1
index 5fd636a..c09ba4a 100644
@@ -21,3 +21,6 @@ LICENSE_PATH += "${LAYERDIR}/licenses"
 
 # used by waf-samba.bbclass
 WAF_CROSS_ANSWERS_PATH = "${LAYERDIR}/files/waf-cross-answers"
+
+# Override security flags
+require conf/distro/include/meta_networking_security_flags.inc
--

2.8.1

--
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

#3 lore raw

Re: [meta-networking][PATCH v2 2/2] meta-networking: override SECURITY_CFLAGS for c-ares

Quoted 8 lines · Khem Raj
Quoted 6 lines · On Mon, Jul 18, 2016 at 1:03 AM <[email protected]> wrote:

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Curl (on which c-ares's configure files seem to be based) used to have the same problem but was fixed upstream by:

https://github.com/curl/curl/commit/5d3cbde72ece7d83c280492957a26e26ab4e5cca

Quoted 68 lines
Quoted 32 lines

Fix this by providing an additional include file that is require'd from conf/layer.conf which for c-ares moves the defines added by security_flags.inc from CFLAGS to CPPFLAGS.

---
 .../conf/distro/include/meta_networking_security_flags.inc          | 6
++++++
 meta-networking/conf/layer.conf                                     | 3
+++
 2 files changed, 9 insertions(+)
 create mode 100644

meta-networking/conf/distro/include/meta_networking_security_flags.inc

diff --git a/meta-networking/conf/distro/include/meta_networking_security_flags.inc b/meta-networking/conf/distro/include/meta_networking_security_flags.inc new file mode 100644
index 0000000..06802d6
--- /dev/null
+++
b/meta-networking/conf/distro/include/meta_networking_security_flags.inc

(quoted diff) +3 -2
@@ -0,0 +1,6 @@
+# configure righteously complains:
+# | configure:3479: using CFLAGS:  -O2 -pipe -g
-feliminate-unused-debug-types -fstack-protector-strong -pie -fpie
-D_FORTIFY_SOURCE=2
+# | configure:3485: CFLAGS error: CFLAGS may only be used to specify C

compiler flags, not macro definitions. Use CPPFLAGS for: -D_FORTIFY_SOURCE=2 +# | configure:3516: error: Can not continue. Fix errors mentioned immediately above this line.

meta-networking/conf/distro/include/meta_networking_security_flags.inc line 6

Quoted 2 lines
meta-networking/conf/distro/include/meta_networking_security_flags.inc new file +2 -0
+TARGET_CFLAGS_remove_pn-c-ares = "${lcl_maybe_fortify}"
+TARGET_CPPFLAGS_append_pn-c-ares = "${lcl_maybe_fortify}"

will

lcl_maybe_fortify_pn-c-area = ""

work ?

Quoted 15 lines
meta-networking/conf/layer.conf +3 -1
index 5fd636a..c09ba4a 100644
@@ -21,3 +21,6 @@ LICENSE_PATH += "${LAYERDIR}/licenses"
 
 # used by waf-samba.bbclass
 WAF_CROSS_ANSWERS_PATH = "${LAYERDIR}/files/waf-cross-answers"
+
+# Override security flags
+require conf/distro/include/meta_networking_security_flags.inc
--

2.8.1

Quoted 6 lines

--
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

--
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

#4 lore raw

Re: [meta-networking][PATCH v2 2/2] meta-networking: override SECURITY_CFLAGS for c-ares

Quoted 12 lines · Andre McCurdy
Quoted 10 lines · Khem Raj
Quoted 7 lines · On Mon, Jul 18, 2016 at 1:03 AM <[email protected]> wrote:

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Quoted 6 lines

Curl (on which c-ares's configure files seem to be based) used to have the same problem but was fixed upstream by:


https://github.com/curl/curl/commit/5d3cbde72ece7d83c280492957a26e26ab4e5c
ca

I must say I agree with c-ares' error here, and this really highlights a bug in how OE handles the security flags. By convention, preprocessor flags belong into CPPFLAGS, not CFLAGS.

The real solution hence should be to have OE place -D flags (including ${lcl_maybe_fortify} into CPPFLAGS, not CFLAGS in the first place.

But that'd be a change I am not in a position to test, as it would touch everything. E.g. there might be build-environments that (silently) ignore user-supplied CPPFLAGS completely (cmake being one of those [1]).

a.

[1]
https://gitlab.kitware.com/cmake/cmake/issues/12928
https://cmake.org/Bug/view.php?id=12928

#5 lore raw

Re: [meta-networking][PATCH v2 2/2] meta-networking: override SECURITY_CFLAGS for c-ares

Quoted 23 lines · André Draszik
Quoted 12 lines · Andre McCurdy
Quoted 10 lines · Khem Raj
Quoted 7 lines · On Mon, Jul 18, 2016 at 1:03 AM <[email protected]> wrote:

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Quoted 6 lines

Curl (on which c-ares's configure files seem to be based) used to have the same problem but was fixed upstream by:

https://github.com/curl/curl/commit/5d3cbde72ece7d83c280492957a26e26ab4e5c
ca

Quoted 6 lines

I must say I agree with c-ares' error here, and this really highlights a bug in how OE handles the security flags. By convention, preprocessor flags belong into CPPFLAGS, not CFLAGS.

The real solution hence should be to have OE place -D flags (including ${lcl_maybe_fortify} into CPPFLAGS, not CFLAGS in the first place.

right. Would you might sending a patch for OE-core

Quoted 4 lines

But that'd be a change I am not in a position to test, as it would touch everything. E.g. there might be build-environments that (silently) ignore user-supplied CPPFLAGS completely (cmake being one of those [1]).

Auto builders can help. Do whatever testing you can do. On minimum add the flags to CPPFLAGS

Quoted 11 lines

a.

[1]
https://gitlab.kitware.com/cmake/cmake/issues/12928
https://cmake.org/Bug/view.php?id=12928
--
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

#6 lore raw

Re: [meta-networking][PATCH v2 2/2] meta-networking: override SECURITY_CFLAGS for c-ares

Quoted 39 lines · Khem Raj
Quoted 27 lines · André Draszik
Quoted 15 lines · Andre McCurdy
Quoted 6 lines · Khem Raj
Quoted 2 lines · On Mon, Jul 18, 2016 at 1:03 AM <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Quoted 7 lines

Curl (on which c-ares's configure files seem to be based) used to have the same problem but was fixed upstream by:

https://github.com/curl/curl/commit/5d3cbde72ece7d83c280492957a26e26ab
4e5c
ca

Quoted 7 lines

I must say I agree with c-ares' error here, and this really highlights a bug
in how OE handles the security flags. By convention, preprocessor flags belong into CPPFLAGS, not CFLAGS.

The real solution hence should be to have OE place -D flags (including ${lcl_maybe_fortify} into CPPFLAGS, not CFLAGS in the first place.

right. Would you might sending a patch for OE-core

Quoted 2 lines
Quoted 8 lines
Quoted 4 lines

But that'd be a change I am not in a position to test, as it would touch everything. E.g. there might be build-environments that (silently) ignore
user-supplied CPPFLAGS completely (cmake being one of those [1]).

Auto builders can help. Do whatever testing you can do. On minimum add the flags
to CPPFLAGS

Looking around a little bit, I don't think this is feasible.

meta/conf/bitbake.conf unconditionally adds TARGET_CPPFLAGS to TARGET_CFLAGS. So adding the flag to CPPFLAGS alone isn't going to do much, we'd just have it in the compiler command line thrice.

Moving the flag from CFLAGS to CPPFLAGS by default is not going to be feasible either.
I was under the impression that any recipe that inherits autotools*.bbclass would continue to work fine, but various projects use hand-crafted Makefile.in which again don't respect CPPFLAGS.

I could split out CPPFLAGS from SECURITY_CFLAGS in oe-core:

SECURITY_CFLAGS_NO_CPPFLAGS ?= "-fstack-protector-strong -pie -fpie ${SECURITY_STRINGFORMAT}" SECURITY_CFLAGS ?= "${SECURITY_CFLAGS_NO_CPPFLAGS} ${lcl_maybe_fortify}"

Then I could in meta-openembedded:

lcl_maybe_fortify ?= ""
SECURITY_CFLAGS_pn-c-ares = "${SECURITY_CFLAGS_NO_CPPFLAGS}" TARGET_CPPFLAGS_append_pn-c-ares = "${lcl_maybe_fortify}"

(but I'd also have to
TARGET_CFLAGS_remove = "${TARGET_CPPFLAGS}"
in c-ares.bb due to bitbake.conf)

This all looks like lots of churn and I don't think that's much better than what I proposed originally. What do you think?

Cheers,
Andre'

#7 lore raw

Re: [meta-networking][PATCH v2 2/2] meta-networking: override SECURITY_CFLAGS for c-ares

In reply to Khem Raj
Quoted 48 lines · Khem Raj
Quoted 41 lines · On Mon, Jul 18, 2016 at 1:03 AM <[email protected]> wrote:

From: André Draszik <[email protected]>

c-ares doesn't build if the distro has enabled usage of the security_flags.inc file as it is picky about what is placed into CPPFLAGS and CFLAGS. It complains and errors out if any preprocessor options appear in CFLAGS.

Fix this by providing an additional include file that is require'd from conf/layer.conf which for c-ares moves the defines added by security_flags.inc from CFLAGS to CPPFLAGS.

---
 .../conf/distro/include/meta_networking_security_flags.inc          | 6
++++++
 meta-networking/conf/layer.conf                                     | 3
+++

 2 files changed, 9 insertions(+)

 create mode 100644 meta-networking/conf/distro/include/meta_networking_security_flags.inc

diff --git a/meta-networking/conf/distro/include/meta_networking_security_flags.inc b/meta-networking/conf/distro/include/meta_networking_security_flags.inc new file mode 100644
index 0000000..06802d6
--- /dev/null
+++
b/meta-networking/conf/distro/include/meta_networking_security_flags.inc

(quoted diff) +3 -2
@@ -0,0 +1,6 @@
+# configure righteously complains:
+# | configure:3479: using CFLAGS:  -O2 -pipe -g
-feliminate-unused-debug-types -fstack-protector-strong -pie -fpie
-D_FORTIFY_SOURCE=2
+# | configure:3485: CFLAGS error: CFLAGS may only be used to specify C

compiler flags, not macro definitions. Use CPPFLAGS for:

(quoted diff) +1 -1
-D_FORTIFY_SOURCE=2
+# | configure:3516: error: Can not continue. Fix errors mentioned

immediately above this line.

meta-networking/conf/distro/include/meta_networking_security_flags.inc line 6

Quoted 2 lines
meta-networking/conf/distro/include/meta_networking_security_flags.inc new file +2 -0
+TARGET_CFLAGS_remove_pn-c-ares = "${lcl_maybe_fortify}"
+TARGET_CPPFLAGS_append_pn-c-ares = "${lcl_maybe_fortify}"

will

Quoted 3 lines

lcl_maybe_fortify_pn-c-area = ""

work ?

But that would remove -D_FORTIFY_SOURCE=2 completely...

I don't want to remove it, I just want to move it from CFLAGS to CPPFLAGS, without adding further knowledge here about  what else is in SECURITY_CFLAGS.

a.