From db14c1001d761372e1b8149886e9ed42fa213aed Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 27 Nov 2024 18:19:18 +0000 Subject: [PATCH] lisa._assets.kmodules.lisa: Workaround llvm-nm bug FIX llvm-nm is broken when working with LLVM bitcode files, as it reports 0 for symbol size, irrespective of the actual symbol size: https://github.com/llvm/llvm-project/issues/33743 Fix the issue by forcing clang to emit a regular ELF object file rather than a LLVM bitcode file by disabling LTO. --- lisa/_assets/kmodules/lisa/lisa-eval-c.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lisa/_assets/kmodules/lisa/lisa-eval-c.sh b/lisa/_assets/kmodules/lisa/lisa-eval-c.sh index 74400f5eb..7126f1a6b 100755 --- a/lisa/_assets/kmodules/lisa/lisa-eval-c.sh +++ b/lisa/_assets/kmodules/lisa/lisa-eval-c.sh @@ -30,7 +30,26 @@ CC=${CC:=cc} NM=${NM:=nm} if ("$CC" --version | grep -i clang) &>/dev/null; then - clang_args=(-Wno-error=unused-command-line-argument) + clang_args=( + # Some CLI args are not used in our simple invocation (e.g. some + # linker-related things), so we don't want that to become a hard error. + -Wno-error=unused-command-line-argument + + # If LTO is enabled, clang will emit LLVM bitcode file instead of object files. + # It turns out llvm-nm is broken and reports 0 size for the symbols + # when passed an LLVM bitcode file: + # https://github.com/llvm/llvm-project/issues/33743 + # + # Consequently, we need to either disable LTO or convince clang to + # still emit an ELF object file with LLVM bitcode in a section instead. + # This can be done with -ffat-lto-objects, but that option is only + # available starting from clang 18. For compat with older versions, we + # disable LTO, and we also disable CFI sanitizer since it requires LTO. + # Note that CFI is similar but not the same as the kCFI sanitizer that + # kernels >= 6.1 exploit. kCFI can be enabled independently of LTO. + -fno-lto + -fno-sanitize=cfi + ) fi # All -I are relative to the kernel tree root, so we need to run from there. -- GitLab