diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-04 11:28:24 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-04 11:28:24 +0000 |
commit | 1da86d2f40f304d78b2ae4aac3b590b19adc7ce3 (patch) | |
tree | 6f2a87934ad24c0e640c6313d56d2e28d1e81185 | |
parent | 1e93f3c5859aeebcca7c0480de2bd038defe8b1c (diff) | |
download | busybox-w32-1da86d2f40f304d78b2ae4aac3b590b19adc7ce3.tar.gz busybox-w32-1da86d2f40f304d78b2ae4aac3b590b19adc7ce3.tar.bz2 busybox-w32-1da86d2f40f304d78b2ae4aac3b590b19adc7ce3.zip |
build system: add PIE build option
-rw-r--r-- | Config.in | 8 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | Makefile.flags | 20 | ||||
-rw-r--r-- | scripts/Makefile.IMA | 6 | ||||
-rw-r--r-- | scripts/Makefile.build | 4 |
5 files changed, 32 insertions, 10 deletions
@@ -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 | ||
265 | config 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 | |||
265 | config NOMMU | 273 | config NOMMU |
266 | bool "Force NOMMU build" | 274 | bool "Force NOMMU build" |
267 | default n | 275 | default n |
@@ -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 |
317 | CFLAGS := $(CFLAGS) | 317 | CFLAGS := $(CFLAGS) |
318 | # Added only to final link stage of busybox binary | ||
319 | CFLAGS_busybox := $(CFLAGS_busybox) | ||
318 | CPPFLAGS := $(CPPFLAGS) | 320 | CPPFLAGS := $(CPPFLAGS) |
319 | AFLAGS := $(AFLAGS) | 321 | AFLAGS := $(AFLAGS) |
320 | LDFLAGS := $(LDFLAGS) | 322 | LDFLAGS := $(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) | |||
50 | CFLAGS += $(call cc-option,-g) | 50 | CFLAGS += $(call cc-option,-g) |
51 | endif | 51 | endif |
52 | 52 | ||
53 | # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)... | ||
54 | ARCH_FPIC ?= -fpic | ||
55 | ARCH_FPIE ?= -fpie | ||
56 | ARCH_PIE ?= -pie | ||
57 | |||
53 | ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y) | 58 | ifeq ($(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) |
56 | CFLAGS += -fpic | 61 | CFLAGS += $(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) |
59 | CFLAGS += $(call cc-option,-fvisibility=hidden) | 64 | CFLAGS += $(call cc-option,-fvisibility=hidden) |
60 | endif | 65 | endif |
61 | 66 | ||
62 | ifeq ($(CONFIG_STATIC),y) | 67 | ifeq ($(CONFIG_STATIC),y) |
63 | LDFLAGS += -static | 68 | CFLAGS_busybox += -static |
69 | endif | ||
70 | |||
71 | ifeq ($(CONFIG_PIE),y) | ||
72 | CFLAGS_busybox += $(ARCH_PIE) | ||
73 | CFLAGS += $(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) | ||
77 | CFLAGS += $(call cc-option,-fno-jump-tables) | ||
64 | endif | 78 | endif |
65 | 79 | ||
66 | LDLIBS += m crypt | 80 | LDLIBS += m crypt |
@@ -81,8 +95,6 @@ ifeq ($(CONFIG_DMALLOC),y) | |||
81 | LDLIBS += dmalloc | 95 | LDLIBS += dmalloc |
82 | endif | 96 | endif |
83 | 97 | ||
84 | #LDFLAGS += -nostdlib | ||
85 | |||
86 | LDFLAGS_ELF2FLT = -Wl,-elf2flt | 98 | LDFLAGS_ELF2FLT = -Wl,-elf2flt |
87 | ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS))) | 99 | ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS))) |
88 | SKIP_STRIP = y | 100 | SKIP_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 | |||
45 | OBJCOPY = $(CROSS_COMPILE)objcopy | 45 | OBJCOPY = $(CROSS_COMPILE)objcopy |
46 | OBJDUMP = $(CROSS_COMPILE)objdump | 46 | OBJDUMP = $(CROSS_COMPILE)objdump |
47 | 47 | ||
48 | CFLAGS := $(CFLAGS) | 48 | CFLAGS := $(CFLAGS) |
49 | CPPFLAGS+= -D"KBUILD_STR(s)=\#s" #-Q | 49 | CPPFLAGS += -D"KBUILD_STR(s)=\#s" #-Q |
50 | 50 | ||
51 | # We need some generic definitions | 51 | # We need some generic definitions |
52 | include $(srctree)/scripts/Kbuild.include | 52 | include $(srctree)/scripts/Kbuild.include |
@@ -180,7 +180,7 @@ busybox_unstripped.o: $(usage_stuff) include/applet_tables.h include/autoconf.h | |||
180 | busybox: busybox_unstripped.o | 180 | busybox: 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 | |||
251 | quiet_cmd_link_o_target = LD $@ | 251 | quiet_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 |
253 | cmd_link_o_target = $(if $(strip $(obj-y)),\ | 253 | cmd_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) |