Skip to content

Commit 1198c9c

Browse files
rnavmpe
authored andcommitted
kbuild: Add generic hook for architectures to use before the final vmlinux link
On powerpc, we would like to be able to make a pass on vmlinux.o and generate a new object file to be linked into vmlinux. Add a generic pass in Makefile.vmlinux that architectures can use for this purpose. Architectures need to select CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX and must provide arch/<arch>/tools/Makefile with .arch.vmlinux.o target, which will be invoked prior to the final vmlinux link step. Acked-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Naveen N Rao <naveen@kernel.org> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://patch.msgid.link/20241030070850.1361304-12-hbathini@linux.ibm.com
1 parent 782f46c commit 1198c9c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

arch/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,4 +1684,10 @@ config CC_HAS_SANE_FUNCTION_ALIGNMENT
16841684
config ARCH_NEED_CMPXCHG_1_EMU
16851685
bool
16861686

1687+
config ARCH_WANTS_PRE_LINK_VMLINUX
1688+
bool
1689+
help
1690+
An architecture can select this if it provides arch/<arch>/tools/Makefile
1691+
with .arch.vmlinux.o target to be linked into vmlinux.
1692+
16871693
endmenu

scripts/Makefile.vmlinux

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ targets += .vmlinux.export.o
2222
vmlinux: .vmlinux.export.o
2323
endif
2424

25+
ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
26+
vmlinux: arch/$(SRCARCH)/tools/vmlinux.arch.o
27+
28+
arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE
29+
$(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
30+
endif
31+
2532
ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
2633

2734
# Final link of vmlinux with optional arch pass after final link

scripts/link-vmlinux.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ vmlinux_link()
100100
${ld} ${ldflags} -o ${output} \
101101
${wl}--whole-archive ${objs} ${wl}--no-whole-archive \
102102
${wl}--start-group ${libs} ${wl}--end-group \
103-
${kallsymso} ${btf_vmlinux_bin_o} ${ldlibs}
103+
${kallsymso} ${btf_vmlinux_bin_o} ${arch_vmlinux_o} ${ldlibs}
104104
}
105105

106106
# generate .BTF typeinfo from DWARF debuginfo
@@ -198,6 +198,11 @@ fi
198198

199199
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init init/version-timestamp.o
200200

201+
arch_vmlinux_o=
202+
if is_enabled CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX; then
203+
arch_vmlinux_o=arch/${SRCARCH}/tools/vmlinux.arch.o
204+
fi
205+
201206
btf_vmlinux_bin_o=
202207
kallsymso=
203208
strip_debug=

0 commit comments

Comments
 (0)