Skip to contentSkip to conversation

pseudo: Fix build when security flags are enabled

PATCH New Khem Raj 1 participant 2 messages Feb 17, 2016

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/2 pseudo: Fix build when security flags are enabled

filter out PIE options

---
 .../files/0001-configure-Prune-PIE-flags.patch     | 44 ++++++++++++++++++++++
 meta/recipes-devtools/pseudo/pseudo_1.7.5.bb       |  1 +
 2 files changed, 45 insertions(+)
 create mode 100644 meta/recipes-devtools/pseudo/files/0001-configure-Prune-PIE-flags.patch
meta/recipes-devtools/pseudo/files/0001-configure-Prune-PIE-flags.patch new file +44 -0
new file mode 100644
index 0000000..43504ea
@@ -0,0 +1,44 @@
+From b5545c08e6c674c49aef14b47a56a3e92df4d2a7 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Wed, 17 Feb 2016 07:36:34 +0000
+Subject: [pseudo][PATCH] configure: Prune PIE flags
+
+LDFLAGS are not taken from environment and CFLAGS is used for LDFLAGS
+however when using security options -fpie and -pie options are coming
+as part of ARCH_FLAGS and they get into LDFLAGS of shared objects as
+well so we end up with conflicting options -shared -pie, which gold
+rejects outright and bfd linker lets the one appearning last in cmdline
+take effect. This create quite a unpleasant situation in OE when
+security flags are enabled and gold or not-gold options are used
+it errors out but errors are not same.
+
+Anyway, with this patch we filter pie options from ARCH_FLAGS
+ouright and take control of generating PIC objects
+
+Helps with errors like
+
+| /mnt/oe/build/tmp-glibc/sysroots/x86_64-linux/usr/libexec/x86_64-oe-linux/gcc/x86_64-oe-linux/5.3.0/ld: pseudo_client.o: relocation R_X86_64_PC32 against symbol `pseudo_util_debug_flags' can not be used when making a shared object; recompile with -fPIC
+| /mnt/oe/build/tmp-glibc/sysroots/x86_64-linux/usr/libexec/x86_64-oe-linux/gcc/x86_64-oe-linux/5.3.0/ld: final link failed: Bad value
+| collect2: error: ld returned 1 exit status
+| make: *** [lib/pseudo/lib64/libpseudo.so] Error 1
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Submitted
+
+ configure | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/configure b/configure
+index e5ef9ce..83b0890 100755
+--- a/configure
++++ b/configure
+@@ -339,3 +339,5 @@ sed -e '
+   s,@ARCH@,'"$opt_arch"',g
+   s,@BITS@,'"$opt_bits"',g
+ ' < Makefile.in > Makefile
++
++sed -i -e 's/\-[f]*pie//g' Makefile
+-- 
+1.8.3.1
+
meta/recipes-devtools/pseudo/pseudo_1.7.5.bb +1 -0
index 195a508..88bd1f5 100644
@@ -2,6 +2,7 @@ require pseudo.inc
 
 SRC_URI = " \
     http://downloads.yoctoproject.org/releases/pseudo/${BPN}-${PV}.tar.bz2 \
+    file://0001-configure-Prune-PIE-flags.patch \
     file://fallback-passwd \
     file://fallback-group \
 "
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 libnewt: Fix build with PIE flags

security flags add -pie -fpie to CFLAGS which is not right options for compiling .so files, they are only useful for compiling executables

---
 meta/recipes-extended/newt/files/pie-flags.patch | 36 ++++++++++++++++++++++++
 meta/recipes-extended/newt/libnewt_0.52.18.bb    |  2 ++
 2 files changed, 38 insertions(+)
 create mode 100644 meta/recipes-extended/newt/files/pie-flags.patch
meta/recipes-extended/newt/files/pie-flags.patch new file +36 -0
new file mode 100644
index 0000000..8883e26
@@ -0,0 +1,36 @@
+specify -fPIC after CFLAGS so it can override the CFLAGS containing -pie and -fpie
+this makes sure the objects that go into shared objects are compiled with -fPIC
+and not with -fpie. We can not use -fpie on objects which will go into .so files
+Fixes errors like
+
+| /mnt/oe/build/tmp-glibc/sysroots/x86_64-linux/usr/libexec/x86_64-oe-linux/gcc/x86_64-oe-linux/5.3.0/ld: shared/newt.o: relocation R_X86_64_PC32 against undefined symbol `SLtt_Screen_Rows@@SLANG2' can not be used when making a shared object; recompile with -fPIC
+| /mnt/oe/build/tmp-glibc/sysroots/x86_64-linux/usr/libexec/x86_64-oe-linux/gcc/x86_64-oe-linux/5.3.0/ld: final link failed: Bad value
+| collect2: error: ld returned 1 exit status
+| make: *** [libnewt.so.0.52.18] Error 1
+
+Signed-off-by: Khem Raj <[email protected]>
+Upstream-Status: Pending
+Index: newt-0.52.18/Makefile.in
+===================================================================
+--- newt-0.52.18.orig/Makefile.in
++++ newt-0.52.18/Makefile.in
+@@ -96,8 +96,8 @@ _snack.$(SOEXT):   snack.c $(LIBNEWTSH)
+ 		PIFLAGS=`$$pyconfig --includes`; \
+ 		PLDFLAGS=`$$pyconfig --ldflags`; \
+ 		PLFLAGS=`$$pyconfig --libs`; \
+-		echo $(CC) $(SHCFLAGS) $(CPPFLAGS) $$PIFLAGS $$PCFLAGS -c -o $$ver/snack.o snack.c; \
+-		$(CC) $(SHCFLAGS) $(CPPFLAGS) $$PIFLAGS $$PCFLAGS -c -o $$ver/snack.o snack.c; \
++		echo $(CC) $(CPPFLAGS) $(SHCFLAGS) $$PIFLAGS $$PCFLAGS -c -o $$ver/snack.o snack.c; \
++		$(CC) $(CPPFLAGS) $(SHCFLAGS) $$PIFLAGS $$PCFLAGS -c -o $$ver/snack.o snack.c; \
+ 		echo $(CC) --shared $$PLDFLAGS $$PLFLAGS $(LDFLAGS) -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L.  -lnewt $(LIBS); \
+ 		$(CC) --shared $$PLDFLAGS $$PLFLAGS $(LDFLAGS) -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L.  -lnewt $(LIBS); \
+ 	done || :
+@@ -135,7 +135,7 @@ $(LIBNEWTSH): $(SHAREDOBJS)
+ 	ln -fs $(LIBNEWTSH) $(LIBNEWTSONAME)
+ 
+ $(SHAREDDIR)/%.o : %.c $(SHAREDDIR)
+-	$(CC) $(SHCFLAGS) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
++	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(SHCFLAGS) -o $@ $<
+ 
+ install: $(LIBNEWT) install-sh whiptail
+ 	[ -d $(instroot)/$(bindir) ] || install -m 755 -d $(instroot)/$(bindir)
meta/recipes-extended/newt/libnewt_0.52.18.bb +2 -0
index 293c1a8..9a2964b 100644
@@ -22,6 +22,7 @@ SRC_URI = "https://fedorahosted.org/releases/n/e/newt/newt-${PV}.tar.gz \
            file://fix_SHAREDDIR.patch \
            file://cross_ar.patch \
            file://Makefile.in-Add-tinfo-library-to-the-linking-librari.patch \
+           file://pie-flags.patch \
 "
 
 SRC_URI[md5sum] = "685721bee1a318570704b19dcf31d268"
@@ -37,6 +38,7 @@ CLEANBROKEN = "1"
 
 export STAGING_INCDIR
 export STAGING_LIBDIR
+export CPPFLAGS
 
 export BUILD_SYS
 export HOST_SYS
Signature · 1 line
1.8.3.1