blob: 44163e8c3868ec4dda58fed54f38411134224089 [file] [log] [blame]
Sam Ravnborgdb569af2008-01-30 13:32:30 +01001#
2# linux/arch/x86/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
Kees Cookfb7183e2014-10-31 09:22:04 -07006# vmlinuz is:
7# decompression code (*.o)
8# asm globals (piggy.S), including:
9# vmlinux.bin.(gz|bz2|lzma|...)
10#
11# vmlinux.bin is:
12# vmlinux stripped of debugging and comments
13# vmlinux.bin.all is:
14# vmlinux.bin + vmlinux.relocs
15# vmlinux.bin.(gz|bz2|lzma|...) is:
16# (see scripts/Makefile.lib size_append)
17# compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
Sam Ravnborgdb569af2008-01-30 13:32:30 +010018
Josh Poimboeufc0dd6716862016-02-28 22:22:34 -060019KASAN_SANITIZE := n
20OBJECT_FILES_NON_STANDARD := y
Andrey Ryabininef7f0d62015-02-13 14:39:25 -080021
Dmitry Vyukov5c9a8752016-03-22 14:27:30 -070022# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
23KCOV_INSTRUMENT := n
24
Kyungsik Leef9b493a2013-07-08 16:01:48 -070025targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
26 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
Sam Ravnborgdb569af2008-01-30 13:32:30 +010027
Paul Bolle846221c2016-11-03 09:53:50 +010028KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ -O2
H.J. Lu6d92bc92016-03-16 20:04:35 -070029KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC)
H. Peter Anvin95a38f32009-04-01 17:35:00 -070030KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
H. Peter Anvin17a2a9b2009-12-25 15:40:38 -080031cflags-$(CONFIG_X86_32) := -march=i386
Sam Ravnborgdb569af2008-01-30 13:32:30 +010032cflags-$(CONFIG_X86_64) := -mcmodel=small
33KBUILD_CFLAGS += $(cflags-y)
H. Peter Anvin8b3b0052013-12-09 15:43:38 -080034KBUILD_CFLAGS += -mno-mmx -mno-sse
Sam Ravnborgdb569af2008-01-30 13:32:30 +010035KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
36KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
37
38KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
Peter Oberparleiter7bf99fb2009-06-17 16:28:09 -070039GCOV_PROFILE := n
Andrey Ryabininc6d30852016-01-20 15:00:55 -080040UBSAN_SANITIZE :=n
Sam Ravnborgdb569af2008-01-30 13:32:30 +010041
42LDFLAGS := -m elf_$(UTS_MACHINE)
H.J. Lua980ce32016-11-18 13:07:19 -080043# Compressed kernel should be built as PIE since it may be loaded at any
44# address by the bootloader.
H.J. Lu6d92bc92016-03-16 20:04:35 -070045ifeq ($(CONFIG_X86_32),y)
46LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
47else
48# To build 64-bit compressed kernel as PIE, we disable relocation
49# overflow check to avoid relocation overflow error with a new linker
50# command-line option, -z noreloc-overflow.
51LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
52 && echo "-z noreloc-overflow -pie --no-dynamic-linker")
53endif
Sam Ravnborgdb569af2008-01-30 13:32:30 +010054LDFLAGS_vmlinux := -T
55
H. Peter Anvin02a884c2009-05-08 17:42:16 -070056hostprogs-y := mkpiggy
Matt Fleming12871c52012-02-28 13:37:22 +000057HOST_EXTRACFLAGS += -I$(srctree)/tools/include
H. Peter Anvin02a884c2009-05-08 17:42:16 -070058
Yinghai Lu4abf0612016-04-28 17:09:08 -070059sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
Yinghai Lu67b66622016-04-28 17:09:06 -070060
61quiet_cmd_voffset = VOFFSET $@
62 cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
63
64targets += ../voffset.h
65
66$(obj)/../voffset.h: vmlinux FORCE
67 $(call if_changed,voffset)
68
69$(obj)/misc.o: $(obj)/../voffset.h
70
Josh Triplett9a1cb472014-03-10 13:03:10 -070071vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
Kees Cookdc425a62016-05-02 15:51:00 -070072 $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
Josh Triplett9e6abd22014-03-10 13:11:26 -070073 $(obj)/piggy.o $(obj)/cpuflags.o
74
Josh Triplett3afed062014-03-10 13:26:10 -070075vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
Kees Cook9b238742016-04-18 09:42:10 -070076vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
Kees Cook3a947072016-05-06 15:01:35 -070077ifdef CONFIG_X86_64
78 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o
79endif
Matt Fleming291f3632011-12-12 21:27:52 +000080
Matthew Garrett9dead5b2012-07-26 18:00:00 -040081$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
Matthew Garrett9dead5b2012-07-26 18:00:00 -040082
Ard Biesheuvel243b6752014-11-05 17:00:56 +010083vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
84 $(objtree)/drivers/firmware/efi/libstub/lib.a
Matt Fleming96738c62015-01-13 15:25:00 +000085vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
Matt Fleming291f3632011-12-12 21:27:52 +000086
Kees Cook98f78522016-05-25 15:45:30 -070087# The compressed kernel is built with -fPIC/-fPIE so that a boot loader
88# can place it anywhere in memory and it will still run. However, since
89# it is executed as-is without any ELF relocation processing performed
90# (and has already had all relocation sections stripped from the binary),
91# none of the code can use data relocations (e.g. static assignments of
92# pointer values), since they will be meaningless at runtime. This check
93# will refuse to link the vmlinux if any of these relocations are found.
94quiet_cmd_check_data_rel = DATAREL $@
95define cmd_check_data_rel
96 for obj in $(filter %.o,$^); do \
97 readelf -S $$obj | grep -qF .rel.local && { \
98 echo "error: $$obj has data relocations!" >&2; \
99 exit 1; \
100 } || true; \
101 done
102endef
103
Josh Triplett9a1cb472014-03-10 13:03:10 -0700104$(obj)/vmlinux: $(vmlinux-objs-y) FORCE
Kees Cook98f78522016-05-25 15:45:30 -0700105 $(call if_changed,check_data_rel)
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100106 $(call if_changed,ld)
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100107
Ian Campbell099e1372008-02-13 20:54:58 +0000108OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100109$(obj)/vmlinux.bin: vmlinux FORCE
110 $(call if_changed,objcopy)
111
Josh Triplett9a1cb472014-03-10 13:03:10 -0700112targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100113
H. Peter Anvin6520fe52012-05-08 21:22:24 +0300114CMD_RELOCS = arch/x86/tools/relocs
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100115quiet_cmd_relocs = RELOCS $@
H. Peter Anvin6520fe52012-05-08 21:22:24 +0300116 cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
117$(obj)/vmlinux.relocs: vmlinux FORCE
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100118 $(call if_changed,relocs)
119
120vmlinux.bin.all-y := $(obj)/vmlinux.bin
H. Peter Anvin5f11e022009-05-05 22:53:11 -0700121vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100122
H. Peter Anvin5f11e022009-05-05 22:53:11 -0700123$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100124 $(call if_changed,gzip)
H. Peter Anvin5f11e022009-05-05 22:53:11 -0700125$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
Alain Knaffae03c492009-01-04 22:46:17 +0100126 $(call if_changed,bzip2)
H. Peter Anvin5f11e022009-05-05 22:53:11 -0700127$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
Alain Knaffae03c492009-01-04 22:46:17 +0100128 $(call if_changed,lzma)
Lasse Collin30314802011-01-12 17:01:24 -0800129$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
130 $(call if_changed,xzkern)
Albin Tonnerre13510992010-01-08 14:42:45 -0800131$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
132 $(call if_changed,lzo)
Kyungsik Leef9b493a2013-07-08 16:01:48 -0700133$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
134 $(call if_changed,lz4)
Sam Ravnborgdb569af2008-01-30 13:32:30 +0100135
H. Peter Anvin283ab1c2009-05-08 15:32:47 -0700136suffix-$(CONFIG_KERNEL_GZIP) := gz
137suffix-$(CONFIG_KERNEL_BZIP2) := bz2
138suffix-$(CONFIG_KERNEL_LZMA) := lzma
Lasse Collin30314802011-01-12 17:01:24 -0800139suffix-$(CONFIG_KERNEL_XZ) := xz
Albin Tonnerre13510992010-01-08 14:42:45 -0800140suffix-$(CONFIG_KERNEL_LZO) := lzo
Kyungsik Leef9b493a2013-07-08 16:01:48 -0700141suffix-$(CONFIG_KERNEL_LZ4) := lz4
Alain Knaffae03c492009-01-04 22:46:17 +0100142
H. Peter Anvin02a884c2009-05-08 17:42:16 -0700143quiet_cmd_mkpiggy = MKPIGGY $@
Yinghai Lu4d2d5422016-04-28 17:09:07 -0700144 cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
H. Peter Anvin02a884c2009-05-08 17:42:16 -0700145
146targets += piggy.S
147$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
148 $(call if_changed,mkpiggy)