1 # SPDX-License-Identifier: GPL-2.0
3 # linux/arch/x86/boot/compressed/Makefile
5 # create a compressed vmlinux image from the original vmlinux
8 # decompression code (*.o)
9 # asm globals (piggy.S), including:
10 # vmlinux.bin.(gz|bz2|lzma|...)
13 # vmlinux stripped of debugging and comments
15 # vmlinux.bin + vmlinux.relocs
16 # vmlinux.bin.(gz|bz2|lzma|...) is:
17 # (see scripts/Makefile.lib size_append)
18 # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
20 # Sanitizer runtimes are unavailable and cannot be linked for early boot code.
23 OBJECT_FILES_NON_STANDARD := y
25 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
28 targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
29 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
31 # CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
32 # case of cross compiling, as it has the '--target=' flag, which is needed to
33 # avoid errors with '-march=i386', and future flags may depend on the target to
35 KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
36 KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
37 KBUILD_CFLAGS += -Wundef
38 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
39 cflags-$(CONFIG_X86_32) := -march=i386
40 cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
41 KBUILD_CFLAGS += $(cflags-y)
42 KBUILD_CFLAGS += -mno-mmx -mno-sse
43 KBUILD_CFLAGS += -ffreestanding -fshort-wchar
44 KBUILD_CFLAGS += -fno-stack-protector
45 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
46 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
47 KBUILD_CFLAGS += -Wno-pointer-sign
48 KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
49 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
50 KBUILD_CFLAGS += -D__DISABLE_EXPORTS
51 # Disable relocation relaxation in case the link is not PIE.
52 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
53 KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
55 # sev.c indirectly inludes inat-table.h which is generated during
56 # compilation and stored in $(objtree). Add the directory to the includes so
57 # that the compiler finds it even with out-of-tree builds (make O=/some/path).
58 CFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
60 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
64 KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
65 KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
66 # Compressed kernel should be built as PIE since it may be loaded at any
67 # address by the bootloader.
68 LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
69 ifdef CONFIG_LD_ORPHAN_WARN
70 LDFLAGS_vmlinux += --orphan-handling=warn
72 LDFLAGS_vmlinux += -z noexecstack
73 ifeq ($(CONFIG_LD_IS_BFD),y)
74 LDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
79 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
81 sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
83 quiet_cmd_voffset = VOFFSET $@
84 cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
86 targets += ../voffset.h
88 $(obj)/../voffset.h: vmlinux FORCE
89 $(call if_changed,voffset)
91 $(obj)/misc.o: $(obj)/../voffset.h
93 vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
94 $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
95 $(obj)/piggy.o $(obj)/cpuflags.o
97 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
98 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
100 vmlinux-objs-y += $(obj)/ident_map_64.o
101 vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
102 vmlinux-objs-y += $(obj)/mem_encrypt.o
103 vmlinux-objs-y += $(obj)/pgtable_64.o
104 vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
107 vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
108 vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o
110 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
111 vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
112 efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
114 $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
115 $(call if_changed,ld)
117 OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
118 $(obj)/vmlinux.bin: vmlinux FORCE
119 $(call if_changed,objcopy)
121 targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
123 CMD_RELOCS = arch/x86/tools/relocs
124 quiet_cmd_relocs = RELOCS $@
125 cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
126 $(obj)/vmlinux.relocs: vmlinux FORCE
127 $(call if_changed,relocs)
129 vmlinux.bin.all-y := $(obj)/vmlinux.bin
130 vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
132 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
133 $(call if_changed,gzip)
134 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
135 $(call if_changed,bzip2_with_size)
136 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
137 $(call if_changed,lzma_with_size)
138 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
139 $(call if_changed,xzkern_with_size)
140 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
141 $(call if_changed,lzo_with_size)
142 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
143 $(call if_changed,lz4_with_size)
144 $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
145 $(call if_changed,zstd22_with_size)
147 suffix-$(CONFIG_KERNEL_GZIP) := gz
148 suffix-$(CONFIG_KERNEL_BZIP2) := bz2
149 suffix-$(CONFIG_KERNEL_LZMA) := lzma
150 suffix-$(CONFIG_KERNEL_XZ) := xz
151 suffix-$(CONFIG_KERNEL_LZO) := lzo
152 suffix-$(CONFIG_KERNEL_LZ4) := lz4
153 suffix-$(CONFIG_KERNEL_ZSTD) := zst
155 quiet_cmd_mkpiggy = MKPIGGY $@
156 cmd_mkpiggy = $(obj)/mkpiggy $< > $@
159 $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
160 $(call if_changed,mkpiggy)