Allow link-time optimization of Xen
RFC PATCH 1/1 Allow link-time optimization of Xen
This patch series applies on top of the clang/llvm one I just posted. It rearranges the Xen makefiles so that Xen can be built using bitcode intermediate files and link-time optimization. Since gold can't link binary and bitcode files together to produce a bitcode file, we need to gather binary objects and bitcode objects separately until the final link.
The first patch does that and is a candidate for checking in, although maybe not immediately. The second is just a hack to work around a bug in the LLVM linker, and is just here for anyone who wants to try it out.
PATCH 1/1 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.
# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299497649 0
# Node ID 9da74925d21627d886dc4d97028149f81bbc50b2
# Parent d91e6a8d36ad3dbf89f42264334baec0cb37063f
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.
config/StdGNU.mk +10 -2
@@ -1,10 +1,11 @@ AS = $(CROSS_COMPILE)as +LD = $(CROSS_COMPILE)ld ifeq ($(clang),y) -LD = $(CROSS_COMPILE)gold CC = $(CROSS_COMPILE)clang +LD_LTO = $(CROSS_COMPILE)llvm-ld else -LD = $(CROSS_COMPILE)ld CC = $(CROSS_COMPILE)gcc +LD_LTO = $(CROSS_COMPILE)ld endif CPP = $(CC) -E AR = $(CROSS_COMPILE)ar
@@ -79,3 +80,10 @@ ifneq ($(clang),y) CFLAGS += -fno-optimize-sibling-calls endif endif + +ifeq ($(lto),y) +CFLAGS += -flto +ifeq ($(clang),y) +LDFLAGS += -plugin LLVMgold.so +endif +endif
xen/Makefile +1 -1
@@ -159,4 +159,4 @@ FORCE: $(MAKE) -f $(BASEDIR)/Rules.mk -C $(*D) $(@F) %/: FORCE - $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o + $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o built_in_bin.o
xen/Rules.mk +36 -3
@@ -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)
xen/arch/x86/Makefile +21 -7
@@ -10,8 +10,8 @@ subdir-$(x86_64) += x86_64 obj-y += apic.o obj-y += bitops.o -obj-y += clear_page.o -obj-y += copy_page.o +obj-bin-y += clear_page.o +obj-bin-y += copy_page.o obj-y += compat.o obj-y += debug.o obj-y += delay.o
@@ -65,24 +65,38 @@ x86_emulate.o: x86_emulate/x86_emulate.c ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` + ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(ALL_OBJS) -$(TARGET)-syms: $(ALL_OBJS) xen.lds +ifeq ($(lto),y) +# Gather all LTO objects together +prelink_lto.o: $(ALL_OBJS) + $(LD_LTO) -r -o $@ $^ + +# Link it with all the binary objects +prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o + $(LD) $(LDFLAGS) -r -o $@ $^ +else +prelink.o: $(ALL_OBJS) + $(LD) $(LDFLAGS) -r -o $@ $^ +endif + +$(TARGET)-syms: prelink.o xen.lds $(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/common/symbols-dummy.o - $(LD) $(LDFLAGS) -T xen.lds -N $(ALL_OBJS) \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0 $(NM) -n $(@D)/.$(@F).0 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).0.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o - $(LD) $(LDFLAGS) -T xen.lds -N $(ALL_OBJS) \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1 $(NM) -n $(@D)/.$(@F).1 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).1.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o - $(LD) $(LDFLAGS) -T xen.lds -N $(ALL_OBJS) \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ $(@D)/.$(@F).1.o -o $@ rm -f $(@D)/.$(@F).[0-9]* asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c - $(CC) $(CFLAGS) -S -o $@ $< + $(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $< xen.lds: xen.lds.S $(CC) -P -E -Ui386 $(AFLAGS) -o $@ $<
xen/arch/x86/acpi/Makefile +2 -2
@@ -1,4 +1,4 @@ subdir-y += cpufreq -obj-y += boot.o -obj-y += power.o suspend.o wakeup_prot.o cpu_idle.o cpuidle_menu.o +obj-y += boot.o power.o suspend.o cpu_idle.o cpuidle_menu.o +obj-bin-y += wakeup_prot.o
xen/arch/x86/boot/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-y += head.o +obj-bin-y += head.o head.o: reloc.S
xen/arch/x86/boot/build32.mk +1 -0
@@ -6,6 +6,7 @@ include $(XEN_ROOT)/Config.mk $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) CFLAGS += -Werror -fno-builtin -msoft-float +CFLAGS := $(filter-out -flto,$(CFLAGS)) # NB. awk invocation is a portable alternative to 'head -n -1' %.S: %.bin
xen/arch/x86/hvm/svm/Makefile +1 -1
@@ -1,6 +1,6 @@ obj-y += asid.o obj-y += emulate.o -obj-y += entry.o +obj-bin-y += entry.o obj-y += intr.o obj-y += svm.o obj-y += vmcb.o
xen/arch/x86/hvm/vmx/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-y += entry.o +obj-bin-y += entry.o obj-y += intr.o obj-y += realmode.o obj-y += vmcs.o
xen/arch/x86/x86_32/Makefile +3 -3
@@ -1,6 +1,6 @@ obj-y += domain_page.o -obj-y += entry.o -obj-y += gpr_switch.o +obj-bin-y += entry.o +obj-bin-y += gpr_switch.o obj-y += mm.o obj-y += seg_fixup.o obj-y += traps.o
@@ -9,4 +9,4 @@ obj-y += pci.o obj-$(crash_debug) += gdbstub.o -obj-$(supervisor_mode_kernel) += supervisor_mode_kernel.o +obj-bin-$(supervisor_mode_kernel) += supervisor_mode_kernel.o
xen/arch/x86/x86_64/Makefile +3 -3
@@ -1,7 +1,7 @@ subdir-y += compat -obj-y += entry.o -obj-y += gpr_switch.o +obj-bin-y += entry.o +obj-bin-y += gpr_switch.o obj-y += mm.o obj-y += traps.o obj-y += machine_kexec.o
@@ -11,7 +11,7 @@ obj-y += mmconf-fam10h.o obj-y += mmconfig_64.o obj-y += mmconfig-shared.o obj-y += compat.o -obj-y += compat_kexec.o +obj-bin-y += compat_kexec.o obj-y += domain.o obj-y += physdev.o obj-y += platform_hypercall.o
xen/arch/x86/x86_64/compat/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-y += entry.o +obj-bin-y += entry.o
xen/common/libelf/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-y := libelf.o +obj-bin-y := libelf.o SECTIONS := text data rodata $(foreach n,1 2 4 8,rodata.str1.$(n)) $(foreach r,rel rel.ro,data.$(r) data.$(r).local)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 LLVM's linker currently can't handle two C files with the same name
In reply to Tim Deeganhttp://llvm.org/bugs/show_bug.cgi?id=8759
Work around that by renaming a lot of files (using symlinks).
This patch is definitely not to be considered for checking in to xen-unstable; it's just a hack to work around LLVM until it's fixed.
# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299497650 0
# Node ID 04aa04a5cfef5906fc988db4baf3255259fc4646
# Parent 9da74925d21627d886dc4d97028149f81bbc50b2
LLVM's linker currently can't handle two C files with the same name.
http://llvm.org/bugs/show_bug.cgi?id=8759
Work around that by renaming a lot of files (using symlinks).
This patch is definitely not to be considered for checking in to xen-unstable; it's just a hack to work around LLVM until it's fixed.
xen/arch/x86/Makefile +21 -14
@@ -12,12 +12,12 @@ obj-y += apic.o obj-y += bitops.o obj-bin-y += clear_page.o obj-bin-y += copy_page.o -obj-y += compat.o +obj-y += arch.compat.o obj-y += debug.o obj-y += delay.o obj-y += dmi_scan.o -obj-y += domctl.o -obj-y += domain.o +obj-y += arch.domctl.o +obj-y += arch.domain.o obj-y += domain_build.o obj-y += e820.o obj-y += extable.o
@@ -28,30 +28,30 @@ obj-y += i8259.o obj-y += io_apic.o obj-y += msi.o obj-y += ioport_emulate.o -obj-y += irq.o +obj-y += arch.irq.o obj-y += microcode.o obj-y += microcode_amd.o obj-y += microcode_intel.o obj-y += mm.o obj-y += mpparse.o obj-y += nmi.o -obj-y += numa.o -obj-y += pci.o +obj-y += arch.numa.o +obj-y += arch.pci.o obj-y += percpu.o -obj-y += physdev.o +obj-y += arch.physdev.o obj-y += setup.o -obj-y += shutdown.o +obj-y += arch.shutdown.o obj-y += smp.o obj-y += smpboot.o obj-y += srat.o -obj-y += string.o -obj-y += sysctl.o -obj-y += time.o -obj-y += trace.o -obj-y += traps.o +obj-y += arch.string.o +obj-y += arch.sysctl.o +obj-y += arch.time.o +obj-y += arch.trace.o +obj-y += arch.traps.o obj-y += usercopy.o obj-y += x86_emulate.o -obj-y += machine_kexec.o +obj-y += arch.machine_kexec.o obj-y += crash.o obj-y += tboot.o obj-y += hpet.o
@@ -106,6 +106,13 @@ xen.lds: xen.lds.S boot/mkelf32: boot/mkelf32.c $(HOSTCC) $(HOSTCFLAGS) -o $@ $< + +arch.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) arch.*.c + .PHONY: clean clean:: rm -f asm-offsets.s xen.lds boot/*.o boot/*~ boot/core boot/mkelf32
xen/arch/x86/acpi/cpufreq/Makefile +8 -1
@@ -1,2 +1,9 @@ -obj-y += cpufreq.o +obj-y += a.cpufreq.o obj-y += powernow.o + + +a.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) a.*.c
xen/arch/x86/cpu/Makefile +8 -1
@@ -2,10 +2,17 @@ subdir-y += mcheck subdir-y += mtrr obj-y += amd.o -obj-y += common.o +obj-y += cpu.common.o obj-y += intel.o obj-y += intel_cacheinfo.o obj-$(x86_32) += centaur.o obj-$(x86_32) += cyrix.o obj-$(x86_32) += transmeta.o + + +cpu.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) cpu.*.c
xen/arch/x86/hvm/Makefile +11 -4
@@ -3,17 +3,17 @@ subdir-y += vmx obj-y += asid.o obj-y += emulate.o -obj-y += hpet.o +obj-y += hvm.hpet.o obj-y += hvm.o obj-y += i8254.o obj-y += intercept.o obj-y += io.o -obj-y += irq.o +obj-y += hvm.irq.o obj-y += mtrr.o obj-y += pmtimer.o obj-y += quirks.o obj-y += rtc.o -obj-y += save.o +obj-y += hvm.save.o obj-y += stdvga.o obj-y += vioapic.o obj-y += viridian.o
@@ -21,4 +21,11 @@ obj-y += vlapic.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o -obj-y += vpmu.o +obj-y += vpmu.o + + +hvm.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) hvm.*.c
xen/arch/x86/hvm/svm/Makefile +10 -4
@@ -1,7 +1,13 @@ -obj-y += asid.o -obj-y += emulate.o +obj-y += svm.asid.o +obj-y += svm.emulate.o obj-bin-y += entry.o -obj-y += intr.o +obj-y += svm.intr.o obj-y += svm.o obj-y += vmcb.o -obj-y += vpmu.o +obj-y += svm.vpmu.o + +svm.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) svm.*.c
xen/arch/x86/hvm/vmx/Makefile +6 -0
@@ -4,3 +4,9 @@ obj-y += realmode.o obj-y += vmcs.o obj-y += vmx.o obj-y += vpmu_core2.o + +intr_vmx.c: intr.c + ln -sf $< $@ + +clean:: + $(RM) intr_vmx.c
xen/arch/x86/mm/Makefile +7 -1
@@ -11,5 +11,11 @@ obj-$(x86_64) += mem_paging.o obj-$(x86_64) += mem_sharing.o obj-$(x86_64) += mem_access.o -guest_walk_%.o: guest_walk.c Makefile +guest_walk_%.o: guest_walk_%.c $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@ + +guest_walk_%.c: guest_walk.c Makefile + ln -sf $< $@ + +clean:: + $(RM) guest_walk_*.c
xen/arch/x86/mm/hap/Makefile +7 -1
@@ -7,5 +7,11 @@ obj-y += p2m-ept.o guest_levels = $(subst level,,$(filter %level,$(subst ., ,$(subst _, ,$(1))))) guest_walk_defns = -DGUEST_PAGING_LEVELS=$(call guest_levels,$(1)) -guest_walk_%level.o: guest_walk.c Makefile +guest_walk_%level.o: guest_walk_%level.c $(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c $< -o $@ + +guest_walk_%level.c: guest_walk.c Makefile + ln -sf $< $@ + +clean:: + $(RM) guest_walk_*.c
xen/arch/x86/mm/shadow/Makefile +7 -1
@@ -1,5 +1,11 @@ obj-$(x86_32) += common.o guest_2.o guest_3.o obj-$(x86_64) += common.o guest_2.o guest_3.o guest_4.o -guest_%.o: multi.c Makefile +guest_%.o: guest_%.c $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@ + +guest_%.c: multi.c Makefile + ln -sf $< $@ + +clean:: + $(RM) guest_*.c
xen/arch/x86/oprofile/Makefile +7 -1
@@ -1,6 +1,12 @@ -obj-y += xenoprof.o +obj-y += x64.xenoprof.o obj-y += nmi_int.o obj-y += op_model_p4.o obj-y += op_model_ppro.o obj-y += op_model_athlon.o obj-y += backtrace.o + +x64.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) x64.*.c
xen/arch/x86/x86_64/Makefile +16 -10
@@ -2,20 +2,26 @@ subdir-y += compat obj-bin-y += entry.o obj-bin-y += gpr_switch.o -obj-y += mm.o -obj-y += traps.o -obj-y += machine_kexec.o -obj-y += pci.o +obj-y += x64.mm.o +obj-y += x64.traps.o +obj-y += x64.machine_kexec.o +obj-y += x64.pci.o obj-y += acpi_mmcfg.o obj-y += mmconf-fam10h.o obj-y += mmconfig_64.o obj-y += mmconfig-shared.o -obj-y += compat.o +obj-y += x64.compat.o obj-bin-y += compat_kexec.o -obj-y += domain.o -obj-y += physdev.o -obj-y += platform_hypercall.o -obj-y += cpu_idle.o -obj-y += cpufreq.o +obj-y += x64.domain.o +obj-y += x64.physdev.o +obj-y += x64.platform_hypercall.o +obj-y += x64.cpu_idle.o +obj-y += x64.cpufreq.o obj-$(crash_debug) += gdbstub.o + +x64.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) x64.*.c
xen/common/compat/Makefile +11 -5
@@ -1,6 +1,12 @@ -obj-y += domain.o -obj-y += kernel.o -obj-y += memory.o -obj-y += multicall.o +obj-y += c.domain.o +obj-y += c.kernel.o +obj-y += c.memory.o +obj-y += c.multicall.o obj-y += xlat.o -obj-y += tmem_xen.o +obj-y += c.tmem_xen.o + +c.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) c.*.c
xen/drivers/passthrough/Makefile +9 -3
@@ -2,6 +2,12 @@ subdir-$(x86) += vtd subdir-$(ia64) += vtd subdir-$(x86) += amd -obj-y += iommu.o -obj-y += io.o -obj-y += pci.o +obj-y += pass.iommu.o +obj-y += pass.io.o +obj-y += pass.pci.o + +pass.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) pass.*.c
xen/drivers/passthrough/vtd/Makefile +10 -3
@@ -1,9 +1,16 @@ subdir-$(x86) += x86 subdir-$(ia64) += ia64 -obj-y += iommu.o +obj-y += vtd.iommu.o obj-y += dmar.o -obj-y += utils.o +obj-y += vtd.utils.o obj-y += qinval.o obj-y += intremap.o -obj-y += quirks.o +obj-y += vtd.quirks.o + +vtd.%.c: %.c + ln -sf $< $@ + +clean:: + $(RM) vtd.*.c +
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel