Makefile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. # Sanitizer runtimes are unavailable and cannot be linked for early boot code.
  20. KASAN_SANITIZE := n
  21. KCSAN_SANITIZE := n
  22. KMSAN_SANITIZE := n
  23. OBJECT_FILES_NON_STANDARD := y
  24. # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
  25. KCOV_INSTRUMENT := n
  26. targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
  27. vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
  28. # CLANG_FLAGS must come before any cc-disable-warning or cc-option calls in
  29. # case of cross compiling, as it has the '--target=' flag, which is needed to
  30. # avoid errors with '-march=i386', and future flags may depend on the target to
  31. # be valid.
  32. KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
  33. KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
  34. KBUILD_CFLAGS += -Wundef
  35. KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
  36. cflags-$(CONFIG_X86_32) := -march=i386
  37. cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
  38. KBUILD_CFLAGS += $(cflags-y)
  39. KBUILD_CFLAGS += -mno-mmx -mno-sse
  40. KBUILD_CFLAGS += -ffreestanding -fshort-wchar
  41. KBUILD_CFLAGS += -fno-stack-protector
  42. KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
  43. KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
  44. KBUILD_CFLAGS += -Wno-pointer-sign
  45. KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
  46. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  47. KBUILD_CFLAGS += -D__DISABLE_EXPORTS
  48. # Disable relocation relaxation in case the link is not PIE.
  49. KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no)
  50. KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
  51. # sev.c indirectly inludes inat-table.h which is generated during
  52. # compilation and stored in $(objtree). Add the directory to the includes so
  53. # that the compiler finds it even with out-of-tree builds (make O=/some/path).
  54. CFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
  55. KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
  56. GCOV_PROFILE := n
  57. UBSAN_SANITIZE :=n
  58. KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
  59. KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
  60. # Compressed kernel should be built as PIE since it may be loaded at any
  61. # address by the bootloader.
  62. LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
  63. ifdef CONFIG_LD_ORPHAN_WARN
  64. LDFLAGS_vmlinux += --orphan-handling=warn
  65. endif
  66. LDFLAGS_vmlinux += -z noexecstack
  67. ifeq ($(CONFIG_LD_IS_BFD),y)
  68. LDFLAGS_vmlinux += $(call ld-option,--no-warn-rwx-segments)
  69. endif
  70. LDFLAGS_vmlinux += -T
  71. hostprogs := mkpiggy
  72. HOST_EXTRACFLAGS += -I$(srctree)/tools/include
  73. sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
  74. quiet_cmd_voffset = VOFFSET $@
  75. cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
  76. targets += ../voffset.h
  77. $(obj)/../voffset.h: vmlinux FORCE
  78. $(call if_changed,voffset)
  79. $(obj)/misc.o: $(obj)/../voffset.h
  80. vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \
  81. $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
  82. $(obj)/piggy.o $(obj)/cpuflags.o
  83. vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
  84. vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
  85. ifdef CONFIG_X86_64
  86. vmlinux-objs-y += $(obj)/ident_map_64.o
  87. vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
  88. vmlinux-objs-y += $(obj)/mem_encrypt.o
  89. vmlinux-objs-y += $(obj)/pgtable_64.o
  90. vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
  91. endif
  92. vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
  93. vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o
  94. vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
  95. vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
  96. efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
  97. $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
  98. $(call if_changed,ld)
  99. OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
  100. $(obj)/vmlinux.bin: vmlinux FORCE
  101. $(call if_changed,objcopy)
  102. targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
  103. CMD_RELOCS = arch/x86/tools/relocs
  104. quiet_cmd_relocs = RELOCS $@
  105. cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
  106. $(obj)/vmlinux.relocs: vmlinux FORCE
  107. $(call if_changed,relocs)
  108. vmlinux.bin.all-y := $(obj)/vmlinux.bin
  109. vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
  110. $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
  111. $(call if_changed,gzip)
  112. $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
  113. $(call if_changed,bzip2_with_size)
  114. $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
  115. $(call if_changed,lzma_with_size)
  116. $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
  117. $(call if_changed,xzkern_with_size)
  118. $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
  119. $(call if_changed,lzo_with_size)
  120. $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
  121. $(call if_changed,lz4_with_size)
  122. $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
  123. $(call if_changed,zstd22_with_size)
  124. suffix-$(CONFIG_KERNEL_GZIP) := gz
  125. suffix-$(CONFIG_KERNEL_BZIP2) := bz2
  126. suffix-$(CONFIG_KERNEL_LZMA) := lzma
  127. suffix-$(CONFIG_KERNEL_XZ) := xz
  128. suffix-$(CONFIG_KERNEL_LZO) := lzo
  129. suffix-$(CONFIG_KERNEL_LZ4) := lz4
  130. suffix-$(CONFIG_KERNEL_ZSTD) := zst
  131. quiet_cmd_mkpiggy = MKPIGGY $@
  132. cmd_mkpiggy = $(obj)/mkpiggy $< > $@
  133. targets += piggy.S
  134. $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
  135. $(call if_changed,mkpiggy)