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
This commit is contained in:
Igor Cota 2018-02-19 10:13:44 +01:00 committed by Rusty Russell
parent c360cb7b1f
commit d4d1c4acb0

View file

@ -32,6 +32,11 @@ ifeq ($(COVERAGE),1)
COVFLAGS = --coverage COVFLAGS = --coverage
endif endif
ifeq ($(PIE),1)
PIE_CFLAGS=-fPIE -fPIC
PIE_LDFLAGS=-pie
endif
PYTEST := $(shell command -v pytest 2> /dev/null) PYTEST := $(shell command -v pytest 2> /dev/null)
# This is where we add new features as bitcoin adds them. # 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))'"' CPPFLAGS = -DBINTOPKGLIBEXECDIR='"'$(shell sh tools/rel.sh $(bindir) $(pkglibexecdir))'"'
CWARNFLAGS := -Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition CWARNFLAGS := -Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition
CDEBUGFLAGS := -std=gnu11 -g -fstack-protector 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) LDLIBS = -lm -lgmp -lsqlite3 $(COVFLAGS)
default: all-programs all-test-programs default: all-programs all-test-programs