Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: Create intermediate vmlinux build with relocations preserved

The imperative paradigm used to build vmlinux, extract some info from it
or perform some checks on it, and subsequently modify it again goes
against the declarative paradigm that is usually employed for defining
make rules.

In particular, the Makefile.postlink files that consume their input via
an output rule result in some dodgy logic in the decompressor makefiles
for RISC-V and x86, given that the vmlinux.relocs input file needed to
generate the arch-specific relocation tables may not exist or be out of
date, but cannot be constructed using the ordinary Make dependency based
rules, because the info needs to be extracted while vmlinux is in its
ephemeral, non-stripped form.

So instead, for architectures that require the static relocations that
are emitted into vmlinux when passing --emit-relocs to the linker, and
are subsequently stripped out again, introduce an intermediate vmlinux
target called vmlinux.unstripped, and organize the reset of the build
logic accordingly:

- vmlinux.unstripped is created only once, and not updated again
- build rules under arch/*/boot can depend on vmlinux.unstripped without
running the risk of the data disappearing or being out of date
- the final vmlinux generated by the build is not bloated with static
relocations that are never needed again after the build completes.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Ard Biesheuvel and committed by
Masahiro Yamada
ac4f0678 9b400d17

+30 -34
+1
.gitignore
··· 65 65 /vmlinux.32 66 66 /vmlinux.map 67 67 /vmlinux.symvers 68 + /vmlinux.unstripped 68 69 /vmlinux-gdb.py 69 70 /vmlinuz 70 71 /System.map
+1 -1
Makefile
··· 1569 1569 # Directories & files removed with 'make clean' 1570 1570 CLEAN_FILES += vmlinux.symvers modules-only.symvers \ 1571 1571 modules.builtin modules.builtin.modinfo modules.nsdeps \ 1572 - modules.builtin.ranges vmlinux.o.map \ 1572 + modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ 1573 1573 compile_commands.json rust/test \ 1574 1574 rust-project.json .vmlinux.objs .vmlinux.export.c \ 1575 1575 .builtin-dtbs-list .builtin-dtb.S
+1 -4
arch/riscv/boot/Makefile
··· 32 32 endif 33 33 34 34 ifdef CONFIG_RELOCATABLE 35 - vmlinux.relocs: vmlinux 36 - @ (! [ -f vmlinux.relocs ] && echo "vmlinux.relocs can't be found, please remove vmlinux and try again") || true 37 - 38 - $(obj)/Image: vmlinux.relocs FORCE 35 + $(obj)/Image: vmlinux.unstripped FORCE 39 36 else 40 37 $(obj)/Image: vmlinux FORCE 41 38 endif
-3
scripts/Makefile.lib
··· 371 371 quiet_cmd_objcopy = OBJCOPY $@ 372 372 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 373 373 374 - quiet_cmd_strip_relocs = RSTRIP $@ 375 - cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@ 376 - 377 374 # Gzip 378 375 # --------------------------------------------------------------------------- 379 376
+21 -7
scripts/Makefile.vmlinux
··· 9 9 10 10 targets := 11 11 12 + ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS 13 + vmlinux-final := vmlinux.unstripped 14 + 15 + quiet_cmd_strip_relocs = RSTRIP $@ 16 + cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $< $@ 17 + 18 + vmlinux: $(vmlinux-final) FORCE 19 + $(call if_changed,strip_relocs) 20 + 21 + targets += vmlinux 22 + else 23 + vmlinux-final := vmlinux 24 + endif 25 + 12 26 %.o: %.c FORCE 13 27 $(call if_changed_rule,cc_o_c) 14 28 ··· 61 47 62 48 ifdef CONFIG_GENERIC_BUILTIN_DTB 63 49 targets += .builtin-dtbs.S .builtin-dtbs.o 64 - vmlinux: .builtin-dtbs.o 50 + $(vmlinux-final): .builtin-dtbs.o 65 51 endif 66 52 67 53 # vmlinux ··· 69 55 70 56 ifdef CONFIG_MODULES 71 57 targets += .vmlinux.export.o 72 - vmlinux: .vmlinux.export.o 58 + $(vmlinux-final): .vmlinux.export.o 73 59 endif 74 60 75 61 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX 76 - vmlinux: arch/$(SRCARCH)/tools/vmlinux.arch.o 62 + $(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o 77 63 78 64 arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE 79 65 $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ ··· 86 72 $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ 87 73 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 88 74 89 - targets += vmlinux 90 - vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE 75 + targets += $(vmlinux-final) 76 + $(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE 91 77 +$(call if_changed_dep,link_vmlinux) 92 78 ifdef CONFIG_DEBUG_INFO_BTF 93 - vmlinux: $(RESOLVE_BTFIDS) 79 + $(vmlinux-final): $(RESOLVE_BTFIDS) 94 80 endif 95 81 96 82 ifdef CONFIG_BUILDTIME_TABLE_SORT ··· 110 96 modules.builtin vmlinux.map vmlinux.o.map FORCE 111 97 $(call if_changed,modules_builtin_ranges) 112 98 113 - vmlinux.map: vmlinux 99 + vmlinux.map: $(vmlinux-final) 114 100 @: 115 101 116 102 endif