Makefile.modpost 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 include/config/auto.conf
  34. include $(srctree)/scripts/Kbuild.include
  35. MODPOST = scripts/mod/modpost
  36. modpost-args = \
  37. $(if $(CONFIG_MODULES),-M) \
  38. $(if $(CONFIG_MODVERSIONS),-m) \
  39. $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
  40. $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
  41. $(if $(KBUILD_MODPOST_WARN),-w) \
  42. $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
  43. $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
  44. $(if $(findstring 1, $(KBUILD_EXTRA_WARN)),-W) \
  45. -o $@
  46. modpost-deps := $(MODPOST)
  47. # 'make -i -k' ignores compile errors, and builds as many modules as possible.
  48. ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
  49. modpost-args += -n
  50. endif
  51. # Read out modules.order to pass in modpost.
  52. # Otherwise, allmodconfig would fail with "Argument list too long".
  53. ifdef KBUILD_MODULES
  54. modpost-args += -T $(MODORDER)
  55. modpost-deps += $(MODORDER)
  56. endif
  57. ifeq ($(KBUILD_EXTMOD),)
  58. # Generate the list of in-tree objects in vmlinux
  59. # ---------------------------------------------------------------------------
  60. # This is used to retrieve symbol versions generated by genksyms.
  61. ifdef CONFIG_MODVERSIONS
  62. vmlinux.symvers Module.symvers: .vmlinux.objs
  63. endif
  64. # Ignore libgcc.a
  65. # Some architectures do '$(CC) --print-libgcc-file-name' to borrow libgcc.a
  66. # from the toolchain, but there is no EXPORT_SYMBOL in it.
  67. quiet_cmd_vmlinux_objs = GEN $@
  68. cmd_vmlinux_objs = \
  69. for f in $(real-prereqs); do \
  70. case $${f} in \
  71. *libgcc.a) ;; \
  72. *) $(AR) t $${f} ;; \
  73. esac \
  74. done > $@
  75. targets += .vmlinux.objs
  76. .vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
  77. $(call if_changed,vmlinux_objs)
  78. ifdef CONFIG_TRIM_UNUSED_KSYMS
  79. ksym-wl := $(CONFIG_UNUSED_KSYMS_WHITELIST)
  80. ksym-wl := $(if $(filter-out /%, $(ksym-wl)),$(if $(wildcard $(ksym-wl)),,$(srctree)/))$(ksym-wl)
  81. modpost-args += -t $(addprefix -u , $(ksym-wl))
  82. modpost-deps += $(ksym-wl)
  83. endif
  84. ifeq ($(wildcard vmlinux.o),)
  85. missing-input := vmlinux.o
  86. output-symdump := modules-only.symvers
  87. else
  88. modpost-args += vmlinux.o
  89. modpost-deps += vmlinux.o
  90. output-symdump := $(if $(KBUILD_MODULES), Module.symvers, vmlinux.symvers)
  91. endif
  92. else
  93. # set src + obj - they may be used in the modules's Makefile
  94. obj := $(KBUILD_EXTMOD)
  95. src := $(if $(VPATH),$(VPATH)/)$(obj)
  96. # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
  97. include $(kbuild-file)
  98. output-symdump := $(KBUILD_EXTMOD)/Module.symvers
  99. ifeq ($(wildcard Module.symvers),)
  100. missing-input := Module.symvers
  101. else
  102. modpost-args += -i Module.symvers
  103. modpost-deps += Module.symvers
  104. endif
  105. modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS))
  106. endif # ($(KBUILD_EXTMOD),)
  107. quiet_cmd_modpost = MODPOST $@
  108. cmd_modpost = \
  109. $(if $(missing-input), \
  110. echo >&2 "WARNING: $(missing-input) is missing."; \
  111. echo >&2 " Modules may not have dependencies or modversions."; \
  112. echo >&2 " You may get many unresolved symbol errors."; \
  113. echo >&2 " You can set KBUILD_MODPOST_WARN=1 to turn errors into warning"; \
  114. echo >&2 " if you want to proceed at your own risk.";) \
  115. $(MODPOST) $(modpost-args)
  116. targets += $(output-symdump)
  117. $(output-symdump): $(modpost-deps) FORCE
  118. $(call if_changed,modpost)
  119. __modpost: $(output-symdump)
  120. PHONY += FORCE
  121. FORCE:
  122. existing-targets := $(wildcard $(sort $(targets)))
  123. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  124. .PHONY: $(PHONY)