Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 1 | # |
| 2 | # linux/arch/x86/boot/compressed/Makefile |
| 3 | # |
| 4 | # create a compressed vmlinux image from the original vmlinux |
| 5 | # |
Kees Cook | fb7183e | 2014-10-31 09:22:04 -0700 | [diff] [blame] | 6 | # 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 Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 18 | |
Josh Poimboeuf | c0dd671686 | 2016-02-28 22:22:34 -0600 | [diff] [blame] | 19 | KASAN_SANITIZE := n |
| 20 | OBJECT_FILES_NON_STANDARD := y |
Andrey Ryabinin | ef7f0d6 | 2015-02-13 14:39:25 -0800 | [diff] [blame] | 21 | |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 22 | # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. |
| 23 | KCOV_INSTRUMENT := n |
| 24 | |
Kyungsik Lee | f9b493a | 2013-07-08 16:01:48 -0700 | [diff] [blame] | 25 | targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ |
| 26 | vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 27 | |
Paul Bolle | 846221c | 2016-11-03 09:53:50 +0100 | [diff] [blame] | 28 | KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ -O2 |
H.J. Lu | 6d92bc9 | 2016-03-16 20:04:35 -0700 | [diff] [blame] | 29 | KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC) |
H. Peter Anvin | 95a38f3 | 2009-04-01 17:35:00 -0700 | [diff] [blame] | 30 | KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING |
H. Peter Anvin | 17a2a9b | 2009-12-25 15:40:38 -0800 | [diff] [blame] | 31 | cflags-$(CONFIG_X86_32) := -march=i386 |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 32 | cflags-$(CONFIG_X86_64) := -mcmodel=small |
| 33 | KBUILD_CFLAGS += $(cflags-y) |
H. Peter Anvin | 8b3b005 | 2013-12-09 15:43:38 -0800 | [diff] [blame] | 34 | KBUILD_CFLAGS += -mno-mmx -mno-sse |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 35 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) |
| 36 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) |
| 37 | |
| 38 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ |
Peter Oberparleiter | 7bf99fb | 2009-06-17 16:28:09 -0700 | [diff] [blame] | 39 | GCOV_PROFILE := n |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 40 | UBSAN_SANITIZE :=n |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 41 | |
| 42 | LDFLAGS := -m elf_$(UTS_MACHINE) |
H.J. Lu | a980ce3 | 2016-11-18 13:07:19 -0800 | [diff] [blame] | 43 | # Compressed kernel should be built as PIE since it may be loaded at any |
| 44 | # address by the bootloader. |
H.J. Lu | 6d92bc9 | 2016-03-16 20:04:35 -0700 | [diff] [blame] | 45 | ifeq ($(CONFIG_X86_32),y) |
| 46 | LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) |
| 47 | else |
| 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. |
| 51 | LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ |
| 52 | && echo "-z noreloc-overflow -pie --no-dynamic-linker") |
| 53 | endif |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 54 | LDFLAGS_vmlinux := -T |
| 55 | |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 56 | hostprogs-y := mkpiggy |
Matt Fleming | 12871c5 | 2012-02-28 13:37:22 +0000 | [diff] [blame] | 57 | HOST_EXTRACFLAGS += -I$(srctree)/tools/include |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 58 | |
Yinghai Lu | 4abf061 | 2016-04-28 17:09:08 -0700 | [diff] [blame] | 59 | sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' |
Yinghai Lu | 67b6662 | 2016-04-28 17:09:06 -0700 | [diff] [blame] | 60 | |
| 61 | quiet_cmd_voffset = VOFFSET $@ |
| 62 | cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@ |
| 63 | |
| 64 | targets += ../voffset.h |
| 65 | |
| 66 | $(obj)/../voffset.h: vmlinux FORCE |
| 67 | $(call if_changed,voffset) |
| 68 | |
| 69 | $(obj)/misc.o: $(obj)/../voffset.h |
| 70 | |
Josh Triplett | 9a1cb47 | 2014-03-10 13:03:10 -0700 | [diff] [blame] | 71 | vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ |
Kees Cook | dc425a6 | 2016-05-02 15:51:00 -0700 | [diff] [blame] | 72 | $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \ |
Josh Triplett | 9e6abd2 | 2014-03-10 13:11:26 -0700 | [diff] [blame] | 73 | $(obj)/piggy.o $(obj)/cpuflags.o |
| 74 | |
Josh Triplett | 3afed06 | 2014-03-10 13:26:10 -0700 | [diff] [blame] | 75 | vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o |
Kees Cook | 9b23874 | 2016-04-18 09:42:10 -0700 | [diff] [blame] | 76 | vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o |
Kees Cook | 3a94707 | 2016-05-06 15:01:35 -0700 | [diff] [blame] | 77 | ifdef CONFIG_X86_64 |
| 78 | vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o |
| 79 | endif |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 80 | |
Matthew Garrett | 9dead5b | 2012-07-26 18:00:00 -0400 | [diff] [blame] | 81 | $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone |
Matthew Garrett | 9dead5b | 2012-07-26 18:00:00 -0400 | [diff] [blame] | 82 | |
Ard Biesheuvel | 243b675 | 2014-11-05 17:00:56 +0100 | [diff] [blame] | 83 | vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \ |
| 84 | $(objtree)/drivers/firmware/efi/libstub/lib.a |
Matt Fleming | 96738c6 | 2015-01-13 15:25:00 +0000 | [diff] [blame] | 85 | vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 86 | |
Kees Cook | 98f7852 | 2016-05-25 15:45:30 -0700 | [diff] [blame] | 87 | # 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. |
| 94 | quiet_cmd_check_data_rel = DATAREL $@ |
| 95 | define 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 |
| 102 | endef |
| 103 | |
Josh Triplett | 9a1cb47 | 2014-03-10 13:03:10 -0700 | [diff] [blame] | 104 | $(obj)/vmlinux: $(vmlinux-objs-y) FORCE |
Kees Cook | 98f7852 | 2016-05-25 15:45:30 -0700 | [diff] [blame] | 105 | $(call if_changed,check_data_rel) |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 106 | $(call if_changed,ld) |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 107 | |
Ian Campbell | 099e137 | 2008-02-13 20:54:58 +0000 | [diff] [blame] | 108 | OBJCOPYFLAGS_vmlinux.bin := -R .comment -S |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 109 | $(obj)/vmlinux.bin: vmlinux FORCE |
| 110 | $(call if_changed,objcopy) |
| 111 | |
Josh Triplett | 9a1cb47 | 2014-03-10 13:03:10 -0700 | [diff] [blame] | 112 | targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 113 | |
H. Peter Anvin | 6520fe5 | 2012-05-08 21:22:24 +0300 | [diff] [blame] | 114 | CMD_RELOCS = arch/x86/tools/relocs |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 115 | quiet_cmd_relocs = RELOCS $@ |
H. Peter Anvin | 6520fe5 | 2012-05-08 21:22:24 +0300 | [diff] [blame] | 116 | cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< |
| 117 | $(obj)/vmlinux.relocs: vmlinux FORCE |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 118 | $(call if_changed,relocs) |
| 119 | |
| 120 | vmlinux.bin.all-y := $(obj)/vmlinux.bin |
H. Peter Anvin | 5f11e02 | 2009-05-05 22:53:11 -0700 | [diff] [blame] | 121 | vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 122 | |
H. Peter Anvin | 5f11e02 | 2009-05-05 22:53:11 -0700 | [diff] [blame] | 123 | $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 124 | $(call if_changed,gzip) |
H. Peter Anvin | 5f11e02 | 2009-05-05 22:53:11 -0700 | [diff] [blame] | 125 | $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE |
Alain Knaff | ae03c49 | 2009-01-04 22:46:17 +0100 | [diff] [blame] | 126 | $(call if_changed,bzip2) |
H. Peter Anvin | 5f11e02 | 2009-05-05 22:53:11 -0700 | [diff] [blame] | 127 | $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE |
Alain Knaff | ae03c49 | 2009-01-04 22:46:17 +0100 | [diff] [blame] | 128 | $(call if_changed,lzma) |
Lasse Collin | 3031480 | 2011-01-12 17:01:24 -0800 | [diff] [blame] | 129 | $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE |
| 130 | $(call if_changed,xzkern) |
Albin Tonnerre | 1351099 | 2010-01-08 14:42:45 -0800 | [diff] [blame] | 131 | $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE |
| 132 | $(call if_changed,lzo) |
Kyungsik Lee | f9b493a | 2013-07-08 16:01:48 -0700 | [diff] [blame] | 133 | $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE |
| 134 | $(call if_changed,lz4) |
Sam Ravnborg | db569af | 2008-01-30 13:32:30 +0100 | [diff] [blame] | 135 | |
H. Peter Anvin | 283ab1c | 2009-05-08 15:32:47 -0700 | [diff] [blame] | 136 | suffix-$(CONFIG_KERNEL_GZIP) := gz |
| 137 | suffix-$(CONFIG_KERNEL_BZIP2) := bz2 |
| 138 | suffix-$(CONFIG_KERNEL_LZMA) := lzma |
Lasse Collin | 3031480 | 2011-01-12 17:01:24 -0800 | [diff] [blame] | 139 | suffix-$(CONFIG_KERNEL_XZ) := xz |
Albin Tonnerre | 1351099 | 2010-01-08 14:42:45 -0800 | [diff] [blame] | 140 | suffix-$(CONFIG_KERNEL_LZO) := lzo |
Kyungsik Lee | f9b493a | 2013-07-08 16:01:48 -0700 | [diff] [blame] | 141 | suffix-$(CONFIG_KERNEL_LZ4) := lz4 |
Alain Knaff | ae03c49 | 2009-01-04 22:46:17 +0100 | [diff] [blame] | 142 | |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 143 | quiet_cmd_mkpiggy = MKPIGGY $@ |
Yinghai Lu | 4d2d542 | 2016-04-28 17:09:07 -0700 | [diff] [blame] | 144 | cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false ) |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 145 | |
| 146 | targets += piggy.S |
| 147 | $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE |
| 148 | $(call if_changed,mkpiggy) |