svn commit: trunk/busybox: scripts
vda at busybox.net
vda at busybox.net
Wed Jun 4 11:28:24 UTC 2008
Author: vda
Date: 2008-06-04 04:28:24 -0700 (Wed, 04 Jun 2008)
New Revision: 22211
Log:
build system: add PIE build option
Modified:
trunk/busybox/Config.in
trunk/busybox/Makefile
trunk/busybox/Makefile.flags
trunk/busybox/scripts/Makefile.IMA
trunk/busybox/scripts/Makefile.build
Changeset:
Modified: trunk/busybox/Config.in
===================================================================
--- trunk/busybox/Config.in 2008-06-04 10:33:33 UTC (rev 22210)
+++ trunk/busybox/Config.in 2008-06-04 11:28:24 UTC (rev 22211)
@@ -262,6 +262,14 @@
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
bool "Force NOMMU build"
default n
Modified: trunk/busybox/Makefile
===================================================================
--- trunk/busybox/Makefile 2008-06-04 10:33:33 UTC (rev 22210)
+++ trunk/busybox/Makefile 2008-06-04 11:28:24 UTC (rev 22211)
@@ -315,6 +315,8 @@
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
CFLAGS := $(CFLAGS)
+# Added only to final link stage of busybox binary
+CFLAGS_busybox := $(CFLAGS_busybox)
CPPFLAGS := $(CPPFLAGS)
AFLAGS := $(AFLAGS)
LDFLAGS := $(LDFLAGS)
@@ -580,7 +582,7 @@
cmd_busybox__ ?= $(srctree)/scripts/trylink \
"$@" \
"$(CC)" \
- "$(CFLAGS)" \
+ "$(CFLAGS) $(CFLAGS_busybox)" \
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
Modified: trunk/busybox/Makefile.flags
===================================================================
--- trunk/busybox/Makefile.flags 2008-06-04 10:33:33 UTC (rev 22210)
+++ trunk/busybox/Makefile.flags 2008-06-04 11:28:24 UTC (rev 22211)
@@ -50,19 +50,33 @@
CFLAGS += $(call cc-option,-g)
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)
# on i386: 14% smaller libbusybox.so
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
-CFLAGS += -fpic
+CFLAGS += $(ARCH_FPIC)
# and another 4% reduction of libbusybox.so:
# (external entry points must be marked EXTERNALLY_VISIBLE)
CFLAGS += $(call cc-option,-fvisibility=hidden)
endif
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
+
LDLIBS += m crypt
ifeq ($(CONFIG_PAM),y)
@@ -81,8 +95,6 @@
LDLIBS += dmalloc
endif
-#LDFLAGS += -nostdlib
-
LDFLAGS_ELF2FLT = -Wl,-elf2flt
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
SKIP_STRIP = y
Modified: trunk/busybox/scripts/Makefile.IMA
===================================================================
--- trunk/busybox/scripts/Makefile.IMA 2008-06-04 10:33:33 UTC (rev 22210)
+++ trunk/busybox/scripts/Makefile.IMA 2008-06-04 11:28:24 UTC (rev 22211)
@@ -45,8 +45,8 @@
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
-CFLAGS := $(CFLAGS)
-CPPFLAGS+= -D"KBUILD_STR(s)=\#s" #-Q
+CFLAGS := $(CFLAGS)
+CPPFLAGS += -D"KBUILD_STR(s)=\#s" #-Q
# We need some generic definitions
include $(srctree)/scripts/Kbuild.include
@@ -180,7 +180,7 @@
busybox: busybox_unstripped.o
$(srctree)/scripts/trylink \
busybox_unstripped \
- "$(CC)" \
+ "$(CC) $(CFLAGS_busybox)" \
"$(CFLAGS)" \
"$(LDFLAGS)" \
"busybox_unstripped.o" \
Modified: trunk/busybox/scripts/Makefile.build
===================================================================
--- trunk/busybox/scripts/Makefile.build 2008-06-04 10:33:33 UTC (rev 22210)
+++ trunk/busybox/scripts/Makefile.build 2008-06-04 11:28:24 UTC (rev 22211)
@@ -251,8 +251,8 @@
quiet_cmd_link_o_target = LD $@
# If the list of objects to link is empty, just create an empty built-in.o
cmd_link_o_target = $(if $(strip $(obj-y)),\
- $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
- rm -f $@; $(AR) rcs $@)
+ $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
+ rm -f $@; $(AR) rcs $@)
$(builtin-target): $(obj-y) FORCE
$(call if_changed,link_o_target)
More information about the busybox-cvs
mailing list