Makefile.vmlinux_o 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. PHONY := __default
  3. __default: vmlinux.o
  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 delay-objtool (IBT or LTO), objtool doesn't run on individual translation
  25. # units. Instead it runs on vmlinux.o.
  26. #
  27. # For !delay-objtool + CONFIG_NOINSTR_VALIDATION, it runs on both translation
  28. # units and vmlinux.o, with the latter only used for noinstr/unret validation.
  29. objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
  30. ifeq ($(delay-objtool),y)
  31. vmlinux-objtool-args-y += $(objtool-args-y)
  32. else
  33. vmlinux-objtool-args-$(CONFIG_OBJTOOL_WERROR) += --werror
  34. endif
  35. vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \
  36. $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_SRSO)), --unret)
  37. objtool-args = $(vmlinux-objtool-args-y) --link
  38. # Link of vmlinux.o used for section mismatch analysis
  39. # ---------------------------------------------------------------------------
  40. vmlinux-o-ld-args-$(CONFIG_BUILTIN_MODULE_RANGES) += -Map=$@.map
  41. quiet_cmd_ld_vmlinux.o = LD $@
  42. cmd_ld_vmlinux.o = \
  43. $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
  44. $(vmlinux-o-ld-args-y) \
  45. $(addprefix -T , $(initcalls-lds)) \
  46. --whole-archive vmlinux.a --no-whole-archive \
  47. --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
  48. $(cmd_objtool)
  49. cmd_check_function_names = $(srctree)/scripts/check-function-names.sh $@
  50. define rule_ld_vmlinux.o
  51. $(call cmd_and_savecmd,ld_vmlinux.o)
  52. $(call cmd,gen_objtooldep)
  53. $(call cmd,check_function_names)
  54. endef
  55. vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
  56. $(call if_changed_rule,ld_vmlinux.o)
  57. targets += vmlinux.o
  58. # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
  59. # ---------------------------------------------------------------------------
  60. PHONY += FORCE
  61. FORCE:
  62. # Read all saved command lines and dependencies for the $(targets) we
  63. # may be building above, using $(if_changed{,_dep}). As an
  64. # optimization, we don't need to read them if the target does not
  65. # exist, we will rebuild anyway in that case.
  66. existing-targets := $(wildcard $(sort $(targets)))
  67. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  68. .PHONY: $(PHONY)