Skip to contentSkip to conversation

meson: update Meson devtool to 0.40.1

PATCH In review Adam C. Foltzer 7 participants 21 messages Jun 5, 2017 – Jun 26, 2017 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 meson: update Meson devtool to 0.40.1

---
 meta-oe/recipes-devtools/meson/{meson_0.37.1.bb => meson_0.40.1.bb} | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 rename meta-oe/recipes-devtools/meson/{meson_0.37.1.bb => meson_0.40.1.bb} (88%)
meta-oe/recipes-devtools/meson/meson_0.40.1.bb renamed from meta-oe/recipes-devtools/meson/meson_0.37.1.bb +1 -1
similarity index 88%
rename from meta-oe/recipes-devtools/meson/meson_0.37.1.bb
rename to meta-oe/recipes-devtools/meson/meson_0.40.1.bb
index dbbea64..fd96b42 100644
@@ -9,7 +9,7 @@ SRC_URI = " \
     file://native_bindir.patch \
 "
 
-SRCREV = "3d4bfdcb22314ea7db45a5b075f8b2a9c1498aab"
+SRCREV = "b25d3e4d3f2b4d37029a507cc089bdde643c6240"
 
 S = "${WORKDIR}/git"
 
Signature · 1 line
2.9.4
#1 lore raw

PATCH 2/3 meson: fix build/host confusion for bbclass

Meson and Bitbake use different terminology for the build and host; this provides the correct build machine info to Meson.

---
 meta-oe/classes/meson.bbclass | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
meta-oe/classes/meson.bbclass +3 -3
index c33174a..d2ae626 100644
@@ -66,9 +66,9 @@ c_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
 cpp_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
 
 [host_machine]
-system = '${HOST_OS}'
-cpu_family = '${HOST_ARCH}'
-cpu = '${HOST_ARCH}'
+system = '${BUILD_OS}'
+cpu_family = '${BUILD_ARCH}'
+cpu = '${BUILD_ARCH}'
 endian = '${MESON_HOST_ENDIAN}'
 
 [target_machine]
Signature · 1 line
2.9.4
#2 lore raw

Re: [meta-oe][PATCH 2/3] meson: fix build/host confusion for bbclass

Quoted 2 lines · Adam C. Foltzer

Meson and Bitbake use different terminology for the build and host; this provides the correct build machine info to Meson.

What is the difference?

As far as I understand, bitbake and meson use the same terminology. meson is supposed to get the build machine info from the environment, not the cross file.

/Linus

#3 lore raw

Re: [meta-oe][PATCH 2/3] meson: fix build/host confusion for bbclass

Quoted 6 lines · Linus Svensson

What is the difference?

As far as I understand, bitbake and meson use the same terminology. meson is supposed to get the build machine info from the environment, not the cross file.

Linus is right. Quoting the documentation:

autotools:
--build: In which system the program will be built. --host: In which system the generated program will run.

Meson:
build machine is the computer that is doing the actual compiling host machine is the machine on which the compiled binary will run

So changing host_machine to use BUILD_* variables is wrong.

Ross

#4 lore raw

PATCH 3/3 meson: add LDFLAGS to bbclass C/C++ link arguments

In reply to Adam C. Foltzer

This adds compiler flags for C++ projects, and fixes the linker arguments for both C and C++ to avoid the GNU_HASH qa failure

---
 meta-oe/classes/meson.bbclass | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
meta-oe/classes/meson.bbclass +5 -4
index d2ae626..11c8d34 100644
@@ -32,7 +32,8 @@ MESONOPTS = " --prefix ${prefix} \
               --localstatedir ${localstatedir} \
               --sharedstatedir ${sharedstatedir}"
 
-MESON_C_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+MESON_C_ARGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+MESON_LINK_ARGS = "${TOOLCHAIN_OPTIONS} ${LDFLAGS}"
 
 MESON_HOST_ENDIAN = "${@bb.utils.contains('SITEINFO_ENDIANNESS', 'be', 'big', 'little', d)}"
 MESON_TARGET_ENDIAN = "${@bb.utils.contains('TUNE_FEATURES', 'bigendian', 'big', 'little', d)}"
@@ -61,9 +62,9 @@ pkgconfig = 'pkg-config'
 
 [properties]
 c_args = [${@meson_array('MESON_C_ARGS', d)}]
-cpp_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
-c_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
-cpp_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
+c_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
+cpp_args = [${@meson_array('MESON_C_ARGS', d)}]
+cpp_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
 
 [host_machine]
 system = '${BUILD_OS}'
Signature · 1 line
2.9.4
#5 lore raw

Re: [meta-oe][PATCH 3/3] meson: add LDFLAGS to bbclass C/C++ link arguments

Quoted 23 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Adam C. Foltzer
Sent: den 5 juni 2017 19:23
To: [email protected]
Subject: [oe] [meta-oe][PATCH 3/3] meson: add LDFLAGS to bbclass C/C++ link arguments

This adds compiler flags for C++ projects, and fixes the linker arguments for both C and C++ to avoid the GNU_HASH qa failure

---
 meta-oe/classes/meson.bbclass | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
meta- renamed from meta-oe/classes/meson.bbclass +0 -0

oe/classes/meson.bbclass
index d2ae626..11c8d34 100644

meta-oe/classes/meson.bbclass MESONOPTS = " --prefix ${prefix} \ · line 36

Quoted 6 lines
meta-oe/classes/meson.bbclass +2 -1
@@ -32,7 +32,8 @@ MESONOPTS = " --prefix ${prefix} \
               --localstatedir ${localstatedir} \
               --sharedstatedir ${sharedstatedir}"
 
-MESON_C_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+MESON_C_ARGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+MESON_LINK_ARGS = "${TOOLCHAIN_OPTIONS} ${LDFLAGS}"

According to a colleague of mine, the ${TARGET_CC_ARCH} options need to be passed to the linker as well or binaries end up with the wrong ld.so for armhf.

Also, why do you need to add ${LDFLAGS} here?

Quoted 18 lines
meta-oe/classes/meson.bbclass +0 -0
 MESON_HOST_ENDIAN = "${@bb.utils.contains('SITEINFO_ENDIANNESS', 'be',

'big', 'little', d)}"
MESON_TARGET_ENDIAN = "${@bb.utils.contains('TUNE_FEATURES',
'bigendian', 'big', 'little', d)}"

meta-oe/classes/meson.bbclass +3 -4
@@ -61,9 +62,9 @@ pkgconfig = 'pkg-config'
 
 [properties]
 c_args = [${@meson_array('MESON_C_ARGS', d)}]
-cpp_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
-c_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
-cpp_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
+c_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
+cpp_args = [${@meson_array('MESON_C_ARGS', d)}]
+cpp_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
 
 [host_machine]
 system = '${BUILD_OS}'
--
Quoted 1 line

2.9.4

//Peter

#6 lore raw

PATCH v2 1/1 meson: add LDFLAGS to bbclass C/C++ link

When testing this patch on a 32-bit ARM target, I found that it does indeed need TARGET_CC_ARCH in order to link to the right ld.so.

The addition of LDFLAGS makes sure the --hash-style=gnu argument got passed along—the qa step was failing for my 64-bit ARM target without this option.

Regards,
Adam

#7 lore raw

PATCH v2 1/1 meson: add LDFLAGS to bbclass C/C++ link arguments

This adds compiler flags for C++ projects, and fixes the linker arguments for both C and C++ to avoid the GNU_HASH qa failure

---
 meta-oe/classes/meson.bbclass                  | 11 ++++++-----
 meta-oe/recipes-devtools/meson/meson_0.40.1.bb |  1 -
 2 files changed, 6 insertions(+), 6 deletions(-)
meta-oe/classes/meson.bbclass +6 -5
index d2ae626..2c48a7e 100644
@@ -32,7 +32,8 @@ MESONOPTS = " --prefix ${prefix} \
               --localstatedir ${localstatedir} \
               --sharedstatedir ${sharedstatedir}"
 
-MESON_C_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+MESON_C_ARGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+MESON_LINK_ARGS = "${MESON_C_ARGS} ${LDFLAGS}"
 
 MESON_HOST_ENDIAN = "${@bb.utils.contains('SITEINFO_ENDIANNESS', 'be', 'big', 'little', d)}"
 MESON_TARGET_ENDIAN = "${@bb.utils.contains('TUNE_FEATURES', 'bigendian', 'big', 'little', d)}"
@@ -61,9 +62,9 @@ pkgconfig = 'pkg-config'
 
 [properties]
 c_args = [${@meson_array('MESON_C_ARGS', d)}]
-cpp_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
-c_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
-cpp_link_args = [${@meson_array('TOOLCHAIN_OPTIONS', d)}]
+c_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
+cpp_args = [${@meson_array('MESON_C_ARGS', d)}]
+cpp_link_args = [${@meson_array('MESON_LINK_ARGS', d)}]
 
 [host_machine]
 system = '${BUILD_OS}'
@@ -74,7 +75,7 @@ endian = '${MESON_HOST_ENDIAN}'
 [target_machine]
 system = '${TARGET_OS}'
 cpu_family = '${TARGET_ARCH}'
-cpu = '${TARGET_ARCH}'
+cpu = '${TUNE_PKGARCH}'
 endian = '${MESON_TARGET_ENDIAN}'
 EOF
 }
meta-oe/recipes-devtools/meson/meson_0.40.1.bb +0 -1
index fd96b42..a2c5e4d 100644
@@ -6,7 +6,6 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=3b83ef96387f14655fc854ddc3c6bd57"
 
 SRC_URI = " \
     git://github.com/mesonbuild/meson.git \
-    file://native_bindir.patch \
 "
 
 SRCREV = "b25d3e4d3f2b4d37029a507cc089bdde643c6240"
Signature · 1 line
2.9.4
#8 lore raw

Re: [meta-oe][PATCH v2] meson: add LDFLAGS to bbclass C/C++ link arguments

meta-oe/classes/meson.bbclass endian = '${MESON_HOST_ENDIAN}' · line 78

Quoted 2 lines · Adam C. Foltzer
meta-oe/classes/meson.bbclass +1 -1
-cpu = '${TARGET_ARCH}'
+cpu = '${TUNE_PKGARCH}'

what is this change for ?

#9 lore raw

Re: [meta-oe][PATCH v2] meson: add LDFLAGS to bbclass C/C++ link arguments

Apologies, this line was inadvertently committed. It was a fix I tried before learning that adding TARGET_CC_ARCH was the solution to linking the wrong ld.so.

Quoted 7 lines · Khem Raj

meta-oe/classes/meson.bbclass endian = '${MESON_HOST_ENDIAN}' · line 78

Quoted 2 lines · Adam C. Foltzer
meta-oe/classes/meson.bbclass +1 -1
-cpu = '${TARGET_ARCH}'
+cpu = '${TUNE_PKGARCH}'

what is this change for ?

#10 lore raw

Re: [meta-oe][PATCH v2] meson: add LDFLAGS to bbclass C/C++ link arguments

In reply to Adam C. Foltzer

meta-oe/classes/meson.bbclass endian = '${MESON_HOST_ENDIAN}' · line 78

Quoted 3 lines · Adam C. Foltzer
meta-oe/classes/meson.bbclass +1 -1
-cpu = '${TARGET_ARCH}'
+cpu = '${TUNE_PKGARCH}'

This line was retracted in a later mail but the patch was merged.

Quoted 5 lines
 SRC_URI = " \
     git://github.com/mesonbuild/meson.git \

- file://native_bindir.patch \
"

Was this patch meant to be removed? If so the file needs to be removed too.

Ross

#11 lore raw
In reply to Adam C. Foltzer
Quoted 35 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Adam C. Foltzer
Sent: den 5 juni 2017 19:23
To: [email protected]
Subject: [oe] [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1

---
meta-oe/recipes-devtools/meson/{meson_0.37.1.bb => meson_0.40.1.bb} |
2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
 rename meta-oe/recipes-devtools/meson/{meson_0.37.1.bb =>

meson_0.40.1.bb} (88%)

meta- renamed from meta-oe/recipes-devtools/meson/meson_0.37.1.bb +0 -0

oe/recipes-devtools/meson/meson_0.40.1.bb similarity index 88%
rename from meta-oe/recipes-devtools/meson/meson_0.37.1.bb rename to meta-oe/recipes-devtools/meson/meson_0.40.1.bb index dbbea64..fd96b42 100644

meta-oe/recipes-devtools/meson/meson_0.40.1.bb renamed from meta-oe/recipes-devtools/meson/meson_0.37.1.bb +1 -2
@@ -9,7 +9,7 @@ SRC_URI = " \
     file://native_bindir.patch \
 "
 
-SRCREV = "3d4bfdcb22314ea7db45a5b075f8b2a9c1498aab"
+SRCREV = "b25d3e4d3f2b4d37029a507cc089bdde643c6240"
 
 S = "${WORKDIR}/git"
 
--
Quoted 1 line

2.9.4

When I updated the meson recipe to 0.37.1, I did not update it to the latest version at the time (0.38 something if I remember correctly) because the latter version failed to build shared libraries if building with PIE had been enabled by including security_flags.inc. I had planned to look into that, but never got around to it. If you have not tried building with PIE enabled, you should try that as it probably still causes build problems with 0.40.1...

My guess is that the problem stems from the fact that security_flags.inc adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than SECURITY_LDFLAGS...

//Peter

#12 lore raw

-pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Quoted 3 lines · Peter Kjellerstedt

My guess is that the problem stems from the fact that security_flags.inc adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came after -shared, because then the compiler ended up trying to produce a pie executable instead of a shared library.

Perhaps we should finally address that in security_flags.inc instead of working around it?

Here's an untested patch which puts -pie where it belongs in the final variables, without changing the pie/no pie API:

meta/conf/distro/include/security_flags.inc +5 -2
index e162abeb3d9..b7b19355806 100644
@@ -12,6 +12,9 @@ lcl_maybe_fortify = "${@base_conditional('DEBUG_BUILD','1','','-D_FORTIFY_SOURCE
 # Error on use of format strings that represent possible security problems
 SECURITY_STRINGFORMAT ?= "-Wformat -Wformat-security -Werror=format-security"
 
+# For history reasons and simplicity, -pie is listed here as part of CFLAGS.
+# In practice, it ends up getting used as part of LDFLAGS, as it should
+# be because it is a linker flag.
 SECURITY_CFLAGS ?= "-fstack-protector-strong -pie -fpie ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
 SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
 
@@ -94,8 +97,8 @@ SECURITY_STRINGFORMAT_pn-busybox = ""
 SECURITY_STRINGFORMAT_pn-gcc = ""
 SECURITY_STRINGFORMAT_pn-oh-puzzles = ""
 
-TARGET_CFLAGS_append_class-target = " ${SECURITY_CFLAGS}"
-TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_CFLAGS_append_class-target = " ${@ oe.utils.filter_out('-pie', '${SECURITY_CFLAGS}') }"
+TARGET_LDFLAGS_append_class-target = " ${@ oe.utils.filter('-pie', '${SECURITY_CFLAGS}') } ${SECURITY_LDFLAGS}"
 
 SECURITY_LDFLAGS_remove_pn-gcc-runtime = "-fstack-protector-strong"
 SECURITY_LDFLAGS_remove_pn-glibc = "-fstack-protector-strong"
Signature · 6 lines
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.
#13 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Quoted 11 lines · Patrick Ohly
Quoted 3 lines · Peter Kjellerstedt

My guess is that the problem stems from the fact that security_flags.inc adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came after -shared, because then the compiler ended up trying to produce a pie executable instead of a shared library.

Perhaps we should finally address that in security_flags.inc instead of working around it?

This patch is removing -pie from compiler and linker flags which does not result in intended behavior for executable when linked they will not be using -pie

Libtool adds -shared automatically for shared libraries so we have to either insert pie before that which means make it part of TOOLCHAIN_OPTIONS variable but that might have more unintended consequences especially for external toolchains

Quoted 32 lines

Here's an untested patch which puts -pie where it belongs in the final variables, without changing the pie/no pie API:

meta/conf/distro/include/security_flags.inc +0 -0
index e162abeb3d9..b7b19355806 100644
@@ -12,6 +12,9 @@ lcl_maybe_fortify =

"${@base_conditional('DEBUG_BUILD','1','','-D_FORTIFY_SOURCE
# Error on use of format strings that represent possible security problems SECURITY_STRINGFORMAT ?= "-Wformat -Wformat-security

meta/conf/distro/include/security_flags.inc +1 -1
-Werror=format-security"
 
+# For history reasons and simplicity, -pie is listed here as part of

CFLAGS.

meta/conf/distro/include/security_flags.inc +2 -0
+# In practice, it ends up getting used as part of LDFLAGS, as it should
+# be because it is a linker flag.
 SECURITY_CFLAGS ?= "-fstack-protector-strong -pie -fpie

${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify}
${SECURITY_STRINGFORMAT}"

meta/conf/distro/include/security_flags.inc +1 -2
@@ -94,8 +97,8 @@ SECURITY_STRINGFORMAT_pn-busybox = ""
 SECURITY_STRINGFORMAT_pn-gcc = ""
 SECURITY_STRINGFORMAT_pn-oh-puzzles = ""
 
-TARGET_CFLAGS_append_class-target = " ${SECURITY_CFLAGS}"
-TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_CFLAGS_append_class-target = " ${@ oe.utils.filter_out('-pie',
Quoted 3 lines

'${SECURITY_CFLAGS}') }" +TARGET_LDFLAGS_append_class-target = " ${@ oe.utils.filter('-pie', '${SECURITY_CFLAGS}') } ${SECURITY_

LDFLAGS}"

Quoted 20 lines

SECURITY_LDFLAGS_remove_pn-gcc-runtime = "-fstack-protector-strong" SECURITY_LDFLAGS_remove_pn-glibc = "-fstack-protector-strong"

--
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.

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

#14 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Quoted 17 lines · Khem Raj

On Fri, Jun 9, 2017 at 1:43 AM Patrick Ohly <[email protected]> wrote:

On Wed, 2017-06-07 at 21:44 +0000, Peter Kjellerstedt wrote:
> My guess is that the problem stems from the fact that security_flags.inc
> adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than
> SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came
after -shared, because then the compiler ended up trying to produce a
pie executable instead of a shared library.

Quoted 8 lines

Perhaps we should finally address that in security_flags.inc instead of
working around it?

This patch is removing -pie from compiler and linker flags which does not result in intended behavior for executable when linked they will not be using -pie

The patch had some syntax errors (fixed version below), but it had the code which adds -pie to TARGET_LDFLAGS when it is in SECURITY_CFLAGS, so conceptually the flag shouldn't get lost entirely.

Are you saying that one cannot rely on TARGET_LDFLAGS being used during linking?

I've tested with m4, and it seems to work okay:

$ grep -w -e -pie tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/temp/log.do_compile
x86_64-refkit-linux-gcc  -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot   -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0=/usr/src/debug/m4/1.4.18-r0 -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot-native= -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot=  -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -pie -fstack-protector-strong -Wl,-z,relro,-z,now -o m4 m4.o builtin.o debug.o eval.o format.o freeze.o input.o macro.o output.o path.o symtab.o ../lib/libm4.a    
$ file tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4 
tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f10d0a26299dcb8c5bd0f1c82ed492aea2d8f0ac, stripped

I assume "ELF 64-bit LSB shared object" instead of "ELF 64-bit LSB executable" means "pie executable"?

meta/conf/distro/include/security_flags.inc +5 -2
index e162abeb3d9..b1781ceab42 100644
@@ -12,6 +12,9 @@ lcl_maybe_fortify = "${@base_conditional('DEBUG_BUILD','1','','-D_FORTIFY_SOURCE
 # Error on use of format strings that represent possible security problems
 SECURITY_STRINGFORMAT ?= "-Wformat -Wformat-security -Werror=format-security"
 
+# For history reasons and simplicity, -pie is listed here as part of CFLAGS.
+# In practice, it ends up getting used as part of LDFLAGS, as it should
+# be because it is a linker flag.
 SECURITY_CFLAGS ?= "-fstack-protector-strong -pie -fpie ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
 SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
 
@@ -94,8 +97,8 @@ SECURITY_STRINGFORMAT_pn-busybox = ""
 SECURITY_STRINGFORMAT_pn-gcc = ""
 SECURITY_STRINGFORMAT_pn-oh-puzzles = ""
 
-TARGET_CFLAGS_append_class-target = " ${SECURITY_CFLAGS}"
-TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_CFLAGS_append_class-target = " ${@ oe.utils.str_filter_out('-pie', '${SECURITY_CFLAGS}', d) }"
+TARGET_LDFLAGS_append_class-target = " ${@ oe.utils.str_filter('-pie', '${SECURITY_CFLAGS}', d) } ${SECURITY_LDFLAGS}"
 
 SECURITY_LDFLAGS_remove_pn-gcc-runtime = "-fstack-protector-strong"
 SECURITY_LDFLAGS_remove_pn-glibc = "-fstack-protector-strong"
Signature · 6 lines
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.
#15 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Quoted 36 lines · Patrick Ohly
Quoted 17 lines · Khem Raj

On Fri, Jun 9, 2017 at 1:43 AM Patrick Ohly <[email protected]> wrote:

On Wed, 2017-06-07 at 21:44 +0000, Peter Kjellerstedt wrote:
> My guess is that the problem stems from the fact that security_flags.inc
> adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than
> SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came
after -shared, because then the compiler ended up trying to produce a
pie executable instead of a shared library.

Quoted 8 lines

Perhaps we should finally address that in security_flags.inc instead of
working around it?

This patch is removing -pie from compiler and linker flags which does not result in intended behavior for executable when linked they will not be using -pie

The patch had some syntax errors (fixed version below), but it had the code which adds -pie to TARGET_LDFLAGS when it is in SECURITY_CFLAGS, so conceptually the flag shouldn't get lost entirely.

Are you saying that one cannot rely on TARGET_LDFLAGS being used during linking?

I've tested with m4, and it seems to work okay:

Quoted 8 lines
$ grep -w -e -pie tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/temp/log.do_compile
x86_64-refkit-linux-gcc  -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot   -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0=/usr/src/debug/m4/1.4.18-r0 -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot-native= -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot=  -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -pie -fstack-protector-strong -Wl,-z,relro,-z,now -o m4 m4.o builtin.o debug.o eval.o format.o freeze.o input.o macro.o output.o path.o symtab.o ../lib/libm4.a    
$ file tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4 
tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f10d0a26299dcb8c5bd0f1c82ed492aea2d8f0ac, stripped

I assume "ELF 64-bit LSB shared object" instead of "ELF 64-bit LSB executable" means "pie executable"?

While I don't think my patch caused -pie to get lost, unfortunately I now know that it still doesn't go into the right place in all cases. For example, ncurses puts LDFLAGS after -shared, thus triggering the "main undefined" error.

The TOOLCHAIN_OPTIONS that Khem mentioned get appended directly after the command, so that seems like a better place for -pie than LDFLAGS. It's still a bit odd to pass a linker flag to all compiler invocations, including those that do not link, but it might be a pragmatic solution that is better than what we have now.

However, my patch below now causes /usr/lib/libstdc++.a-gdb.py to be built for gcc-runtime, which triggers an error:

ERROR: gcc-runtime-6.3.0-r0 do_package: QA Issue: gcc-runtime:
Files/directories were installed but not shipped in any package:
/usr/lib/libstdc++.a-gdb.py

That file is not present at all without the patch. If anyone has a clue about what might be causing that, I'm all ears...

Signature · 6 lines
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.
#16 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Quoted 57 lines · Patrick Ohly
Quoted 36 lines · Patrick Ohly
Quoted 17 lines · Khem Raj

On Fri, Jun 9, 2017 at 1:43 AM Patrick Ohly <[email protected]> wrote:

On Wed, 2017-06-07 at 21:44 +0000, Peter Kjellerstedt wrote:
> My guess is that the problem stems from the fact that security_flags.inc
> adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than
> SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came
after -shared, because then the compiler ended up trying to produce a
pie executable instead of a shared library.

Quoted 8 lines

Perhaps we should finally address that in security_flags.inc instead of
working around it?

This patch is removing -pie from compiler and linker flags which does not result in intended behavior for executable when linked they will not be using -pie

The patch had some syntax errors (fixed version below), but it had the code which adds -pie to TARGET_LDFLAGS when it is in SECURITY_CFLAGS, so conceptually the flag shouldn't get lost entirely.

Are you saying that one cannot rely on TARGET_LDFLAGS being used during linking?

I've tested with m4, and it seems to work okay:

Quoted 8 lines
$ grep -w -e -pie tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/temp/log.do_compile
x86_64-refkit-linux-gcc  -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot   -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0=/usr/src/debug/m4/1.4.18-r0 -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot-native= -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot=  -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -pie -fstack-protector-strong -Wl,-z,relro,-z,now -o m4 m4.o builtin.o debug.o eval.o format.o freeze.o input.o macro.o output.o path.o symtab.o ../lib/libm4.a    
$ file tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4 
tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f10d0a26299dcb8c5bd0f1c82ed492aea2d8f0ac, stripped

I assume "ELF 64-bit LSB shared object" instead of "ELF 64-bit LSB executable" means "pie executable"?

While I don't think my patch caused -pie to get lost, unfortunately I now know that it still doesn't go into the right place in all cases. For example, ncurses puts LDFLAGS after -shared, thus triggering the "main undefined" error.

The TOOLCHAIN_OPTIONS that Khem mentioned get appended directly after the command, so that seems like a better place for -pie than LDFLAGS. It's still a bit odd to pass a linker flag to all compiler invocations, including those that do not link, but it might be a pragmatic solution that is better than what we have now.

Quoted 6 lines

However, my patch below now causes /usr/lib/libstdc++.a-gdb.py to be built for gcc-runtime, which triggers an error:

ERROR: gcc-runtime-6.3.0-r0 do_package: QA Issue: gcc-runtime:
Files/directories were installed but not shipped in any package:
/usr/lib/libstdc++.a-gdb.py

That's just a minor follow-up error. The real problem is that libstdc ++.so.6.0.22 was not getting built anymore. The expect .py file then is libstdc++.so.6.0.22-gdb.py.

I'm still unsure about the root cause. Something seems to have gone wrong when building the toolchain, because gcc-runtime doesn't even have -pie in the compiler flags. From log.do_configure:

checking whether the x86_64-refkit-linux-gcc -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2
--sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,-z,now linker (x86_64-refkit-linux-ld --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,-z,now -m elf_x86_64) supports shared libraries... no
checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... unsupported checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... no

I'm going to put this aside for now, but I remain unhappy about how we currently pass -pie in CFLAGS and the workarounds that are getting used as a result of that, like disabling -pie for Python distutils. I understand that that particular change probably only affected very few binaries, but it still looks like a workaround and not a proper solution to me.

What do others thing about the current status quo regarding -pie?

Signature · 6 lines
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.
#17 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Patrick

I have a patchset that is redoing the PIE hardening with using some help from gcc configuration itself. with this patch almost all of the NOPIE entries in secuity.inc are fixed and we get gcc to take care of -pie passing to compiler and linker when needed

This patches are done after gcc7 recipes so I will propose them after gcc7 but if you are interested here is the branch

Top 6 patches are what you want from
http://git.openembedded.org/openembedded-core-contrib/log/?h=kraj/master

Quoted 100 lines · Patrick Ohly
Quoted 57 lines · Patrick Ohly
Quoted 36 lines · Patrick Ohly
Quoted 17 lines · Khem Raj

On Fri, Jun 9, 2017 at 1:43 AM Patrick Ohly <[email protected]> wrote:

On Wed, 2017-06-07 at 21:44 +0000, Peter Kjellerstedt wrote:
> My guess is that the problem stems from the fact that security_flags.inc
> adds -pie (which is a linker flag) to SECURITY_CFLAGS rather than
> SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came
after -shared, because then the compiler ended up trying to produce a
pie executable instead of a shared library.

Quoted 8 lines

Perhaps we should finally address that in security_flags.inc instead of
working around it?

This patch is removing -pie from compiler and linker flags which does not result in intended behavior for executable when linked they will not be using -pie

The patch had some syntax errors (fixed version below), but it had the code which adds -pie to TARGET_LDFLAGS when it is in SECURITY_CFLAGS, so conceptually the flag shouldn't get lost entirely.

Are you saying that one cannot rely on TARGET_LDFLAGS being used during linking?

I've tested with m4, and it seems to work okay:

Quoted 8 lines
$ grep -w -e -pie tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/temp/log.do_compile
x86_64-refkit-linux-gcc  -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot   -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0=/usr/src/debug/m4/1.4.18-r0 -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot-native= -fdebug-prefix-map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot=  -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -pie -fstack-protector-strong -Wl,-z,relro,-z,now -o m4 m4.o builtin.o debug.o eval.o format.o freeze.o input.o macro.o output.o path.o symtab.o ../lib/libm4.a
$ file tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4
tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-split/m4/usr/bin/m4: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f10d0a26299dcb8c5bd0f1c82ed492aea2d8f0ac, stripped

I assume "ELF 64-bit LSB shared object" instead of "ELF 64-bit LSB executable" means "pie executable"?

While I don't think my patch caused -pie to get lost, unfortunately I now know that it still doesn't go into the right place in all cases. For example, ncurses puts LDFLAGS after -shared, thus triggering the "main undefined" error.

The TOOLCHAIN_OPTIONS that Khem mentioned get appended directly after the command, so that seems like a better place for -pie than LDFLAGS. It's still a bit odd to pass a linker flag to all compiler invocations, including those that do not link, but it might be a pragmatic solution that is better than what we have now.

Quoted 6 lines

However, my patch below now causes /usr/lib/libstdc++.a-gdb.py to be built for gcc-runtime, which triggers an error:

ERROR: gcc-runtime-6.3.0-r0 do_package: QA Issue: gcc-runtime:
Files/directories were installed but not shipped in any package:
/usr/lib/libstdc++.a-gdb.py

That's just a minor follow-up error. The real problem is that libstdc ++.so.6.0.22 was not getting built anymore. The expect .py file then is libstdc++.so.6.0.22-gdb.py.

I'm still unsure about the root cause. Something seems to have gone wrong when building the toolchain, because gcc-runtime doesn't even have -pie in the compiler flags. From log.do_configure:

checking whether the x86_64-refkit-linux-gcc -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2
--sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,-z,now linker (x86_64-refkit-linux-ld --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,-z,now -m elf_x86_64) supports shared libraries... no
checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... unsupported checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... no

I'm going to put this aside for now, but I remain unhappy about how we currently pass -pie in CFLAGS and the workarounds that are getting used as a result of that, like disabling -pie for Python distutils. I understand that that particular change probably only affected very few binaries, but it still looks like a workaround and not a proper solution to me.

What do others thing about the current status quo regarding -pie?

--
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.

#18 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

This looks great, except for one thing. What about external toolchains?

We use Poky's compiler when building for ARM, but when building for MIPS we need to use our own, which is based on gcc 4.7.2 and not likely to be updated. With the suggested changes to security_flags.inc we will no longer be able to build with hardening enabled for MIPS...

Regarding your changes:
* Wouldn't it be better to define GCCPIE as:

    GCCPIE ??= ""

in meta/recipes-devtools/gcc/gcc-configure-common.inc and as:
GCCPIE ?= "--enable-default-pie"
in meta/conf/distro/include/security_flags.inc? That way it is easy to disable PIE by setting GCCPIE = "" in local.conf even if other hardenings are enabled by including security_flags.inc.
* It is probably a bad idea to change the definition of SECURITY_NO_PIE_CFLAGS to:

    SECURITY_NO_PIE_CFLAGS ?= "${SECURITY_CFLAGS}"
  since it is most likely used to define SECURITY_CFLAGS in other 
  existing layers via the typical:
    SECURITY_CFLAGS_pn-foo = "${SECURITY_NO_PIE_CFLAGS}"

and you will then end up with a circular definition...

For backwards compatibility it might be an idea to do the following in security_flags.inc:

GCCPIE ?= "--enable-default-pie"

# SECURITY_PIE_CFLAGS is used to maintain backwards compatibility for

# the definitions of SECURITY_CFLAGS and SECURITY_NO_PIE_CFLAGS after 
# the introduction of GCCPIE.
SECURITY_PIE_CFLAGS ?= "${@'' if '${GCCPIE}' else '-pie -fpie'}"
SECURITY_CFLAGS ?= "-fstack-protector-strong ${SECURITY_PIE_CFLAGS} ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"

That way the SECURITY_CFLAGS and SECURITY_NO_PIE_CFLAGS variables would keep their old values unless GCCPIE is set to something, which it is by default.

Enabling hardening but without PIE would then become:

GCCPIE = ""
SECURITY_PIE_CFLAGS = ""

//Peter

Quoted 172 lines

-----Original Message-----
From: Khem Raj [mailto:[email protected]]
Sent: den 12 juni 2017 16:47
To: Patrick Ohly <[email protected]>
Cc: Peter Kjellerstedt <[email protected]>; openembedded- [email protected]
Subject: Re: [oe] -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Patrick

I have a patchset that is redoing the PIE hardening with using some help from gcc configuration itself. with this patch almost all of the NOPIE entries in secuity.inc are fixed and we get gcc to take care of -pie passing to compiler and linker when needed

This patches are done after gcc7 recipes so I will propose them after gcc7 but if you are interested here is the branch

Top 6 patches are what you want from
http://git.openembedded.org/openembedded-core-contrib/log/?h=kraj/master

Quoted 5 lines · Patrick Ohly
Quoted 4 lines · Patrick Ohly
Quoted 3 lines · Patrick Ohly
Quoted 2 lines · Khem Raj

On Fri, Jun 9, 2017 at 1:43 AM Patrick Ohly

<[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

wrote:

        On Wed, 2017-06-07 at 21:44 +0000, Peter Kjellerstedt
Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

> My guess is that the problem stems from the fact that security_flags.inc
> adds -pie (which is a linker flag) to SECURITY_CFLAGS

rather

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

than
> SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came
after -shared, because then the compiler ended up trying

to

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

produce a
pie executable instead of a shared library.

Perhaps we should finally address that in

security_flags.inc

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

instead of
working around it?

This patch is removing -pie from compiler and linker flags which

does

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

not result in intended behavior for executable when linked they

will

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

not be using -pie

The patch had some syntax errors (fixed version below), but it had

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

code which adds -pie to TARGET_LDFLAGS when it is in

SECURITY_CFLAGS, so

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

conceptually the flag shouldn't get lost entirely.

Are you saying that one cannot rely on TARGET_LDFLAGS being used

during

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

linking?

I've tested with m4, and it seems to work okay:

$ grep -w -e -pie tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-

r0/temp/log.do_compile

Quoted 1 line
Quoted 1 line
Quoted 1 line

x86_64-refkit-linux-gcc -m64 -march=corei7 -mtune=corei7 -

mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-
glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot -O2 -
pipe -g -feliminate-unused-debug-types -fdebug-prefix- map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit- linux/m4/1.4.18-r0=/usr/src/debug/m4/1.4.18-r0 -fdebug-prefix- map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit- linux/m4/1.4.18-r0/recipe-sysroot-native= -fdebug-prefix- map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit- linux/m4/1.4.18-r0/recipe-sysroot= -fstack-protector-strong -fpie - D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -pie -fstack-protector- strong -Wl,-z,relro,-z,now -o m4 m4.o builtin.o debug.o eval.o format.o freeze.o input.o macro.o output.o path.o symtab.o ../lib/libm4.a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
$ file tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-

r0/packages-split/m4/usr/bin/m4

Quoted 1 line
Quoted 1 line
Quoted 1 line

tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-

split/m4/usr/bin/m4: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f10d0a26299dcb8c5bd0f1c82ed492aea2d8f0ac, stripped

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

I assume "ELF 64-bit LSB shared object" instead of "ELF 64-bit LSB executable" means "pie executable"?

While I don't think my patch caused -pie to get lost, unfortunately

I

Quoted 1 line
Quoted 1 line

now know that it still doesn't go into the right place in all cases.

For

Quoted 1 line
Quoted 1 line

example, ncurses puts LDFLAGS after -shared, thus triggering the

"main

Quoted 3 lines
Quoted 3 lines

undefined" error.

The TOOLCHAIN_OPTIONS that Khem mentioned get appended directly

after

Quoted 1 line
Quoted 1 line

the command, so that seems like a better place for -pie than

LDFLAGS.

Quoted 1 line
Quoted 1 line

It's still a bit odd to pass a linker flag to all compiler

invocations,

Quoted 1 line
Quoted 1 line

including those that do not link, but it might be a pragmatic

solution

Quoted 11 lines
Quoted 8 lines

that is better than what we have now.

However, my patch below now causes /usr/lib/libstdc++.a-gdb.py to be built for gcc-runtime, which triggers an error:

ERROR: gcc-runtime-6.3.0-r0 do_package: QA Issue: gcc-runtime:
Files/directories were installed but not shipped in any package:
/usr/lib/libstdc++.a-gdb.py

That's just a minor follow-up error. The real problem is that libstdc ++.so.6.0.22 was not getting built anymore. The expect .py file then

is

Quoted 4 lines

libstdc++.so.6.0.22-gdb.py.

I'm still unsure about the root cause. Something seems to have gone wrong when building the toolchain, because gcc-runtime doesn't even

have

Quoted 5 lines

-pie in the compiler flags. From log.do_configure:

checking whether the x86_64-refkit-linux-gcc -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-

64-refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,- z,now linker (x86_64-refkit-linux-ld -- sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64- refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,-z,now -m elf_x86_64) supports shared libraries... no

Quoted 6 lines

checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... unsupported checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... no

I'm going to put this aside for now, but I remain unhappy about how

we

Quoted 1 line

currently pass -pie in CFLAGS and the workarounds that are getting

used

Quoted 2 lines

as a result of that, like disabling -pie for Python distutils. I understand that that particular change probably only affected very

few

Quoted 1 line

binaries, but it still looks like a workaround and not a proper

solution

Quoted 14 lines

to me.

What do others thing about the current status quo regarding -pie?

--
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.

#19 lore raw

Re: -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Quoted 7 lines · Peter Kjellerstedt

This looks great, except for one thing. What about external toolchains?

We use Poky's compiler when building for ARM, but when building for MIPS we need to use our own, which is based on gcc 4.7.2 and not likely to be updated. With the suggested changes to security_flags.inc we will no longer be able to build with hardening enabled for MIPS...

Quoted 8 lines

Regarding your changes:
* Wouldn't it be better to define GCCPIE as:

    GCCPIE ??= ""

in meta/recipes-devtools/gcc/gcc-configure-common.inc and as:
GCCPIE ?= "--enable-default-pie"
in meta/conf/distro/include/security_flags.inc? That way it is easy to disable PIE by setting GCCPIE = "" in local.conf even if other hardenings are enabled by including security_flags.inc.

that seems a fine idea, I will make this change locally.

Quoted 20 lines

* It is probably a bad idea to change the definition of SECURITY_NO_PIE_CFLAGS to:

    SECURITY_NO_PIE_CFLAGS ?= "${SECURITY_CFLAGS}"
  since it is most likely used to define SECURITY_CFLAGS in other
  existing layers via the typical:
    SECURITY_CFLAGS_pn-foo = "${SECURITY_NO_PIE_CFLAGS}"

and you will then end up with a circular definition...

For backwards compatibility it might be an idea to do the following in security_flags.inc:

GCCPIE ?= "--enable-default-pie"

# SECURITY_PIE_CFLAGS is used to maintain backwards compatibility for

# the definitions of SECURITY_CFLAGS and SECURITY_NO_PIE_CFLAGS after
# the introduction of GCCPIE.
SECURITY_PIE_CFLAGS ?= "${@'' if '${GCCPIE}' else '-pie -fpie'}"
SECURITY_CFLAGS ?= "-fstack-protector-strong ${SECURITY_PIE_CFLAGS} ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
SECURITY_NO_PIE_CFLAGS ?= "-fstack-protector-strong ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
Quoted 3 lines

That way the SECURITY_CFLAGS and SECURITY_NO_PIE_CFLAGS variables would keep their old values unless GCCPIE is set to something, which it is by default.

seems good yes, I will have run into this error once I plug in meta-oe but was still building oe-core world.

Quoted 6 lines

Enabling hardening but without PIE would then become:

GCCPIE = ""
SECURITY_PIE_CFLAGS = ""

agreed.

Quoted 174 lines

//Peter

Quoted 172 lines

-----Original Message-----
From: Khem Raj [mailto:[email protected]]
Sent: den 12 juni 2017 16:47
To: Patrick Ohly <[email protected]>
Cc: Peter Kjellerstedt <[email protected]>; openembedded- [email protected]
Subject: Re: [oe] -pie in SECURITY_CFLAGS (was: Re: [meta-oe][PATCH 1/3] meson: update Meson devtool to 0.40.1)

Patrick

I have a patchset that is redoing the PIE hardening with using some help from gcc configuration itself. with this patch almost all of the NOPIE entries in secuity.inc are fixed and we get gcc to take care of -pie passing to compiler and linker when needed

This patches are done after gcc7 recipes so I will propose them after gcc7 but if you are interested here is the branch

Top 6 patches are what you want from
http://git.openembedded.org/openembedded-core-contrib/log/?h=kraj/master

Quoted 5 lines · Patrick Ohly
Quoted 4 lines · Patrick Ohly
Quoted 3 lines · Patrick Ohly
Quoted 2 lines · Khem Raj

On Fri, Jun 9, 2017 at 1:43 AM Patrick Ohly

<[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

wrote:

        On Wed, 2017-06-07 at 21:44 +0000, Peter Kjellerstedt
Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

> My guess is that the problem stems from the fact that security_flags.inc
> adds -pie (which is a linker flag) to SECURITY_CFLAGS

rather

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

than
> SECURITY_LDFLAGS...

I think I've seen that cause problems elsewhere when the CFLAGS came
after -shared, because then the compiler ended up trying

to

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

produce a
pie executable instead of a shared library.

Perhaps we should finally address that in

security_flags.inc

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

instead of
working around it?

This patch is removing -pie from compiler and linker flags which

does

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

not result in intended behavior for executable when linked they

will

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

not be using -pie

The patch had some syntax errors (fixed version below), but it had

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

code which adds -pie to TARGET_LDFLAGS when it is in

SECURITY_CFLAGS, so

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

conceptually the flag shouldn't get lost entirely.

Are you saying that one cannot rely on TARGET_LDFLAGS being used

during

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

linking?

I've tested with m4, and it seems to work okay:

$ grep -w -e -pie tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-

r0/temp/log.do_compile

Quoted 1 line
Quoted 1 line
Quoted 1 line

x86_64-refkit-linux-gcc -m64 -march=corei7 -mtune=corei7 -

mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-
glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/recipe-sysroot -O2 -
pipe -g -feliminate-unused-debug-types -fdebug-prefix- map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit- linux/m4/1.4.18-r0=/usr/src/debug/m4/1.4.18-r0 -fdebug-prefix- map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit- linux/m4/1.4.18-r0/recipe-sysroot-native= -fdebug-prefix- map=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64-refkit- linux/m4/1.4.18-r0/recipe-sysroot= -fstack-protector-strong -fpie - D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -pie -fstack-protector- strong -Wl,-z,relro,-z,now -o m4 m4.o builtin.o debug.o eval.o format.o freeze.o input.o macro.o output.o path.o symtab.o ../lib/libm4.a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
$ file tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-

r0/packages-split/m4/usr/bin/m4

Quoted 1 line
Quoted 1 line
Quoted 1 line

tmp-glibc/work/corei7-64-refkit-linux/m4/1.4.18-r0/packages-

split/m4/usr/bin/m4: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f10d0a26299dcb8c5bd0f1c82ed492aea2d8f0ac, stripped

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

I assume "ELF 64-bit LSB shared object" instead of "ELF 64-bit LSB executable" means "pie executable"?

While I don't think my patch caused -pie to get lost, unfortunately

I

Quoted 1 line
Quoted 1 line

now know that it still doesn't go into the right place in all cases.

For

Quoted 1 line
Quoted 1 line

example, ncurses puts LDFLAGS after -shared, thus triggering the

"main

Quoted 3 lines
Quoted 3 lines

undefined" error.

The TOOLCHAIN_OPTIONS that Khem mentioned get appended directly

after

Quoted 1 line
Quoted 1 line

the command, so that seems like a better place for -pie than

LDFLAGS.

Quoted 1 line
Quoted 1 line

It's still a bit odd to pass a linker flag to all compiler

invocations,

Quoted 1 line
Quoted 1 line

including those that do not link, but it might be a pragmatic

solution

Quoted 11 lines
Quoted 8 lines

that is better than what we have now.

However, my patch below now causes /usr/lib/libstdc++.a-gdb.py to be built for gcc-runtime, which triggers an error:

ERROR: gcc-runtime-6.3.0-r0 do_package: QA Issue: gcc-runtime:
Files/directories were installed but not shipped in any package:
/usr/lib/libstdc++.a-gdb.py

That's just a minor follow-up error. The real problem is that libstdc ++.so.6.0.22 was not getting built anymore. The expect .py file then

is

Quoted 4 lines

libstdc++.so.6.0.22-gdb.py.

I'm still unsure about the root cause. Something seems to have gone wrong when building the toolchain, because gcc-runtime doesn't even

have

Quoted 5 lines

-pie in the compiler flags. From log.do_configure:

checking whether the x86_64-refkit-linux-gcc -m64 -march=corei7 -mtune=corei7 -mfpmath=sse -msse4.2 --sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-

64-refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,- z,now linker (x86_64-refkit-linux-ld -- sysroot=/fast/build/refkit/intel-corei7-64/tmp-glibc/work/corei7-64- refkit-linux/gcc-runtime/6.3.0-r0/recipe-sysroot -Wl,-z,relro,-z,now -m elf_x86_64) supports shared libraries... no

Quoted 6 lines

checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... unsupported checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... no

I'm going to put this aside for now, but I remain unhappy about how

we

Quoted 1 line

currently pass -pie in CFLAGS and the workarounds that are getting

used

Quoted 2 lines

as a result of that, like disabling -pie for Python distutils. I understand that that particular change probably only affected very

few

Quoted 1 line

binaries, but it still looks like a workaround and not a proper

solution

Quoted 14 lines

to me.

What do others thing about the current status quo regarding -pie?

--
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.

#20 lore raw
In reply to Adam C. Foltzer

Doesn't work well with some other meson changes we have:

http://errors.yoctoproject.org/Errors/Details/144180/

Quoted 34 lines · Adam C. Foltzer
---
 meta-oe/recipes-devtools/meson/{meson_0.37.1.bb => meson_0.40.1.bb} | 2
+-
 1 file changed, 1 insertion(+), 1 deletion(-)
 rename meta-oe/recipes-devtools/meson/{meson_0.37.1.bb => meson_0.40.1.bb}

(88%)

meta-oe/recipes-devtools/meson/meson_0.40.1.bb renamed from meta-oe/recipes-devtools/meson/meson_0.37.1.bb +1 -2
similarity index 88%
rename from meta-oe/recipes-devtools/meson/meson_0.37.1.bb
rename to meta-oe/recipes-devtools/meson/meson_0.40.1.bb
index dbbea64..fd96b42 100644
@@ -9,7 +9,7 @@ SRC_URI = " \
     file://native_bindir.patch \
 "
 
-SRCREV = "3d4bfdcb22314ea7db45a5b075f8b2a9c1498aab"
+SRCREV = "b25d3e4d3f2b4d37029a507cc089bdde643c6240"
 
 S = "${WORKDIR}/git"
 
--

2.9.4

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