1db569afaSSam Ravnborg# 2db569afaSSam Ravnborg# linux/arch/x86/boot/compressed/Makefile 3db569afaSSam Ravnborg# 4db569afaSSam Ravnborg# create a compressed vmlinux image from the original vmlinux 5db569afaSSam Ravnborg# 6fb7183efSKees Cook# vmlinuz is: 7fb7183efSKees Cook# decompression code (*.o) 8fb7183efSKees Cook# asm globals (piggy.S), including: 9fb7183efSKees Cook# vmlinux.bin.(gz|bz2|lzma|...) 10fb7183efSKees Cook# 11fb7183efSKees Cook# vmlinux.bin is: 12fb7183efSKees Cook# vmlinux stripped of debugging and comments 13fb7183efSKees Cook# vmlinux.bin.all is: 14fb7183efSKees Cook# vmlinux.bin + vmlinux.relocs 15fb7183efSKees Cook# vmlinux.bin.(gz|bz2|lzma|...) is: 16fb7183efSKees Cook# (see scripts/Makefile.lib size_append) 17fb7183efSKees Cook# compressed vmlinux.bin.all + u32 size of vmlinux.bin.all 18db569afaSSam Ravnborg 19ef7f0d6aSAndrey RyabininKASAN_SANITIZE := n 20c0dd6716SJosh PoimboeufOBJECT_FILES_NON_STANDARD := y 21ef7f0d6aSAndrey Ryabinin 225c9a8750SDmitry Vyukov# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. 235c9a8750SDmitry VyukovKCOV_INSTRUMENT := n 245c9a8750SDmitry Vyukov 25f9b493acSKyungsik Leetargets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ 26f9b493acSKyungsik Lee vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 27db569afaSSam Ravnborg 28db569afaSSam RavnborgKBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 296d92bc9dSH.J. LuKBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC) 3095a38f34SH. Peter AnvinKBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING 3117a2a9b5SH. Peter Anvincflags-$(CONFIG_X86_32) := -march=i386 32db569afaSSam Ravnborgcflags-$(CONFIG_X86_64) := -mcmodel=small 33db569afaSSam RavnborgKBUILD_CFLAGS += $(cflags-y) 348b3b005dSH. Peter AnvinKBUILD_CFLAGS += -mno-mmx -mno-sse 35db569afaSSam RavnborgKBUILD_CFLAGS += $(call cc-option,-ffreestanding) 36db569afaSSam RavnborgKBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 37db569afaSSam Ravnborg 38db569afaSSam RavnborgKBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 397bf99fb6SPeter OberparleiterGCOV_PROFILE := n 40c6d30853SAndrey RyabininUBSAN_SANITIZE :=n 41db569afaSSam Ravnborg 42db569afaSSam RavnborgLDFLAGS := -m elf_$(UTS_MACHINE) 436d92bc9dSH.J. Luifeq ($(CONFIG_RELOCATABLE),y) 446d92bc9dSH.J. Lu# If kernel is relocatable, build compressed kernel as PIE. 456d92bc9dSH.J. Luifeq ($(CONFIG_X86_32),y) 466d92bc9dSH.J. LuLDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) 476d92bc9dSH.J. Luelse 486d92bc9dSH.J. Lu# To build 64-bit compressed kernel as PIE, we disable relocation 496d92bc9dSH.J. Lu# overflow check to avoid relocation overflow error with a new linker 506d92bc9dSH.J. Lu# command-line option, -z noreloc-overflow. 516d92bc9dSH.J. LuLDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ 526d92bc9dSH.J. Lu && echo "-z noreloc-overflow -pie --no-dynamic-linker") 536d92bc9dSH.J. Luendif 546d92bc9dSH.J. Luendif 55db569afaSSam RavnborgLDFLAGS_vmlinux := -T 56db569afaSSam Ravnborg 5702a884c0SH. Peter Anvinhostprogs-y := mkpiggy 5812871c56SMatt FlemingHOST_EXTRACFLAGS += -I$(srctree)/tools/include 5902a884c0SH. Peter Anvin 609a1cb471SJosh Triplettvmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ 613afed06aSJosh Triplett $(obj)/string.o $(obj)/cmdline.o \ 629e6abd2aSJosh Triplett $(obj)/piggy.o $(obj)/cpuflags.o 639e6abd2aSJosh Triplett 643afed06aSJosh Triplettvmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o 659e6abd2aSJosh Triplettvmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o 66291f3632SMatt Fleming 679dead5bbSMatthew Garrett$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone 689dead5bbSMatthew Garrett 69243b6754SArd Biesheuvelvmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \ 70243b6754SArd Biesheuvel $(objtree)/drivers/firmware/efi/libstub/lib.a 7196738c69SMatt Flemingvmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o 72291f3632SMatt Fleming 739a1cb471SJosh Triplett$(obj)/vmlinux: $(vmlinux-objs-y) FORCE 74db569afaSSam Ravnborg $(call if_changed,ld) 75db569afaSSam Ravnborg @: 76db569afaSSam Ravnborg 77099e1377SIan CampbellOBJCOPYFLAGS_vmlinux.bin := -R .comment -S 78db569afaSSam Ravnborg$(obj)/vmlinux.bin: vmlinux FORCE 79db569afaSSam Ravnborg $(call if_changed,objcopy) 80db569afaSSam Ravnborg 819a1cb471SJosh Tripletttargets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs 82db569afaSSam Ravnborg 836520fe55SH. Peter AnvinCMD_RELOCS = arch/x86/tools/relocs 84db569afaSSam Ravnborgquiet_cmd_relocs = RELOCS $@ 856520fe55SH. Peter Anvin cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< 866520fe55SH. Peter Anvin$(obj)/vmlinux.relocs: vmlinux FORCE 87db569afaSSam Ravnborg $(call if_changed,relocs) 88db569afaSSam Ravnborg 89db569afaSSam Ravnborgvmlinux.bin.all-y := $(obj)/vmlinux.bin 905f11e020SH. Peter Anvinvmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs 91db569afaSSam Ravnborg 925f11e020SH. Peter Anvin$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 93db569afaSSam Ravnborg $(call if_changed,gzip) 945f11e020SH. Peter Anvin$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE 95ae03c499SAlain Knaff $(call if_changed,bzip2) 965f11e020SH. Peter Anvin$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 97ae03c499SAlain Knaff $(call if_changed,lzma) 9830314804SLasse Collin$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE 9930314804SLasse Collin $(call if_changed,xzkern) 10013510997SAlbin Tonnerre$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 10113510997SAlbin Tonnerre $(call if_changed,lzo) 102f9b493acSKyungsik Lee$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE 103f9b493acSKyungsik Lee $(call if_changed,lz4) 104db569afaSSam Ravnborg 105283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_GZIP) := gz 106283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_BZIP2) := bz2 107283ab1c0SH. Peter Anvinsuffix-$(CONFIG_KERNEL_LZMA) := lzma 10830314804SLasse Collinsuffix-$(CONFIG_KERNEL_XZ) := xz 10913510997SAlbin Tonnerresuffix-$(CONFIG_KERNEL_LZO) := lzo 110f9b493acSKyungsik Leesuffix-$(CONFIG_KERNEL_LZ4) := lz4 111ae03c499SAlain Knaff 112e2e68ae6SChris ClaytonRUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \ 113d69911a6SKees Cook $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh) 11402a884c0SH. Peter Anvinquiet_cmd_mkpiggy = MKPIGGY $@ 115e6023367SJunjie Mao cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false ) 11602a884c0SH. Peter Anvin 11702a884c0SH. Peter Anvintargets += piggy.S 11802a884c0SH. Peter Anvin$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE 11902a884c0SH. Peter Anvin $(call if_changed,mkpiggy) 120