build system: add PIE build option
This commit is contained in:
parent
1e93f3c585
commit
1da86d2f40
@ -262,6 +262,14 @@ config STATIC
|
|||||||
|
|
||||||
Most people will leave this set to 'N'.
|
Most people will leave this set to 'N'.
|
||||||
|
|
||||||
|
config PIE
|
||||||
|
bool "Build BusyBox as a position independent executable"
|
||||||
|
default n
|
||||||
|
depends on !STATIC
|
||||||
|
help
|
||||||
|
(TODO: what is it and why/when is it useful?)
|
||||||
|
Most people will leave this set to 'N'.
|
||||||
|
|
||||||
config NOMMU
|
config NOMMU
|
||||||
bool "Force NOMMU build"
|
bool "Force NOMMU build"
|
||||||
default n
|
default n
|
||||||
|
4
Makefile
4
Makefile
@ -315,6 +315,8 @@ AFLAGS_KERNEL =
|
|||||||
# Use LINUXINCLUDE when you must reference the include/ directory.
|
# Use LINUXINCLUDE when you must reference the include/ directory.
|
||||||
# Needed to be compatible with the O= option
|
# Needed to be compatible with the O= option
|
||||||
CFLAGS := $(CFLAGS)
|
CFLAGS := $(CFLAGS)
|
||||||
|
# Added only to final link stage of busybox binary
|
||||||
|
CFLAGS_busybox := $(CFLAGS_busybox)
|
||||||
CPPFLAGS := $(CPPFLAGS)
|
CPPFLAGS := $(CPPFLAGS)
|
||||||
AFLAGS := $(AFLAGS)
|
AFLAGS := $(AFLAGS)
|
||||||
LDFLAGS := $(LDFLAGS)
|
LDFLAGS := $(LDFLAGS)
|
||||||
@ -580,7 +582,7 @@ quiet_cmd_busybox__ ?= LINK $@
|
|||||||
cmd_busybox__ ?= $(srctree)/scripts/trylink \
|
cmd_busybox__ ?= $(srctree)/scripts/trylink \
|
||||||
"$@" \
|
"$@" \
|
||||||
"$(CC)" \
|
"$(CC)" \
|
||||||
"$(CFLAGS)" \
|
"$(CFLAGS) $(CFLAGS_busybox)" \
|
||||||
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
|
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
|
||||||
"$(core-y)" \
|
"$(core-y)" \
|
||||||
"$(libs-y)" \
|
"$(libs-y)" \
|
||||||
|
@ -50,17 +50,31 @@ ifeq ($(CONFIG_DEBUG),y)
|
|||||||
CFLAGS += $(call cc-option,-g)
|
CFLAGS += $(call cc-option,-g)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
|
||||||
|
ARCH_FPIC ?= -fpic
|
||||||
|
ARCH_FPIE ?= -fpie
|
||||||
|
ARCH_PIE ?= -pie
|
||||||
|
|
||||||
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
||||||
# on i386: 14% smaller libbusybox.so
|
# on i386: 14% smaller libbusybox.so
|
||||||
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
|
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
|
||||||
CFLAGS += -fpic
|
CFLAGS += $(ARCH_FPIC)
|
||||||
# and another 4% reduction of libbusybox.so:
|
# and another 4% reduction of libbusybox.so:
|
||||||
# (external entry points must be marked EXTERNALLY_VISIBLE)
|
# (external entry points must be marked EXTERNALLY_VISIBLE)
|
||||||
CFLAGS += $(call cc-option,-fvisibility=hidden)
|
CFLAGS += $(call cc-option,-fvisibility=hidden)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_STATIC),y)
|
ifeq ($(CONFIG_STATIC),y)
|
||||||
LDFLAGS += -static
|
CFLAGS_busybox += -static
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_PIE),y)
|
||||||
|
CFLAGS_busybox += $(ARCH_PIE)
|
||||||
|
CFLAGS += $(ARCH_FPIE)
|
||||||
|
# No switch() jump tables. Code growth +1k, binary size down -12k
|
||||||
|
# due to reduced number of code pointers.
|
||||||
|
# (TODO: make overridable: some arches may want to not do this)
|
||||||
|
CFLAGS += $(call cc-option,-fno-jump-tables)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDLIBS += m crypt
|
LDLIBS += m crypt
|
||||||
@ -81,8 +95,6 @@ ifeq ($(CONFIG_DMALLOC),y)
|
|||||||
LDLIBS += dmalloc
|
LDLIBS += dmalloc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#LDFLAGS += -nostdlib
|
|
||||||
|
|
||||||
LDFLAGS_ELF2FLT = -Wl,-elf2flt
|
LDFLAGS_ELF2FLT = -Wl,-elf2flt
|
||||||
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
|
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
|
||||||
SKIP_STRIP = y
|
SKIP_STRIP = y
|
||||||
|
@ -45,8 +45,8 @@ STRIP = $(CROSS_COMPILE)strip
|
|||||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||||
OBJDUMP = $(CROSS_COMPILE)objdump
|
OBJDUMP = $(CROSS_COMPILE)objdump
|
||||||
|
|
||||||
CFLAGS := $(CFLAGS)
|
CFLAGS := $(CFLAGS)
|
||||||
CPPFLAGS+= -D"KBUILD_STR(s)=\#s" #-Q
|
CPPFLAGS += -D"KBUILD_STR(s)=\#s" #-Q
|
||||||
|
|
||||||
# We need some generic definitions
|
# We need some generic definitions
|
||||||
include $(srctree)/scripts/Kbuild.include
|
include $(srctree)/scripts/Kbuild.include
|
||||||
@ -180,7 +180,7 @@ busybox_unstripped.o: $(usage_stuff) include/applet_tables.h include/autoconf.h
|
|||||||
busybox: busybox_unstripped.o
|
busybox: busybox_unstripped.o
|
||||||
$(srctree)/scripts/trylink \
|
$(srctree)/scripts/trylink \
|
||||||
busybox_unstripped \
|
busybox_unstripped \
|
||||||
"$(CC)" \
|
"$(CC) $(CFLAGS_busybox)" \
|
||||||
"$(CFLAGS)" \
|
"$(CFLAGS)" \
|
||||||
"$(LDFLAGS)" \
|
"$(LDFLAGS)" \
|
||||||
"busybox_unstripped.o" \
|
"busybox_unstripped.o" \
|
||||||
|
@ -251,8 +251,8 @@ ifdef builtin-target
|
|||||||
quiet_cmd_link_o_target = LD $@
|
quiet_cmd_link_o_target = LD $@
|
||||||
# If the list of objects to link is empty, just create an empty built-in.o
|
# If the list of objects to link is empty, just create an empty built-in.o
|
||||||
cmd_link_o_target = $(if $(strip $(obj-y)),\
|
cmd_link_o_target = $(if $(strip $(obj-y)),\
|
||||||
$(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
|
$(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
|
||||||
rm -f $@; $(AR) rcs $@)
|
rm -f $@; $(AR) rcs $@)
|
||||||
|
|
||||||
$(builtin-target): $(obj-y) FORCE
|
$(builtin-target): $(obj-y) FORCE
|
||||||
$(call if_changed,link_o_target)
|
$(call if_changed,link_o_target)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user