aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-04 11:28:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-04 11:28:24 +0000
commit1da86d2f40f304d78b2ae4aac3b590b19adc7ce3 (patch)
tree6f2a87934ad24c0e640c6313d56d2e28d1e81185
parent1e93f3c5859aeebcca7c0480de2bd038defe8b1c (diff)
downloadbusybox-w32-1da86d2f40f304d78b2ae4aac3b590b19adc7ce3.tar.gz
busybox-w32-1da86d2f40f304d78b2ae4aac3b590b19adc7ce3.tar.bz2
busybox-w32-1da86d2f40f304d78b2ae4aac3b590b19adc7ce3.zip
build system: add PIE build option
-rw-r--r--Config.in8
-rw-r--r--Makefile4
-rw-r--r--Makefile.flags20
-rw-r--r--scripts/Makefile.IMA6
-rw-r--r--scripts/Makefile.build4
5 files changed, 32 insertions, 10 deletions
diff --git a/Config.in b/Config.in
index a991b8a81..3b374967b 100644
--- a/Config.in
+++ b/Config.in
@@ -262,6 +262,14 @@ config STATIC
262 262
263 Most people will leave this set to 'N'. 263 Most people will leave this set to 'N'.
264 264
265config PIE
266 bool "Build BusyBox as a position independent executable"
267 default n
268 depends on !STATIC
269 help
270 (TODO: what is it and why/when is it useful?)
271 Most people will leave this set to 'N'.
272
265config NOMMU 273config NOMMU
266 bool "Force NOMMU build" 274 bool "Force NOMMU build"
267 default n 275 default n
diff --git a/Makefile b/Makefile
index aad67a1a8..308ea42cd 100644
--- a/Makefile
+++ b/Makefile
@@ -315,6 +315,8 @@ AFLAGS_KERNEL =
315# Use LINUXINCLUDE when you must reference the include/ directory. 315# Use LINUXINCLUDE when you must reference the include/ directory.
316# Needed to be compatible with the O= option 316# Needed to be compatible with the O= option
317CFLAGS := $(CFLAGS) 317CFLAGS := $(CFLAGS)
318# Added only to final link stage of busybox binary
319CFLAGS_busybox := $(CFLAGS_busybox)
318CPPFLAGS := $(CPPFLAGS) 320CPPFLAGS := $(CPPFLAGS)
319AFLAGS := $(AFLAGS) 321AFLAGS := $(AFLAGS)
320LDFLAGS := $(LDFLAGS) 322LDFLAGS := $(LDFLAGS)
@@ -580,7 +582,7 @@ quiet_cmd_busybox__ ?= LINK $@
580 cmd_busybox__ ?= $(srctree)/scripts/trylink \ 582 cmd_busybox__ ?= $(srctree)/scripts/trylink \
581 "$@" \ 583 "$@" \
582 "$(CC)" \ 584 "$(CC)" \
583 "$(CFLAGS)" \ 585 "$(CFLAGS) $(CFLAGS_busybox)" \
584 "$(LDFLAGS) $(EXTRA_LDFLAGS)" \ 586 "$(LDFLAGS) $(EXTRA_LDFLAGS)" \
585 "$(core-y)" \ 587 "$(core-y)" \
586 "$(libs-y)" \ 588 "$(libs-y)" \
diff --git a/Makefile.flags b/Makefile.flags
index 9525889c6..1cfda26ac 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -50,17 +50,31 @@ ifeq ($(CONFIG_DEBUG),y)
50CFLAGS += $(call cc-option,-g) 50CFLAGS += $(call cc-option,-g)
51endif 51endif
52 52
53# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
54ARCH_FPIC ?= -fpic
55ARCH_FPIE ?= -fpie
56ARCH_PIE ?= -pie
57
53ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y) 58ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
54# on i386: 14% smaller libbusybox.so 59# on i386: 14% smaller libbusybox.so
55# (code itself is 9% bigger, we save on relocs/PLT/GOT) 60# (code itself is 9% bigger, we save on relocs/PLT/GOT)
56CFLAGS += -fpic 61CFLAGS += $(ARCH_FPIC)
57# and another 4% reduction of libbusybox.so: 62# and another 4% reduction of libbusybox.so:
58# (external entry points must be marked EXTERNALLY_VISIBLE) 63# (external entry points must be marked EXTERNALLY_VISIBLE)
59CFLAGS += $(call cc-option,-fvisibility=hidden) 64CFLAGS += $(call cc-option,-fvisibility=hidden)
60endif 65endif
61 66
62ifeq ($(CONFIG_STATIC),y) 67ifeq ($(CONFIG_STATIC),y)
63LDFLAGS += -static 68CFLAGS_busybox += -static
69endif
70
71ifeq ($(CONFIG_PIE),y)
72CFLAGS_busybox += $(ARCH_PIE)
73CFLAGS += $(ARCH_FPIE)
74# No switch() jump tables. Code growth +1k, binary size down -12k
75# due to reduced number of code pointers.
76# (TODO: make overridable: some arches may want to not do this)
77CFLAGS += $(call cc-option,-fno-jump-tables)
64endif 78endif
65 79
66LDLIBS += m crypt 80LDLIBS += m crypt
@@ -81,8 +95,6 @@ ifeq ($(CONFIG_DMALLOC),y)
81LDLIBS += dmalloc 95LDLIBS += dmalloc
82endif 96endif
83 97
84#LDFLAGS += -nostdlib
85
86LDFLAGS_ELF2FLT = -Wl,-elf2flt 98LDFLAGS_ELF2FLT = -Wl,-elf2flt
87ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS))) 99ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
88SKIP_STRIP = y 100SKIP_STRIP = y
diff --git a/scripts/Makefile.IMA b/scripts/Makefile.IMA
index 988c6a6d1..a34db50f4 100644
--- a/scripts/Makefile.IMA
+++ b/scripts/Makefile.IMA
@@ -45,8 +45,8 @@ STRIP = $(CROSS_COMPILE)strip
45OBJCOPY = $(CROSS_COMPILE)objcopy 45OBJCOPY = $(CROSS_COMPILE)objcopy
46OBJDUMP = $(CROSS_COMPILE)objdump 46OBJDUMP = $(CROSS_COMPILE)objdump
47 47
48CFLAGS := $(CFLAGS) 48CFLAGS := $(CFLAGS)
49CPPFLAGS+= -D"KBUILD_STR(s)=\#s" #-Q 49CPPFLAGS += -D"KBUILD_STR(s)=\#s" #-Q
50 50
51# We need some generic definitions 51# We need some generic definitions
52include $(srctree)/scripts/Kbuild.include 52include $(srctree)/scripts/Kbuild.include
@@ -180,7 +180,7 @@ busybox_unstripped.o: $(usage_stuff) include/applet_tables.h include/autoconf.h
180busybox: busybox_unstripped.o 180busybox: busybox_unstripped.o
181 $(srctree)/scripts/trylink \ 181 $(srctree)/scripts/trylink \
182 busybox_unstripped \ 182 busybox_unstripped \
183 "$(CC)" \ 183 "$(CC) $(CFLAGS_busybox)" \
184 "$(CFLAGS)" \ 184 "$(CFLAGS)" \
185 "$(LDFLAGS)" \ 185 "$(LDFLAGS)" \
186 "busybox_unstripped.o" \ 186 "busybox_unstripped.o" \
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ddefea5a6..f343818b1 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -251,8 +251,8 @@ ifdef builtin-target
251quiet_cmd_link_o_target = LD $@ 251quiet_cmd_link_o_target = LD $@
252# If the list of objects to link is empty, just create an empty built-in.o 252# If the list of objects to link is empty, just create an empty built-in.o
253cmd_link_o_target = $(if $(strip $(obj-y)),\ 253cmd_link_o_target = $(if $(strip $(obj-y)),\
254 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\ 254 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
255 rm -f $@; $(AR) rcs $@) 255 rm -f $@; $(AR) rcs $@)
256 256
257$(builtin-target): $(obj-y) FORCE 257$(builtin-target): $(obj-y) FORCE
258 $(call if_changed,link_o_target) 258 $(call if_changed,link_o_target)