Makefile.vmlinux_o 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. PHONY := __default
  3. __default: vmlinux.o modules.builtin.modinfo modules.builtin
  4. include include/config/auto.conf
  5. include $(srctree)/scripts/Kbuild.include
  6. # for objtool
  7. include $(srctree)/scripts/Makefile.lib
  8. # Generate a linker script to ensure correct ordering of initcalls for Clang LTO
  9. # ---------------------------------------------------------------------------
  10. quiet_cmd_gen_initcalls_lds = GEN $@
  11. cmd_gen_initcalls_lds = \
  12. $(PYTHON3) $(srctree)/scripts/jobserver-exec \
  13. $(PERL) $(real-prereqs) > $@
  14. .tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
  15. vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
  16. $(call if_changed,gen_initcalls_lds)
  17. targets := .tmp_initcalls.lds
  18. ifdef CONFIG_LTO_CLANG
  19. initcalls-lds := .tmp_initcalls.lds
  20. endif
  21. # objtool for vmlinux.o
  22. # ---------------------------------------------------------------------------
  23. #
  24. # For LTO and IBT, objtool doesn't run on individual translation units.
  25. # Run everything on vmlinux instead.
  26. objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
  27. vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y)
  28. vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
  29. vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \
  30. $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_SRSO)), --unret)
  31. objtool-args = $(vmlinux-objtool-args-y) --link
  32. # Link of vmlinux.o used for section mismatch analysis
  33. # ---------------------------------------------------------------------------
  34. vmlinux-o-ld-args-$(CONFIG_BUILTIN_MODULE_RANGES) += -Map=$@.map
  35. quiet_cmd_ld_vmlinux.o = LD $@
  36. cmd_ld_vmlinux.o = \
  37. $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
  38. $(vmlinux-o-ld-args-y) \
  39. $(addprefix -T , $(initcalls-lds)) \
  40. --whole-archive vmlinux.a --no-whole-archive \
  41. --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
  42. $(cmd_objtool)
  43. define rule_ld_vmlinux.o
  44. $(call cmd_and_savecmd,ld_vmlinux.o)
  45. $(call cmd,gen_objtooldep)
  46. endef
  47. vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
  48. $(call if_changed_rule,ld_vmlinux.o)
  49. targets += vmlinux.o
  50. # module.builtin.modinfo
  51. # ---------------------------------------------------------------------------
  52. OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
  53. targets += modules.builtin.modinfo
  54. modules.builtin.modinfo: vmlinux.o FORCE
  55. $(call if_changed,objcopy)
  56. # module.builtin
  57. # ---------------------------------------------------------------------------
  58. # The second line aids cases where multiple modules share the same object.
  59. quiet_cmd_modules_builtin = GEN $@
  60. cmd_modules_builtin = \
  61. tr '\0' '\n' < $< | \
  62. sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
  63. tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
  64. targets += modules.builtin
  65. modules.builtin: modules.builtin.modinfo FORCE
  66. $(call if_changed,modules_builtin)
  67. # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
  68. # ---------------------------------------------------------------------------
  69. PHONY += FORCE
  70. FORCE:
  71. # Read all saved command lines and dependencies for the $(targets) we
  72. # may be building above, using $(if_changed{,_dep}). As an
  73. # optimization, we don't need to read them if the target does not
  74. # exist, we will rebuild anyway in that case.
  75. existing-targets := $(wildcard $(sort $(targets)))
  76. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  77. .PHONY: $(PHONY)