Hi folks,
Please backport commit f634ca650f72 "kbuild: Add $(KBUILD_HOSTLDFLAGS) to 'has_libelf' test" to stable series 5.10.y, 5.4.y & 4.19.y.
This backport is needed to fix builds with CONFIG_UNWINDER_ORC=y where HOSTLDFLAGS is given on the make command line containing library paths needed to link against libelf. The issue was found when trying to build stable kernel branches for x86-64 using Yocto Project after commit 7fd06a57a1d9 "kernel: Rework kernel make flag to variable mappings" was added to openembedded-core back in October.
The backport to 5.10.y is trivial. The backports to 5.4.y & 4.19.y need a minor tweak so I'll send patches for those following this email.
The build failure is also seen in 4.14.y but I can't see a trivial way to address this as KBUILD_HOSTLDFLAGS does not exist in 4.14.y and backporting the commit which introduces KBUILD_HOSTLDFLAGS would change several other kbuild areas. I'm happy to workaround this locally by disabling CONFIG_UNWINDER_ORC for 4.14.y builds but it may be worth considering alternative fixes for this branch.
Let me know if there are any questions.
From: Nathan Chancellor nathan@kernel.org
Normally, invocations of $(HOSTCC) include $(KBUILD_HOSTLDFLAGS), which in turn includes $(HOSTLDFLAGS), which allows users to pass in their own flags when linking. However, the 'has_libelf' test does not, meaning that if a user requests a specific linker via HOSTLDFLAGS=-fuse-ld=..., it is not respected and the build might error.
For example, if a user building with clang wants to use all of the LLVM tools without any GNU tools, they might remove all of the GNU tools from their system or PATH then build with
$ make HOSTLDFLAGS=-fuse-ld=lld LLVM=1 LLVM_IAS=1
which says use all of the LLVM tools, the integrated assembler, and ld.lld for linking host executables. Without this change, the build will error because $(HOSTCC) uses its default linker, rather than the one requested via -fuse-ld=..., which is GNU ld in clang's case in a default configuration.
error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel make[1]: *** [Makefile:1260: prepare-objtool] Error 1
Add $(KBUILD_HOSTLDFLAGS) to the 'has_libelf' test so that the linker choice is respected.
Link: https://github.com/ClangBuiltLinux/linux/issues/479 Signed-off-by: Nathan Chancellor nathan@kernel.org Signed-off-by: Masahiro Yamada masahiroy@kernel.org
commit f634ca650f72 upstream. Modified to account for the location of the has_libelf check in 5.4.y & 4.19.y. Signed-off-by: Paul Barker paul.barker@sancloud.com --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index cfcecc33b4c1..ebaec73de53b 100644 --- a/Makefile +++ b/Makefile @@ -972,7 +972,7 @@ HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
ifdef CONFIG_STACK_VALIDATION has_libelf := $(call try-run,\ - echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0) + echo "int main() {}" | $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0) ifeq ($(has_libelf),1) objtool_target := tools/objtool FORCE else
On Fri, Jan 14, 2022 at 02:14:02PM +0000, Paul Barker wrote:
Hi folks,
Please backport commit f634ca650f72 "kbuild: Add $(KBUILD_HOSTLDFLAGS) to 'has_libelf' test" to stable series 5.10.y, 5.4.y & 4.19.y.
This backport is needed to fix builds with CONFIG_UNWINDER_ORC=y where HOSTLDFLAGS is given on the make command line containing library paths needed to link against libelf. The issue was found when trying to build stable kernel branches for x86-64 using Yocto Project after commit 7fd06a57a1d9 "kernel: Rework kernel make flag to variable mappings" was added to openembedded-core back in October.
The backport to 5.10.y is trivial. The backports to 5.4.y & 4.19.y need a minor tweak so I'll send patches for those following this email.
The build failure is also seen in 4.14.y but I can't see a trivial way to address this as KBUILD_HOSTLDFLAGS does not exist in 4.14.y and backporting the commit which introduces KBUILD_HOSTLDFLAGS would change several other kbuild areas. I'm happy to workaround this locally by disabling CONFIG_UNWINDER_ORC for 4.14.y builds but it may be worth considering alternative fixes for this branch.
Added to 4.19.y queue right now. Will add to 5.4.y queue once the next release is out as it is currently in -rc status.
thanks,
greg k-h
linux-stable-mirror@lists.linaro.org