| 1 |
# SPDX-License-Identifier: GPL-2.0-only |
| 2 |
|
| 3 |
PHONY := __default |
| 4 |
__default: vmlinux |
| 5 |
|
| 6 |
include include/config/auto.conf |
| 7 |
include $(srctree)/scripts/Kbuild.include |
| 8 |
include $(srctree)/scripts/Makefile.lib |
| 9 |
|
| 10 |
targets := |
| 11 |
|
| 12 |
%.o: %.c FORCE |
| 13 |
$(call if_changed_rule,cc_o_c) |
| 14 |
|
| 15 |
%.o: %.S FORCE |
| 16 |
$(call if_changed_rule,as_o_S) |
| 17 |
|
| 18 |
# Built-in dtb |
| 19 |
# --------------------------------------------------------------------------- |
| 20 |
|
| 21 |
quiet_cmd_wrap_dtbs = WRAP $@ |
| 22 |
cmd_wrap_dtbs = { \ |
| 23 |
echo '\#include <asm-generic/vmlinux.lds.h>'; \ |
| 24 |
echo '.section .dtb.init.rodata,"a"'; \ |
| 25 |
while read dtb; do \ |
| 26 |
symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ |
| 27 |
echo '.balign STRUCT_ALIGNMENT'; \ |
| 28 |
echo ".global $${symbase}_begin"; \ |
| 29 |
echo "$${symbase}_begin:"; \ |
| 30 |
echo '.incbin "'$$dtb'" '; \ |
| 31 |
echo ".global $${symbase}_end"; \ |
| 32 |
echo "$${symbase}_end:"; \ |
| 33 |
done < $<; \ |
| 34 |
} > $@ |
| 35 |
|
| 36 |
.builtin-dtbs.S: .builtin-dtbs-list FORCE |
| 37 |
$(call if_changed,wrap_dtbs) |
| 38 |
|
| 39 |
quiet_cmd_gen_dtbs_list = GEN $@ |
| 40 |
cmd_gen_dtbs_list = \ |
| 41 |
$(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ |
| 42 |
|
| 43 |
.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE |
| 44 |
$(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) |
| 45 |
|
| 46 |
targets += .builtin-dtbs-list |
| 47 |
|
| 48 |
ifdef CONFIG_GENERIC_BUILTIN_DTB |
| 49 |
targets += .builtin-dtbs.S .builtin-dtbs.o |
| 50 |
vmlinux.unstripped: .builtin-dtbs.o |
| 51 |
endif |
| 52 |
|
| 53 |
# vmlinux.unstripped |
| 54 |
# --------------------------------------------------------------------------- |
| 55 |
|
| 56 |
ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX |
| 57 |
vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o |
| 58 |
|
| 59 |
arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE |
| 60 |
$(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ |
| 61 |
endif |
| 62 |
|
| 63 |
ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) |
| 64 |
|
| 65 |
# Final link of vmlinux with optional arch pass after final link |
| 66 |
cmd_link_vmlinux = \ |
| 67 |
$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ |
| 68 |
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) |
| 69 |
|
| 70 |
targets += vmlinux.unstripped .vmlinux.export.o |
| 71 |
vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE |
| 72 |
+$(call if_changed_dep,link_vmlinux) |
| 73 |
ifdef CONFIG_DEBUG_INFO_BTF |
| 74 |
vmlinux.unstripped: $(RESOLVE_BTFIDS) $(srctree)/scripts/gen-btf.sh |
| 75 |
endif |
| 76 |
|
| 77 |
ifdef CONFIG_BUILDTIME_TABLE_SORT |
| 78 |
vmlinux.unstripped: scripts/sorttable |
| 79 |
endif |
| 80 |
|
| 81 |
# vmlinux |
| 82 |
# --------------------------------------------------------------------------- |
| 83 |
|
| 84 |
remove-section-y := .modinfo |
| 85 |
remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' '!.rel*.dyn' |
| 86 |
# for compatibility with binutils < 2.32 |
| 87 |
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=c12d9fa2afe7abcbe407a00e15719e1a1350c2a7 |
| 88 |
remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel.*' |
| 89 |
|
| 90 |
remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*' |
| 91 |
|
| 92 |
# To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy, |
| 93 |
# it is necessary to remove the PT_LOAD flag from the segment. |
| 94 |
quiet_cmd_strip_relocs = OBJCOPY $@ |
| 95 |
cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \ |
| 96 |
$(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@ |
| 97 |
|
| 98 |
targets += vmlinux |
| 99 |
vmlinux: vmlinux.unstripped FORCE |
| 100 |
$(call if_changed,strip_relocs) |
| 101 |
|
| 102 |
# modules.builtin.modinfo |
| 103 |
# --------------------------------------------------------------------------- |
| 104 |
|
| 105 |
# .modinfo in vmlinux.unstripped is aligned to 8 bytes for compatibility with |
| 106 |
# tools that expect vmlinux to have sufficiently aligned sections but the |
| 107 |
# additional bytes used for padding .modinfo to satisfy this requirement break |
| 108 |
# certain versions of kmod with |
| 109 |
# |
| 110 |
# depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname prefix |
| 111 |
# |
| 112 |
# Strip the trailing padding bytes after extracting .modinfo to comply with |
| 113 |
# what kmod expects to parse. |
| 114 |
quiet_cmd_modules_builtin_modinfo = GEN $@ |
| 115 |
cmd_modules_builtin_modinfo = $(cmd_objcopy); \ |
| 116 |
sed -i 's/\x00\+$$/\x00/g' $@; \ |
| 117 |
chmod -x $@ |
| 118 |
|
| 119 |
OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary |
| 120 |
|
| 121 |
targets += modules.builtin.modinfo |
| 122 |
modules.builtin.modinfo: vmlinux.unstripped FORCE |
| 123 |
$(call if_changed,modules_builtin_modinfo) |
| 124 |
|
| 125 |
# modules.builtin |
| 126 |
# --------------------------------------------------------------------------- |
| 127 |
|
| 128 |
__default: modules.builtin |
| 129 |
|
| 130 |
# The second line aids cases where multiple modules share the same object. |
| 131 |
|
| 132 |
quiet_cmd_modules_builtin = GEN $@ |
| 133 |
cmd_modules_builtin = \ |
| 134 |
tr '\0' '\n' < $< | \ |
| 135 |
sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ |
| 136 |
tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ |
| 137 |
|
| 138 |
targets += modules.builtin |
| 139 |
modules.builtin: modules.builtin.modinfo FORCE |
| 140 |
$(call if_changed,modules_builtin) |
| 141 |
|
| 142 |
# modules.builtin.ranges |
| 143 |
# --------------------------------------------------------------------------- |
| 144 |
ifdef CONFIG_BUILTIN_MODULE_RANGES |
| 145 |
__default: modules.builtin.ranges |
| 146 |
|
| 147 |
quiet_cmd_modules_builtin_ranges = GEN $@ |
| 148 |
cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ |
| 149 |
|
| 150 |
targets += modules.builtin.ranges |
| 151 |
modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ |
| 152 |
modules.builtin vmlinux.map vmlinux.o.map FORCE |
| 153 |
$(call if_changed,modules_builtin_ranges) |
| 154 |
|
| 155 |
vmlinux.map: vmlinux.unstripped |
| 156 |
@: |
| 157 |
|
| 158 |
endif |
| 159 |
|
| 160 |
# Add FORCE to the prerequisites of a target to force it to be always rebuilt. |
| 161 |
# --------------------------------------------------------------------------- |
| 162 |
|
| 163 |
PHONY += FORCE |
| 164 |
FORCE: |
| 165 |
|
| 166 |
# Read all saved command lines and dependencies for the $(targets) we |
| 167 |
# may be building above, using $(if_changed{,_dep}). As an |
| 168 |
# optimization, we don't need to read them if the target does not |
| 169 |
# exist, we will rebuild anyway in that case. |
| 170 |
|
| 171 |
existing-targets := $(wildcard $(sort $(targets))) |
| 172 |
|
| 173 |
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
| 174 |
|
| 175 |
.PHONY: $(PHONY) |