From: Andrea Bolognani Date: Sun, 31 Jul 2016 16:56:27 +0000 (+0200) Subject: linux: Enable PIE X-Git-Url: https://code.delx.au/spectrwm/commitdiff_plain/092e5c269ffa08e9d174100a06d0d56ffcc85b69 linux: Enable PIE PIE (position-independent executables) is a security feature that has been made reasonably cheap by recent improvements in GCC; as a result, more and more Linux distributions are pushing for its adoption. Unfortunately, PIE and PIC are not compatible, so we have to manage the CFLAGS and LDFLAGS used to compile the library and the executable indipendently. --- diff --git a/linux/Makefile b/linux/Makefile index 74f648a..bad2b0b 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -17,27 +17,31 @@ ifneq ("${BUILDVERSION}", "") MAINT_CPPFLAGS += -DSPECTRWM_BUILDSTR=\"$(BUILDVERSION)\" endif +BIN_CFLAGS = -fPIE +BIN_LDFLAGS = -fPIE -pie BIN_CPPFLAGS = $(shell pkg-config --cflags x11 x11-xcb xcb-icccm xcb-keysyms xcb-randr xcb-util xcb-xtest xcursor xft) BIN_LDLIBS = $(shell pkg-config --libs x11 x11-xcb xcb-icccm xcb-keysyms xcb-randr xcb-util xcb-xtest xcursor xft) +LIB_CFLAGS = -fPIC +LIB_LDFLAGS = -fPIC -shared LIB_CPPFLAGS = $(shell pkg-config --cflags x11) LIB_LDLIBS = $(shell pkg-config --libs x11) -ldl all: spectrwm libswmhack.so.$(LIBVERSION) spectrwm: spectrwm.o linux.o - $(CC) $(MAINT_LDFLAGS) $(LDFLAGS) -o $@ $+ $(BIN_LDLIBS) $(LDLIBS) + $(CC) $(MAINT_LDFLAGS) $(BIN_LDFLAGS) $(LDFLAGS) -o $@ $+ $(BIN_LDLIBS) $(LDLIBS) spectrwm.o: ../spectrwm.c ../version.h tree.h util.h - $(CC) $(MAINT_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(BIN_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< + $(CC) $(MAINT_CFLAGS) $(BIN_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(BIN_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< linux.o: linux.c util.h - $(CC) $(MAINT_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(BIN_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< + $(CC) $(MAINT_CFLAGS) $(BIN_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(BIN_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< libswmhack.so.$(LIBVERSION): swm_hack.so - $(CC) $(MAINT_LDFLAGS) $(LDFLAGS) -Wl,-soname,$@ -shared -fPIC -o $@ $+ $(LIB_LDLIBS) $(LDLIBS) + $(CC) $(MAINT_LDFLAGS) $(LIB_LDFLAGS) $(LDFLAGS) -Wl,-soname,$@ -o $@ $+ $(LIB_LDLIBS) $(LDLIBS) swm_hack.so: ../lib/swm_hack.c - $(CC) $(MAINT_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(LIB_CPPFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $< + $(CC) $(MAINT_CFLAGS) $(LIB_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(LIB_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< clean: rm -f spectrwm *.o libswmhack.so.* *.so