Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 #
0003 # linux/arch/x86/boot/compressed/Makefile
0004 #
0005 # create a compressed vmlinux image from the original vmlinux
0006 #
0007 # vmlinuz is:
0008 #       decompression code (*.o)
0009 #       asm globals (piggy.S), including:
0010 #               vmlinux.bin.(gz|bz2|lzma|...)
0011 #
0012 # vmlinux.bin is:
0013 #       vmlinux stripped of debugging and comments
0014 # vmlinux.bin.all is:
0015 #       vmlinux.bin + vmlinux.relocs
0016 # vmlinux.bin.(gz|bz2|lzma|...) is:
0017 #       (see scripts/Makefile.lib size_append)
0018 #       compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
0019 
0020 # Sanitizer runtimes are unavailable and cannot be linked for early boot code.
0021 KASAN_SANITIZE                  := n
0022 KCSAN_SANITIZE                  := n
0023 OBJECT_FILES_NON_STANDARD       := y
0024 
0025 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
0026 KCOV_INSTRUMENT         := n
0027 
0028 targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
0029         vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
0030 
0031 # CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
0032 # case of cross compiling, as it has the '--target=' flag, which is needed to
0033 # avoid errors with '-march=i386', and future flags may depend on the target to
0034 # be valid.
0035 KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
0036 KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
0037 KBUILD_CFLAGS += -Wundef
0038 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
0039 cflags-$(CONFIG_X86_32) := -march=i386
0040 cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
0041 KBUILD_CFLAGS += $(cflags-y)
0042 KBUILD_CFLAGS += -mno-mmx -mno-sse
0043 KBUILD_CFLAGS += -ffreestanding -fshort-wchar
0044 KBUILD_CFLAGS += -fno-stack-protector
0045 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
0046 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
0047 KBUILD_CFLAGS += -Wno-pointer-sign
0048 KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
0049 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
0050 KBUILD_CFLAGS += -D__DISABLE_EXPORTS
0051 # Disable relocation relaxation in case the link is not PIE.
0052 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
0053 KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
0054 
0055 # sev.c indirectly inludes inat-table.h which is generated during
0056 # compilation and stored in $(objtree). Add the directory to the includes so
0057 # that the compiler finds it even with out-of-tree builds (make O=/some/path).
0058 CFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
0059 
0060 KBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
0061 GCOV_PROFILE := n
0062 UBSAN_SANITIZE :=n
0063 
0064 KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
0065 KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
0066 # Compressed kernel should be built as PIE since it may be loaded at any
0067 # address by the bootloader.
0068 LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
0069 ifdef CONFIG_LD_ORPHAN_WARN
0070 LDFLAGS_vmlinux += --orphan-handling=warn
0071 endif
0072 LDFLAGS_vmlinux += -z noexecstack
0073 ifeq ($(CONFIG_LD_IS_BFD),y)
0074 LDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
0075 endif
0076 LDFLAGS_vmlinux += -T
0077 
0078 hostprogs       := mkpiggy
0079 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
0080 
0081 sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
0082 
0083 quiet_cmd_voffset = VOFFSET $@
0084       cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
0085 
0086 targets += ../voffset.h
0087 
0088 $(obj)/../voffset.h: vmlinux FORCE
0089         $(call if_changed,voffset)
0090 
0091 $(obj)/misc.o: $(obj)/../voffset.h
0092 
0093 vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
0094         $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
0095         $(obj)/piggy.o $(obj)/cpuflags.o
0096 
0097 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
0098 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
0099 ifdef CONFIG_X86_64
0100         vmlinux-objs-y += $(obj)/ident_map_64.o
0101         vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
0102         vmlinux-objs-y += $(obj)/mem_encrypt.o
0103         vmlinux-objs-y += $(obj)/pgtable_64.o
0104         vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
0105 endif
0106 
0107 vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
0108 vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o
0109 
0110 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
0111 vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
0112 efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
0113 
0114 $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
0115         $(call if_changed,ld)
0116 
0117 OBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
0118 $(obj)/vmlinux.bin: vmlinux FORCE
0119         $(call if_changed,objcopy)
0120 
0121 targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
0122 
0123 CMD_RELOCS = arch/x86/tools/relocs
0124 quiet_cmd_relocs = RELOCS  $@
0125       cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
0126 $(obj)/vmlinux.relocs: vmlinux FORCE
0127         $(call if_changed,relocs)
0128 
0129 vmlinux.bin.all-y := $(obj)/vmlinux.bin
0130 vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
0131 
0132 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
0133         $(call if_changed,gzip)
0134 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
0135         $(call if_changed,bzip2_with_size)
0136 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
0137         $(call if_changed,lzma_with_size)
0138 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
0139         $(call if_changed,xzkern_with_size)
0140 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
0141         $(call if_changed,lzo_with_size)
0142 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
0143         $(call if_changed,lz4_with_size)
0144 $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
0145         $(call if_changed,zstd22_with_size)
0146 
0147 suffix-$(CONFIG_KERNEL_GZIP)    := gz
0148 suffix-$(CONFIG_KERNEL_BZIP2)   := bz2
0149 suffix-$(CONFIG_KERNEL_LZMA)    := lzma
0150 suffix-$(CONFIG_KERNEL_XZ)      := xz
0151 suffix-$(CONFIG_KERNEL_LZO)     := lzo
0152 suffix-$(CONFIG_KERNEL_LZ4)     := lz4
0153 suffix-$(CONFIG_KERNEL_ZSTD)    := zst
0154 
0155 quiet_cmd_mkpiggy = MKPIGGY $@
0156       cmd_mkpiggy = $(obj)/mkpiggy $< > $@
0157 
0158 targets += piggy.S
0159 $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
0160         $(call if_changed,mkpiggy)