Skip to contentSkip to conversation

toolchain: add hidden symbol for PIE support

PATCH New Waldemar Brodkorb 3 participants 4 messages Jul 11, 2016 – Jul 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 toolchain: add hidden symbol for PIE support

uClibc-ng does not support PIE for some architectures as arc and m68k. It isn't implemented in the static linking case, too. With musl toolchains you might have static PIE support with little patching of gcc. Static linking for GNU libc isn't enabled in buildroot. Fixup any package using special treatment of PIE. (grep -ir pie package/*/*.mk)

---
v1 -> v2:
- depends on not required, suggested by Thomas Petazzoni

---
 package/bluez_utils/bluez_utils.mk   | 3 +--
 package/cifs-utils/cifs-utils.mk     | 2 +-
 package/libmemcached/libmemcached.mk | 4 +---
 package/libsodium/libsodium.mk       | 2 +-
 package/lvm2/lvm2.mk                 | 2 +-
 package/openssh/openssh.mk           | 7 +------
 package/openswan/openswan.mk         | 4 ++--
 package/pure-ftpd/pure-ftpd.mk       | 2 +-
 package/quagga/quagga.mk             | 2 +-
 package/tinc/tinc.mk                 | 2 +-
 package/trousers/trousers.mk         | 3 +--
 toolchain/Config.in                  | 3 +++
 toolchain/toolchain-common.in        | 3 +++
 13 files changed, 18 insertions(+), 21 deletions(-)
package/bluez_utils/bluez_utils.mk +1 -2
index 91c2905..5885f18 100644
@@ -54,8 +54,7 @@ BLUEZ_UTILS_CONF_OPTS +=	\
 	--disable-usb
 endif
 
-# PIE is broken for m68k
-ifeq ($(BR2_m68k),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 BLUEZ_UTILS_CONF_OPTS += --disable-pie
 endif
 
package/cifs-utils/cifs-utils.mk +1 -1
index c90a504..6ab408a 100644
@@ -10,7 +10,7 @@ CIFS_UTILS_SITE = http://ftp.samba.org/pub/linux-cifs/cifs-utils
 CIFS_UTILS_LICENSE = GPLv3+
 CIFS_UTILS_LICENSE_FILES = COPYING
 
-ifneq ($(BR2_STATIC_LIBS)$(BR2_m68k),)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 CIFS_UTILS_CONF_OPTS += --disable-pie
 endif
 
package/libmemcached/libmemcached.mk +1 -3
index a5ea4f5..1606fdf 100644
@@ -18,9 +18,7 @@ LIBMEMCACHED_AUTORECONF = YES
 LIBMEMCACHED_LICENSE = BSD-3c
 LIBMEMCACHED_LICENSE_FILES = COPYING
 
-# Help libmemcached to understand that -fPIE and -pie should not be
-# used when linking statically.
-ifeq ($(BR2_STATIC_LIBS),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 LIBMEMCACHED_CONF_ENV += \
 	ax_cv_check_cflags__Werror__fPIE=no \
 	ax_cv_check_cflags__Werror__pie=no \
package/libsodium/libsodium.mk +1 -1
index 13dba8d..2ce8f81 100644
@@ -10,7 +10,7 @@ LIBSODIUM_LICENSE = ISC
 LIBSODIUM_LICENSE_FILES = LICENSE
 LIBSODIUM_INSTALL_STAGING = YES
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 LIBSODIUM_CONF_OPTS += --disable-pie
 endif
 
package/lvm2/lvm2.mk +1 -1
index 64eb926..9a45b53 100644
@@ -43,7 +43,7 @@ else
 LVM2_CONF_OPTS += --disable-applib
 endif
 
-ifeq ($(BR2_arc)$(BR2_m68k),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 LVM2_CONF_ENV += ac_cv_flag_HAVE_PIE=no
 endif
 
package/openssh/openssh.mk +1 -6
index 856646c..32d2929 100644
@@ -22,12 +22,7 @@ define OPENSSH_USERS
 	sshd -1 sshd -1 * - - - SSH drop priv user
 endef
 
-# uClibc toolchain for ARC doesn't support PIE at the moment
-ifeq ($(BR2_arc),y)
-OPENSSH_CONF_OPTS += --without-pie
-endif
-# PIE and static does not work on Linux
-ifeq ($(BR2_STATIC_LIBS),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 OPENSSH_CONF_OPTS += --without-pie
 endif
 
package/openswan/openswan.mk +2 -2
index 54bd4b3..5bf9bb6 100644
@@ -11,8 +11,8 @@ OPENSWAN_LICENSE_FILES = COPYING LICENSE
 
 OPENSWAN_DEPENDENCIES = host-bison host-flex gmp iproute2
 OPENSWAN_MAKE_OPTS = ARCH=$(BR2_ARCH) CC="$(TARGET_CC)" \
-	USERCOMPILE="$(TARGET_CFLAGS) $(if $(BR2_STATIC_LIBS),,-fPIE)" \
-	USERLINK="$(TARGET_LDFLAGS) $(if $(BR2_STATIC_LIBS),,-fPIE)" \
+	USERCOMPILE="$(TARGET_CFLAGS) $(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),-fPIE,)" \
+	USERLINK="$(TARGET_LDFLAGS) $(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),-fPIE,)" \
 	INC_USRLOCAL=/usr USE_KLIPS=false USE_MAST=false USE_NM=false
 
 ifeq ($(BR2_PACKAGE_LIBCURL),y)
package/pure-ftpd/pure-ftpd.mk +1 -1
index e1040fa..db1d82f 100644
@@ -41,7 +41,7 @@ else
 PURE_FTPD_CONF_OPTS += --without-tls
 endif
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 PURE_FTPD_CONF_ENV += ax_cv_check_cflags___fPIE=no ax_cv_check_ldflags___fPIE=no
 endif
 
package/quagga/quagga.mk +1 -1
index 1bbc72d..3954509 100644
@@ -68,7 +68,7 @@ else
 QUAGGA_CONF_OPTS += --disable-vtysh
 endif
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 QUAGGA_CONF_OPTS += --disable-pie
 endif
 
package/tinc/tinc.mk +1 -1
index cb0785b..1cc4cbd 100644
@@ -11,7 +11,7 @@ TINC_LICENSE = GPLv2+ with OpenSSL exception
 TINC_LICENSE_FILES = COPYING COPYING.README
 TINC_CONF_ENV = CFLAGS="$(TARGET_CFLAGS) -std=c99"
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 TINC_CONF_ENV += \
 	ax_cv_check_cflags___fPIE=no \
 	ax_cv_check_ldflags___pie=no
package/trousers/trousers.mk +1 -2
index 70daa88..f0932e7 100644
@@ -23,8 +23,7 @@ endif
 # workaround.
 TROUSERS_CONF_OPTS += --disable-usercheck
 
-# uClibc toolchain for ARC doesn't support PIE at the moment
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 TROUSERS_CONF_ENV += \
 	ax_cv_check_cflags___fPIE__DPIE=no \
 	ax_cv_check_ldflags___pie=no
toolchain/Config.in +3 -0
index b49588f..35db809 100644
@@ -15,9 +15,11 @@ config BR2_TOOLCHAIN_USES_GLIBC
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
 	select BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
+	select BR2_TOOLCHAIN_SUPPORTS_PIE
 
 config BR2_TOOLCHAIN_USES_UCLIBC
 	bool
+	select BR2_TOOLCHAIN_SUPPORTS_PIE if !BR2_arc && !BR2_m68k && !BR2_STATIC_LIBS
 
 config BR2_TOOLCHAIN_USES_MUSL
 	bool
@@ -26,6 +28,7 @@ config BR2_TOOLCHAIN_USES_MUSL
 	select BR2_TOOLCHAIN_HAS_THREADS
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
+	select BR2_TOOLCHAIN_SUPPORTS_PIE
 
 choice
 	prompt "Toolchain type"
toolchain/toolchain-common.in +3 -0
index 65df31b..d69acf2 100644
@@ -39,6 +39,9 @@ config BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
 config BR2_TOOLCHAIN_HAS_SSP
 	bool
 
+config BR2_TOOLCHAIN_SUPPORTS_PIE
+	bool
+
 config BR2_ENABLE_LOCALE_PURGE
 	bool "Purge unwanted locales"
 	help
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/1 toolchain: add hidden symbol for PIE support

Hi Waldemar,

Le 11/07/2016 ? 16:35, Waldemar Brodkorb a ?crit :

Quoted 186 lines

uClibc-ng does not support PIE for some architectures as arc and m68k. It isn't implemented in the static linking case, too. With musl toolchains you might have static PIE support with little patching of gcc. Static linking for GNU libc isn't enabled in buildroot. Fixup any package using special treatment of PIE. (grep -ir pie package/*/*.mk)

---
v1 -> v2:
- depends on not required, suggested by Thomas Petazzoni

---
 package/bluez_utils/bluez_utils.mk   | 3 +--
 package/cifs-utils/cifs-utils.mk     | 2 +-
 package/libmemcached/libmemcached.mk | 4 +---
 package/libsodium/libsodium.mk       | 2 +-
 package/lvm2/lvm2.mk                 | 2 +-
 package/openssh/openssh.mk           | 7 +------
 package/openswan/openswan.mk         | 4 ++--
 package/pure-ftpd/pure-ftpd.mk       | 2 +-
 package/quagga/quagga.mk             | 2 +-
 package/tinc/tinc.mk                 | 2 +-
 package/trousers/trousers.mk         | 3 +--
 toolchain/Config.in                  | 3 +++
 toolchain/toolchain-common.in        | 3 +++
 13 files changed, 18 insertions(+), 21 deletions(-)
package/bluez_utils/bluez_utils.mk +1 -2
index 91c2905..5885f18 100644
@@ -54,8 +54,7 @@ BLUEZ_UTILS_CONF_OPTS +=	\
 	--disable-usb
 endif
 
-# PIE is broken for m68k
-ifeq ($(BR2_m68k),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 BLUEZ_UTILS_CONF_OPTS += --disable-pie
 endif
 
package/cifs-utils/cifs-utils.mk +1 -1
index c90a504..6ab408a 100644
@@ -10,7 +10,7 @@ CIFS_UTILS_SITE = http://ftp.samba.org/pub/linux-cifs/cifs-utils
 CIFS_UTILS_LICENSE = GPLv3+
 CIFS_UTILS_LICENSE_FILES = COPYING
 
-ifneq ($(BR2_STATIC_LIBS)$(BR2_m68k),)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 CIFS_UTILS_CONF_OPTS += --disable-pie
 endif
 
package/libmemcached/libmemcached.mk +1 -3
index a5ea4f5..1606fdf 100644
@@ -18,9 +18,7 @@ LIBMEMCACHED_AUTORECONF = YES
 LIBMEMCACHED_LICENSE = BSD-3c
 LIBMEMCACHED_LICENSE_FILES = COPYING
 
-# Help libmemcached to understand that -fPIE and -pie should not be
-# used when linking statically.
-ifeq ($(BR2_STATIC_LIBS),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 LIBMEMCACHED_CONF_ENV += \
 	ax_cv_check_cflags__Werror__fPIE=no \
 	ax_cv_check_cflags__Werror__pie=no \
package/libsodium/libsodium.mk +1 -1
index 13dba8d..2ce8f81 100644
@@ -10,7 +10,7 @@ LIBSODIUM_LICENSE = ISC
 LIBSODIUM_LICENSE_FILES = LICENSE
 LIBSODIUM_INSTALL_STAGING = YES
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 LIBSODIUM_CONF_OPTS += --disable-pie
 endif
 
package/lvm2/lvm2.mk +1 -1
index 64eb926..9a45b53 100644
@@ -43,7 +43,7 @@ else
 LVM2_CONF_OPTS += --disable-applib
 endif
 
-ifeq ($(BR2_arc)$(BR2_m68k),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 LVM2_CONF_ENV += ac_cv_flag_HAVE_PIE=no
 endif
 
package/openssh/openssh.mk +1 -6
index 856646c..32d2929 100644
@@ -22,12 +22,7 @@ define OPENSSH_USERS
 	sshd -1 sshd -1 * - - - SSH drop priv user
 endef
 
-# uClibc toolchain for ARC doesn't support PIE at the moment
-ifeq ($(BR2_arc),y)
-OPENSSH_CONF_OPTS += --without-pie
-endif
-# PIE and static does not work on Linux
-ifeq ($(BR2_STATIC_LIBS),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 OPENSSH_CONF_OPTS += --without-pie
 endif
 
package/openswan/openswan.mk +2 -2
index 54bd4b3..5bf9bb6 100644
@@ -11,8 +11,8 @@ OPENSWAN_LICENSE_FILES = COPYING LICENSE
 
 OPENSWAN_DEPENDENCIES = host-bison host-flex gmp iproute2
 OPENSWAN_MAKE_OPTS = ARCH=$(BR2_ARCH) CC="$(TARGET_CC)" \
-	USERCOMPILE="$(TARGET_CFLAGS) $(if $(BR2_STATIC_LIBS),,-fPIE)" \
-	USERLINK="$(TARGET_LDFLAGS) $(if $(BR2_STATIC_LIBS),,-fPIE)" \
+	USERCOMPILE="$(TARGET_CFLAGS) $(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),-fPIE,)" \
+	USERLINK="$(TARGET_LDFLAGS) $(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),-fPIE,)" \
 	INC_USRLOCAL=/usr USE_KLIPS=false USE_MAST=false USE_NM=false
 
 ifeq ($(BR2_PACKAGE_LIBCURL),y)
package/pure-ftpd/pure-ftpd.mk +1 -1
index e1040fa..db1d82f 100644
@@ -41,7 +41,7 @@ else
 PURE_FTPD_CONF_OPTS += --without-tls
 endif
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 PURE_FTPD_CONF_ENV += ax_cv_check_cflags___fPIE=no ax_cv_check_ldflags___fPIE=no
 endif
 
package/quagga/quagga.mk +1 -1
index 1bbc72d..3954509 100644
@@ -68,7 +68,7 @@ else
 QUAGGA_CONF_OPTS += --disable-vtysh
 endif
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 QUAGGA_CONF_OPTS += --disable-pie
 endif
 
package/tinc/tinc.mk +1 -1
index cb0785b..1cc4cbd 100644
@@ -11,7 +11,7 @@ TINC_LICENSE = GPLv2+ with OpenSSL exception
 TINC_LICENSE_FILES = COPYING COPYING.README
 TINC_CONF_ENV = CFLAGS="$(TARGET_CFLAGS) -std=c99"
 
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 TINC_CONF_ENV += \
 	ax_cv_check_cflags___fPIE=no \
 	ax_cv_check_ldflags___pie=no
package/trousers/trousers.mk +1 -2
index 70daa88..f0932e7 100644
@@ -23,8 +23,7 @@ endif
 # workaround.
 TROUSERS_CONF_OPTS += --disable-usercheck
 
-# uClibc toolchain for ARC doesn't support PIE at the moment
-ifeq ($(BR2_arc),y)
+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)
 TROUSERS_CONF_ENV += \
 	ax_cv_check_cflags___fPIE__DPIE=no \
 	ax_cv_check_ldflags___pie=no
toolchain/Config.in +0 -0
index b49588f..35db809 100644

toolchain/Config.in config BR2_TOOLCHAIN_USES_GLIBC · line 22

Quoted 8 lines
toolchain/Config.in +2 -0
@@ -15,9 +15,11 @@ config BR2_TOOLCHAIN_USES_GLIBC
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
 	select BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
+	select BR2_TOOLCHAIN_SUPPORTS_PIE
 
 config BR2_TOOLCHAIN_USES_UCLIBC
 	bool
+	select BR2_TOOLCHAIN_SUPPORTS_PIE if !BR2_arc && !BR2_m68k && !BR2_STATIC_LIBS

It seems that we also need to black list ARM + uClibc + static linking config [1]

Also, what about a test in the toolchain helper to check PIE support is really available ?

In order to ease the review, I would be great if you can split these changes in two patches ?
- add BR2_TOOLCHAIN_SUPPORTS_PIE in the toolchain infra
- use BR2_TOOLCHAIN_SUPPORTS_PIE in packages

[1] http://lists.busybox.net/pipermail/buildroot/2016-July/168309.html

Best regards,
Romain

Quoted 26 lines
toolchain/Config.in +1 -0
 config BR2_TOOLCHAIN_USES_MUSL
 	bool
@@ -26,6 +28,7 @@ config BR2_TOOLCHAIN_USES_MUSL
 	select BR2_TOOLCHAIN_HAS_THREADS
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
+	select BR2_TOOLCHAIN_SUPPORTS_PIE
 
 choice
 	prompt "Toolchain type"
toolchain/toolchain-common.in +3 -0
index 65df31b..d69acf2 100644
@@ -39,6 +39,9 @@ config BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
 config BR2_TOOLCHAIN_HAS_SSP
 	bool
 
+config BR2_TOOLCHAIN_SUPPORTS_PIE
+	bool
+
 config BR2_ENABLE_LOCALE_PURGE
 	bool "Purge unwanted locales"
 	help
#2 lore raw

PATCH v2 1/1 toolchain: add hidden symbol for PIE support

Hello,

Quoted 5 lines · Romain Naour

toolchain/Config.in config BR2_TOOLCHAIN_USES_GLIBC · line 22

Quoted 3 lines

config BR2_TOOLCHAIN_USES_UCLIBC

toolchain/Config.in +1 -0
 	bool
+	select BR2_TOOLCHAIN_SUPPORTS_PIE if !BR2_arc && !BR2_m68k && !BR2_STATIC_LIBS  

It seems that we also need to black list ARM + uClibc + static linking config [1]

Isn't it blacklisted above? Waldemar's code will select BR2_TOOLCHAIN_SUPPORTS_PIE only if we are not on ARC *and* we are not on m68k *and* we are not static linking.

So if you're static linking, !BR2_arc && !BR2_m68k && !BR2_STATIC_LIBS is false, and BR2_TOOLCHAIN_SUPPORTS_PIE is not selected.

Quoted 2 lines

Also, what about a test in the toolchain helper to check PIE support is really available ?

Would be nice, but I'm not sure it's that easy: in practice a simple executable will build with -fPIE on ARC, but more complicated piece of code will not.

Thomas

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

PATCH v2 1/1 toolchain: add hidden symbol for PIE support

In reply to Waldemar Brodkorb

Hello,

Quoted 1 line · Waldemar Brodkorb

+ifneq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),y)

I've changed to positive logic instead:

ifeq ($(BR2_TOOLCHAIN_SUPPORTS_PIE),)

package/openswan/openswan.mk OPENSWAN_LICENSE_FILES = COPYING LICENSE · line 15

Quoted 2 lines
package/openswan/openswan.mk +2 -0
+	USERCOMPILE="$(TARGET_CFLAGS) $(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),-fPIE,)" \
+	USERLINK="$(TARGET_LDFLAGS) $(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),-fPIE,)" \

The final comma was not needed.

Applied with those two changes. Thanks!

Thomas

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