Makefile.modpost 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # SPDX-License-Identifier: GPL-2.0
  2. # ===========================================================================
  3. # Module versions
  4. # ===========================================================================
  5. #
  6. # Stage one of module building created the following:
  7. # a) The individual .o files used for the module
  8. # b) A <module>.o file which is the .o files above linked together
  9. # c) A <module>.mod file, listing the name of the preliminary <module>.o file,
  10. # plus all .o files
  11. # d) modules.order, which lists all the modules
  12. # Stage 2 is handled by this file and does the following
  13. # 1) Find all modules listed in modules.order
  14. # 2) modpost is then used to
  15. # 3) create one <module>.mod.c file per module
  16. # 4) create one Module.symvers file with CRC for all exported symbols
  17. # Step 3 is used to place certain information in the module's ELF
  18. # section, including information such as:
  19. # Version magic (see include/linux/vermagic.h for full details)
  20. # - Kernel release
  21. # - SMP is CONFIG_SMP
  22. # - PREEMPT is CONFIG_PREEMPT[_RT]
  23. # - GCC Version
  24. # Module info
  25. # - Module version (MODULE_VERSION)
  26. # - Module alias'es (MODULE_ALIAS)
  27. # - Module license (MODULE_LICENSE)
  28. # - See include/linux/module.h for more details
  29. # Step 4 is solely used to allow module versioning in external modules,
  30. # where the CRC of each module is retrieved from the Module.symvers file.
  31. PHONY := __modpost
  32. __modpost:
  33. include $(objtree)/include/config/auto.conf
  34. include $(srctree)/scripts/Kbuild.include
  35. MODPOST = $(objtree)/scripts/mod/modpost
  36. modpost-args = \
  37. $(if $(CONFIG_MODULES),-M) \
  38. $(if $(CONFIG_MODVERSIONS),-m) \
  39. $(if $(CONFIG_BASIC_MODVERSIONS),-b) \
  40. $(if $(CONFIG_EXTENDED_MODVERSIONS),-x) \
  41. $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
  42. $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
  43. $(if $(KBUILD_MODPOST_WARN),-w) \
  44. $(if $(KBUILD_NSDEPS),-d modules.nsdeps) \
  45. $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
  46. $(if $(findstring 1, $(KBUILD_EXTRA_WARN)),-W) \
  47. -o $@
  48. modpost-deps := $(MODPOST)
  49. # 'make -i -k' ignores compile errors, and builds as many modules as possible.
  50. ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
  51. modpost-args += -n
  52. endif
  53. # Read out modules.order to pass in modpost.
  54. # Otherwise, allmodconfig would fail with "Argument list too long".
  55. ifdef KBUILD_MODULES
  56. modpost-args += -T modules.order
  57. modpost-deps += modules.order
  58. endif
  59. ifeq ($(KBUILD_EXTMOD),)
  60. # Generate the list of in-tree objects in vmlinux
  61. # ---------------------------------------------------------------------------
  62. # This is used to retrieve symbol versions generated by genksyms.
  63. ifdef CONFIG_MODVERSIONS
  64. vmlinux.symvers Module.symvers: .vmlinux.objs
  65. endif
  66. # Ignore libgcc.a
  67. # Some architectures do '$(CC) --print-libgcc-file-name' to borrow libgcc.a
  68. # from the toolchain, but there is no EXPORT_SYMBOL in it.
  69. quiet_cmd_vmlinux_objs = GEN $@
  70. cmd_vmlinux_objs = \
  71. for f in $(real-prereqs); do \
  72. case $${f} in \
  73. *libgcc.a) ;; \
  74. *) $(AR) t $${f} ;; \
  75. esac \
  76. done > $@
  77. targets += .vmlinux.objs
  78. .vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
  79. $(call if_changed,vmlinux_objs)
  80. ifdef CONFIG_TRIM_UNUSED_KSYMS
  81. ksym-wl := $(CONFIG_UNUSED_KSYMS_WHITELIST)
  82. ksym-wl := $(if $(filter-out /%, $(ksym-wl)),$(if $(wildcard $(ksym-wl)),,$(srctree)/))$(ksym-wl)
  83. modpost-args += -t $(addprefix -u , $(ksym-wl))
  84. modpost-deps += $(ksym-wl)
  85. endif
  86. ifeq ($(wildcard vmlinux.o),)
  87. missing-input := vmlinux.o
  88. output-symdump := modules-only.symvers
  89. else
  90. modpost-args += vmlinux.o
  91. modpost-deps += vmlinux.o
  92. output-symdump := $(if $(KBUILD_MODULES), Module.symvers, vmlinux.symvers)
  93. endif
  94. else
  95. # set src + obj - they may be used in the modules's Makefile
  96. obj := .
  97. src := $(srcroot)
  98. # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
  99. include $(kbuild-file)
  100. output-symdump := Module.symvers
  101. ifeq ($(wildcard $(objtree)/Module.symvers),)
  102. missing-input := $(objtree)/Module.symvers
  103. else
  104. modpost-args += -i $(objtree)/Module.symvers
  105. modpost-deps += $(objtree)/Module.symvers
  106. endif
  107. modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS))
  108. endif # ($(KBUILD_EXTMOD),)
  109. quiet_cmd_modpost = MODPOST $@
  110. cmd_modpost = \
  111. $(if $(missing-input), \
  112. echo >&2 "WARNING: $(missing-input) is missing."; \
  113. echo >&2 " Modules may not have dependencies or modversions."; \
  114. echo >&2 " You may get many unresolved symbol errors."; \
  115. echo >&2 " You can set KBUILD_MODPOST_WARN=1 to turn errors into warning"; \
  116. echo >&2 " if you want to proceed at your own risk.";) \
  117. $(MODPOST) $(modpost-args)
  118. targets += $(output-symdump)
  119. $(output-symdump): $(modpost-deps) FORCE
  120. $(call if_changed,modpost)
  121. __modpost: $(output-symdump)
  122. PHONY += FORCE
  123. FORCE:
  124. existing-targets := $(wildcard $(sort $(targets)))
  125. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  126. .PHONY: $(PHONY)