From f39546861225898aa571d3c18805ec54c883e02d Mon Sep 17 00:00:00 2001 From: Oyvind Albrigtsen Date: Tue, 9 Apr 2019 15:38:06 +0200 Subject: [PATCH] build: harden and make it possible to build with -fPIE --- Makefile.top.in | 4 +++- client/Makefile.in | 13 +++++++++++-- common/Makefile.in | 12 ++++++++++++ config/Makefile.in | 2 +- server/Makefile.in | 33 +++++++++++++++++++++------------ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Makefile.top.in b/Makefile.top.in index 981fefa..1e79096 100644 --- a/Makefile.top.in +++ b/Makefile.top.in @@ -2,7 +2,9 @@ CC=@CC@ CXX=@CXX@ CFLAGS=@CFLAGS@ -CFLAGS+=-fPIC -Wall -Wformat=2 -Wstrict-prototypes -Wshadow -D_GNU_SOURCE +CFLAGS+=-Wall -Wformat=2 -Wstrict-prototypes -Wshadow -D_GNU_SOURCE +CXXFLAGS=@CXXFLAGS@ +CXXFLAGS+=-Wall -Wformat=2 -Wstrict-prototypes -Wshadow -D_GNU_SOURCE LEX=@LEX@ YACC=@YACC@ diff --git a/client/Makefile.in b/client/Makefile.in index 4908c00..d3a36b8 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -24,7 +24,7 @@ INCLUDES=-I../include `nss-config --cflags` `nspr-config --cflags` \ `xml2-config --cflags` # nss sucks in way too much stuff -LIBS+=-lnss3 `xml2-config --libs` +LIBS+=-lnss3 `xml2-config --libs` -Wl,-z,now TARGETS=${TARGET} @@ -40,7 +40,16 @@ fence_xvm: ${TARGET} ln -snf $^ $@ fence_virt: ${fence_virt_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -L../common -lfence_virt + $(CC) $(CFLAGS) -o $@ $^ -shared $(LIBS) -L../common -lfence_virt + +mcast.o: mcast.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +options.o: options.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +serial.o: serial.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) %.o: %.c $(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES) diff --git a/common/Makefile.in b/common/Makefile.in index e3b470b..2c88a73 100644 --- a/common/Makefile.in +++ b/common/Makefile.in @@ -24,6 +24,18 @@ all: ${TARGETS} libfence_virt.a: ${libfence_virt_a_SOURCE:.c=.o} ar rc $@ $^ +fdops.o: fdops.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +ip_lookup.o: ip_lookup.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +mcast.o: mcast.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +tcp.o: tcp.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + %.o: %.c $(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES) diff --git a/config/Makefile.in b/config/Makefile.in index 300e9e2..502bcab 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -42,7 +42,7 @@ config.c: y.tab.h config.l $(LEX) -oconfig.c config.l %.o: %.c - $(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES) + $(CC) $(CFLAGS) -fPIE -c -o $@ $^ $(INCLUDES) clean: rm -f ${TARGETS} *~ *.o testprog config.tab.c config.tab.h config.c diff --git a/server/Makefile.in b/server/Makefile.in index afb2ac8..a87342d 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -32,7 +32,7 @@ NSS_LIBS=-lnss3 XML_LIBS=`xml2-config --libs` INCLUDES=-I../include `nss-config --cflags` `nspr-config --cflags` `xml2-config --cflags` -LIBS+=-L../common -lfence_virt -Wl,-wrap,syslog,-wrap,closelog -lpthread -luuid +LIBS+=-L../common -lfence_virt -Wl,-z,now,-wrap,syslog,-wrap,closelog -lpthread -luuid MODULE_PATH=${libdir}/${PACKAGE_NAME} @@ -159,40 +159,49 @@ endif all: ${TARGETS} ${MODULES} fence_virtd: ${fence_virtd_SOURCES:.c=.o} ${fence_virtd_cxx_SOURCES:.cpp=.opp} - $(CXX) -o $@ $^ $(MAIN_LIBS) $(LIBS) + $(CXX) $(CXXFLAGS) -o $@ $^ $(MAIN_LIBS) $(LIBS) multicast.so: ${multicast_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(NSS_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(NSS_LIBS) libvirt.so: ${libvirt_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) libvirt-qmf.so: ${libvirt_qmf_so_SOURCES:.c=.o} ${libvirt_qmf_cxx_so_SOURCES:.cpp=.opp} - $(CXX) -o $@ $^ $(LIBS) -shared $(VIRT_QPID) + $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_QPID) pm-fence.so: ${pm_fence_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(PACEMAKER_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(PACEMAKER_LIBS) cpg.so: ${cpg_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS) $(COROSYNC_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS) $(COROSYNC_LIBS) null.so: ${null_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared serial.so: ${serial_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS) tcp.so: ${tcp_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(NSS_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(NSS_LIBS) vsock.so: ${vsock_so_SOURCES:.c=.o} - $(CC) -o $@ $^ $(LIBS) -shared $(NSS_LIBS) + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(NSS_LIBS) + +cpg-virt.o: cpg-virt.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +virt.o: virt.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) + +virt-serial.o: virt-serial.c + $(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES) %.o: %.c $(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES) %.opp: %.cpp - $(CXX) $(CFLAGS) -c -o $@ $^ $(INCLUDES) + $(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES) install: all if [ ! -d ${DESTDIR}/${sbindir} ]; then \