aboutsummaryrefslogtreecommitdiffstats
path: root/xen/Rules.mk
diff options
context:
space:
mode:
authorTim Deegan <Tim.Deegan@citrix.com>2011-03-07 11:34:09 +0000
committerTim Deegan <Tim.Deegan@citrix.com>2011-03-07 11:34:09 +0000
commite4cdd74f02eaeea96348dc51534eff8e03d87697 (patch)
tree7e6947edf542bd1c6e87205fe7e7cec3d0388fa9 /xen/Rules.mk
parent436323c065f0ace4f469f5854f43423702a5082a (diff)
downloadxen-e4cdd74f02eaeea96348dc51534eff8e03d87697.tar.gz
xen-e4cdd74f02eaeea96348dc51534eff8e03d87697.tar.bz2
xen-e4cdd74f02eaeea96348dc51534eff8e03d87697.zip
xen: add "lto=y" option to build Xen with link-time optimizations.
This involves gathering object files from .asm (which will be binary) and object files from .c (which will be in LTO format) separately until the final link. Only tested for x86_64 Xen builds using Clang/LLVM bitcode; it should be possible to do the same with newer GCCs and GIMPLE. Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com> Acked-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/Rules.mk')
-rw-r--r--xen/Rules.mk39
1 files changed, 36 insertions, 3 deletions
diff --git a/xen/Rules.mk b/xen/Rules.mk
index 59d0dc7c31..9a9829bcb3 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -9,6 +9,8 @@ perfc_arrays ?= n
lock_profile ?= n
crash_debug ?= n
frame_pointer ?= n
+clang ?= n
+lto ?= n
XEN_ROOT=$(BASEDIR)/..
include $(XEN_ROOT)/Config.mk
@@ -75,7 +77,8 @@ CFLAGS += $(CFLAGS-y)
# Most CFLAGS are safe for assembly files:
# -std=gnu{89,99} gets confused by #-prefixed end-of-line comments
-AFLAGS += $(AFLAGS-y) $(filter-out -std=gnu%,$(CFLAGS))
+# -flto makes no sense and annoys clang
+AFLAGS += $(AFLAGS-y) $(filter-out -std=gnu%,$(filter-out -flto,$(CFLAGS)))
# LDFLAGS are only passed directly to $(LD)
LDFLAGS += $(LDFLAGS_DIRECT)
@@ -86,18 +89,45 @@ include Makefile
subdir-n := $(patsubst %,%/,$(patsubst %/,%,$(subdir-n) $(subdir-)))
subdir-y := $(patsubst %,%/,$(patsubst %/,%,$(subdir-y)))
-# Add explicitly declared subdirectories to the object list.
+# Add explicitly declared subdirectories to the object lists.
obj-y += $(patsubst %/,%/built_in.o,$(subdir-y))
-# Add implicitly declared subdirectories (in the object list) to the
+# Add implicitly declared subdirectories (in the object lists) to the
# subdirectory list, and rewrite the object-list entry.
subdir-y += $(filter %/,$(obj-y))
obj-y := $(patsubst %/,%/built-in.o,$(obj-y))
subdir-all := $(subdir-y) $(subdir-n)
+ifeq ($(lto),y)
+# Would like to handle all object files as bitcode, but objects made from
+# pure asm are in a different format and have to be collected separately.
+# Mirror the directory tree, collecting them as built_in_bin.o.
+# If there are no binary objects in a given directory, make a dummy .o
+obj-bin-y += $(patsubst %/built_in.o,%/built_in_bin.o,$(filter %/built_in.o,$(obj-y)))
+else
+# For a non-LTO build, bundle obj-bin targets in with the normal objs.
+obj-y += $(obj-bin-y)
+obj-bin-y :=
+endif
+
built_in.o: $(obj-y)
+ifeq ($(obj-y),)
+ $(CC) $(CFLAGS) -c -x c /dev/null -o $@
+else
+ifeq ($(lto),y)
+ $(LD_LTO) -r -o $@ $^
+else
+ $(LD) $(LDFLAGS) -r -o $@ $^
+endif
+endif
+
+built_in_bin.o: $(obj-bin-y)
+ifeq ($(obj-bin-y),)
+ $(CC) $(AFLAGS) -c -x assembler /dev/null -o $@
+else
$(LD) $(LDFLAGS) -r -o $@ $^
+endif
# Force execution of pattern rules (for which PHONY cannot be directly used).
.PHONY: FORCE
@@ -106,6 +136,9 @@ FORCE:
%/built_in.o: FORCE
$(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o
+%/built_in_bin.o: FORCE
+ $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in_bin.o
+
.PHONY: clean
clean:: $(addprefix _clean_, $(subdir-all))
rm -f *.o *~ core $(DEPS)