Makefile.vmlinux_o 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 $(if $(CONFIG_CPU_UNRET_ENTRY), --unret)
  30. objtool-args = $(vmlinux-objtool-args-y) --link
  31. # Link of vmlinux.o used for section mismatch analysis
  32. # ---------------------------------------------------------------------------
  33. quiet_cmd_ld_vmlinux.o = LD $@
  34. cmd_ld_vmlinux.o = \
  35. $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
  36. $(addprefix -T , $(initcalls-lds)) \
  37. --whole-archive vmlinux.a --no-whole-archive \
  38. --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
  39. $(cmd_objtool)
  40. define rule_ld_vmlinux.o
  41. $(call cmd_and_savecmd,ld_vmlinux.o)
  42. $(call cmd,gen_objtooldep)
  43. endef
  44. vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
  45. $(call if_changed_rule,ld_vmlinux.o)
  46. targets += vmlinux.o
  47. # module.builtin.modinfo
  48. # ---------------------------------------------------------------------------
  49. OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
  50. targets += modules.builtin.modinfo
  51. modules.builtin.modinfo: vmlinux.o FORCE
  52. $(call if_changed,objcopy)
  53. # module.builtin
  54. # ---------------------------------------------------------------------------
  55. # The second line aids cases where multiple modules share the same object.
  56. quiet_cmd_modules_builtin = GEN $@
  57. cmd_modules_builtin = \
  58. tr '\0' '\n' < $< | \
  59. sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
  60. tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
  61. targets += modules.builtin
  62. modules.builtin: modules.builtin.modinfo FORCE
  63. $(call if_changed,modules_builtin)
  64. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
  65. # ---------------------------------------------------------------------------
  66. PHONY += FORCE
  67. FORCE:
  68. # Read all saved command lines and dependencies for the $(targets) we
  69. # may be building above, using $(if_changed{,_dep}). As an
  70. # optimization, we don't need to read them if the target does not
  71. # exist, we will rebuild anyway in that case.
  72. existing-targets := $(wildcard $(sort $(targets)))
  73. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  74. .PHONY: $(PHONY)