Loading...
1#
2# linux/arch/x86/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
8 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
9
10KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
11KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
12KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
13cflags-$(CONFIG_X86_32) := -march=i386
14cflags-$(CONFIG_X86_64) := -mcmodel=small
15KBUILD_CFLAGS += $(cflags-y)
16KBUILD_CFLAGS += -mno-mmx -mno-sse
17KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
18KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
19
20KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
21GCOV_PROFILE := n
22
23LDFLAGS := -m elf_$(UTS_MACHINE)
24LDFLAGS_vmlinux := -T
25
26hostprogs-y := mkpiggy
27HOST_EXTRACFLAGS += -I$(srctree)/tools/include
28
29VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
30 $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
31 $(obj)/piggy.o $(obj)/cpuflags.o $(obj)/aslr.o
32
33$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
34
35ifeq ($(CONFIG_EFI_STUB), y)
36 VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
37endif
38
39$(obj)/vmlinux: $(VMLINUX_OBJS) FORCE
40 $(call if_changed,ld)
41 @:
42
43OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
44$(obj)/vmlinux.bin: vmlinux FORCE
45 $(call if_changed,objcopy)
46
47targets += $(patsubst $(obj)/%,%,$(VMLINUX_OBJS)) vmlinux.bin.all vmlinux.relocs
48
49CMD_RELOCS = arch/x86/tools/relocs
50quiet_cmd_relocs = RELOCS $@
51 cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
52$(obj)/vmlinux.relocs: vmlinux FORCE
53 $(call if_changed,relocs)
54
55vmlinux.bin.all-y := $(obj)/vmlinux.bin
56vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
57
58$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
59 $(call if_changed,gzip)
60$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
61 $(call if_changed,bzip2)
62$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
63 $(call if_changed,lzma)
64$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
65 $(call if_changed,xzkern)
66$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
67 $(call if_changed,lzo)
68$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
69 $(call if_changed,lz4)
70
71suffix-$(CONFIG_KERNEL_GZIP) := gz
72suffix-$(CONFIG_KERNEL_BZIP2) := bz2
73suffix-$(CONFIG_KERNEL_LZMA) := lzma
74suffix-$(CONFIG_KERNEL_XZ) := xz
75suffix-$(CONFIG_KERNEL_LZO) := lzo
76suffix-$(CONFIG_KERNEL_LZ4) := lz4
77
78quiet_cmd_mkpiggy = MKPIGGY $@
79 cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
80
81targets += piggy.S
82$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
83 $(call if_changed,mkpiggy)
1# SPDX-License-Identifier: GPL-2.0
2#
3# linux/arch/x86/boot/compressed/Makefile
4#
5# create a compressed vmlinux image from the original vmlinux
6#
7# vmlinuz is:
8# decompression code (*.o)
9# asm globals (piggy.S), including:
10# vmlinux.bin.(gz|bz2|lzma|...)
11#
12# vmlinux.bin is:
13# vmlinux stripped of debugging and comments
14# vmlinux.bin.all is:
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
19
20targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
21 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
22
23# CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
24# case of cross compiling, as it has the '--target=' flag, which is needed to
25# avoid errors with '-march=i386', and future flags may depend on the target to
26# be valid.
27KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
28KBUILD_CFLAGS += -std=gnu11
29KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
30KBUILD_CFLAGS += -Wundef
31KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
32cflags-$(CONFIG_X86_32) := -march=i386
33cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
34KBUILD_CFLAGS += $(cflags-y)
35KBUILD_CFLAGS += -mno-mmx -mno-sse
36KBUILD_CFLAGS += -ffreestanding -fshort-wchar
37KBUILD_CFLAGS += -fno-stack-protector
38KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
39KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
40KBUILD_CFLAGS += -Wno-pointer-sign
41KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
42KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
43KBUILD_CFLAGS += -D__DISABLE_EXPORTS
44# Disable relocation relaxation in case the link is not PIE.
45KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no)
46KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
47
48# sev.c indirectly includes inat-table.h which is generated during
49# compilation and stored in $(objtree). Add the directory to the includes so
50# that the compiler finds it even with out-of-tree builds (make O=/some/path).
51CFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
52
53KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
54
55KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
56KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
57# Compressed kernel should be built as PIE since it may be loaded at any
58# address by the bootloader.
59LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
60ifdef CONFIG_LD_ORPHAN_WARN
61LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
62endif
63LDFLAGS_vmlinux += -z noexecstack
64ifeq ($(CONFIG_LD_IS_BFD),y)
65LDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
66endif
67ifeq ($(CONFIG_EFI_STUB),y)
68# ensure that the static EFI stub library will be pulled in, even if it is
69# never referenced explicitly from the startup code
70LDFLAGS_vmlinux += -u efi_pe_entry
71endif
72LDFLAGS_vmlinux += -T
73
74hostprogs := mkpiggy
75HOST_EXTRACFLAGS += -I$(srctree)/tools/include
76
77sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__start_rodata\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
78
79quiet_cmd_voffset = VOFFSET $@
80 cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
81
82targets += ../voffset.h
83
84$(obj)/../voffset.h: vmlinux FORCE
85 $(call if_changed,voffset)
86
87$(obj)/misc.o: $(obj)/../voffset.h
88
89vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
90 $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
91 $(obj)/piggy.o $(obj)/cpuflags.o
92
93vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
94vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
95ifdef CONFIG_X86_64
96 vmlinux-objs-y += $(obj)/ident_map_64.o
97 vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
98 vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/mem_encrypt.o
99 vmlinux-objs-y += $(obj)/pgtable_64.o
100 vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
101endif
102
103vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
104vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o $(obj)/tdx-shared.o
105vmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/mem.o
106
107vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
108vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o
109vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
110
111$(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE
112 $(call if_changed,ld)
113
114OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
115$(obj)/vmlinux.bin: vmlinux FORCE
116 $(call if_changed,objcopy)
117
118targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
119
120# vmlinux.relocs is created by the vmlinux postlink step.
121$(obj)/vmlinux.relocs: vmlinux
122 @true
123
124vmlinux.bin.all-y := $(obj)/vmlinux.bin
125vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
126
127$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
128 $(call if_changed,gzip)
129$(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
130 $(call if_changed,bzip2_with_size)
131$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
132 $(call if_changed,lzma_with_size)
133$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
134 $(call if_changed,xzkern_with_size)
135$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
136 $(call if_changed,lzo_with_size)
137$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
138 $(call if_changed,lz4_with_size)
139$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
140 $(call if_changed,zstd22_with_size)
141
142suffix-$(CONFIG_KERNEL_GZIP) := gz
143suffix-$(CONFIG_KERNEL_BZIP2) := bz2
144suffix-$(CONFIG_KERNEL_LZMA) := lzma
145suffix-$(CONFIG_KERNEL_XZ) := xz
146suffix-$(CONFIG_KERNEL_LZO) := lzo
147suffix-$(CONFIG_KERNEL_LZ4) := lz4
148suffix-$(CONFIG_KERNEL_ZSTD) := zst
149
150quiet_cmd_mkpiggy = MKPIGGY $@
151 cmd_mkpiggy = $(obj)/mkpiggy $< > $@
152
153targets += piggy.S
154$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
155 $(call if_changed,mkpiggy)