Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
Date: 2005-02-04
Initial Package Version: 3.2.4
Upstream Status: Not submitted
Origin: None
Description: Check for gcc -fpie, -fpic, -fstack-protector, and ld -pie,
-z relro, -z now. Use whatever works.

See:
http://www.linuxfromscratch.org/~robert/Homogenic/

diff -Naur procps-3.2.4.orig/Makefile procps-3.2.4/Makefile
--- procps-3.2.4.orig/Makefile	2005-02-04 12:33:13.010142448 +0000
+++ procps-3.2.4/Makefile	2005-02-04 12:33:22.857645400 +0000
@@ -93,10 +93,12 @@
 # an option that starts with "-g". (-g, -g2, -g3, -ggdb, etc.)
 CFLAGS       := -O2 -s
 ALL_CFLAGS   := $(PKG_CFLAGS) $(CFLAGS)
+EXE_CFLAGS  :=
 
 PKG_LDFLAGS  := -Wl,-warn-common
 LDFLAGS      :=
 ALL_LDFLAGS  := $(PKG_LDFLAGS) $(LDFLAGS)
+EXE_LDFLAGS :=
 
 ############ Add some extra flags if gcc allows
 
@@ -137,6 +139,13 @@
 # in case -O3 is enabled, avoid bloat
 ALL_CFLAGS += $(call check_gcc,-fno-inline-functions,)
 
+# Extra stuff.
+ALL_CFLAGS += $(call check_gcc,-fstack-protector-all,)
+EXE_CFLAGS += $(call check_gcc,-pie -fpie,)
+EXE_LDFLAGS += $(call check_gcc,-pie,)
+ALL_LDFLAGS += $(call check_gcc,-z relro,)
+ALL_LDFLAGS += $(call check_gcc,-z now,)
+
 endif
 endif
 endif
@@ -225,21 +234,24 @@
 top.o : top.h
 
 %.o : %.c
-	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<
+	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(EXE_CFLAGS) -c -o $@ $<
 
 w.o:    w.c
-	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(W_SHOWFROM) -c $<
+	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(EXE_CFLAGS) $(W_SHOWFROM) -c $<
 
 ############ prog.o --> prog
 
 pmap w uptime tload free sysctl vmstat utmp pgrep skill pwdx: % : %.o $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@
+	$(CC) $(ALL_CFLAGS) $(EXE_CFLAGS) $^ $(ALL_LDFLAGS) \
+		$(EXE_LDFLAGS) -o $@
 
 slabtop top: % : %.o $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES)
+	$(CC) $(ALL_CFLAGS) $(EXE_CFLAGS) $^ $(ALL_LDFLAGS) \
+		$(EXE_LDFLAGS) -o $@ $(CURSES)
 
 watch: % : %.o
-	$(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES)
+	$(CC) $(ALL_CFLAGS) $(EXE_CFLAGS) $^ $(ALL_LDFLAGS) \
+		$(EXE_LDFLAGS) -o $@ $(CURSES)
 
 ############ progX --> progY
 
diff -Naur procps-3.2.4.orig/ps/module.mk procps-3.2.4/ps/module.mk
--- procps-3.2.4.orig/ps/module.mk	2005-02-04 12:33:13.037138344 +0000
+++ procps-3.2.4/ps/module.mk	2005-02-04 12:36:43.652120000 +0000
@@ -20,14 +20,15 @@
 TARFILES += $(PSSRC) $(addprefix ps/,$(PS_X))
 
 ps/ps: $(PSOBJ) $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^
+	$(CC) $(ALL_CFLAGS) $(EXE_CFLAGS) $(ALL_LDFLAGS) $(EXE_LDFLAGS) -o $@ $^
 
 # This just adds the stacktrace code
 ps/debug: $(PSOBJ) stacktrace.o $(LIBPROC)
-	$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^ -lefence
+	$(CC) $(ALL_CFLAGS) $(EXE_CFLAGS) $(ALL_LDFLAGS) \
+		$(EXE_LDFLAGS) -o $@ $^ -lefence
 
 $(PSOBJ): %.o: %.c ps/common.h $(LIBPROC)
-	$(CC) -c $(ALL_CPPFLAGS) $(ALL_CFLAGS) $< -o $@
+	$(CC) -c $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(EXE_CFLAGS) $< -o $@
 
 ps/stacktrace.o: ps/stacktrace.c
 
