From d4d1c4acb08efb6be4f491cdee5cb6dd4b84ddf7 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Mon, 19 Feb 2018 10:13:44 +0100 Subject: [PATCH] Add PIE option to Makefile to build position independent executables As of version 5.0 Android requires all dynamically linked executables to support PIE. This allows programs to be loaded at a different addresses, making it harder for attackers to target. Enable with PIE=1 --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 82974dcb8..8e3934ba3 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,11 @@ ifeq ($(COVERAGE),1) COVFLAGS = --coverage endif +ifeq ($(PIE),1) +PIE_CFLAGS=-fPIE -fPIC +PIE_LDFLAGS=-pie +endif + PYTEST := $(shell command -v pytest 2> /dev/null) # This is where we add new features as bitcoin adds them. @@ -152,9 +157,9 @@ ALL_PROGRAMS = CPPFLAGS = -DBINTOPKGLIBEXECDIR='"'$(shell sh tools/rel.sh $(bindir) $(pkglibexecdir))'"' CWARNFLAGS := -Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition CDEBUGFLAGS := -std=gnu11 -g -fstack-protector -CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I/usr/local/include $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS +CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I/usr/local/include $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) -LDFLAGS = -L/usr/local/lib +LDFLAGS = -L/usr/local/lib $(PIE_LDFLAGS) LDLIBS = -lm -lgmp -lsqlite3 $(COVFLAGS) default: all-programs all-test-programs