Public bug reported:

When building out-of-tree kernel modules (via DKMS or manual module
build) on systems with the debuginfo package (`linux-image-*-dbgsym`)
installed, BTF (BPF Type Format) generation is skipped due to vmlinux
not being found in the expected location. This prevents BPF-based
tracing tools (bpftrace, BCC) from attaching kprobes/kfuncs to out-of-
tree module functions.

steps to reproduce:

git clone https://github.com/ivbakula/hello-world-kernel-module

$ cd hello-world-kernel-module

$ make -C /usr/src/linux-headers-6.14.0-33-generic/ M=$PWD modules V=1

make: Entering directory '/usr/src/linux-headers-6.14.0-33-generic'
<snip>

# LD [M]  hello.ko

  ld -r -m elf_x86_64 -z noexecstack --no-warn-rwx-segments --build-
id=sha1  -T /usr/src/linux-headers-6.14.0-33-generic/scripts/module.lds
-o hello.ko hello.o hello.mod.o .module-common.o

# BTF [M] hello.ko

  if [ ! -f /usr/src/linux-headers-6.14.0-33-generic/vmlinux ]; then
printf "Skipping BTF generation for %s due to unavailability of
vmlinux\n" hello.ko 1>&2; else LLVM_OBJCOPY="objcopy" pahole -J
--btf_gen_floats -j --skip_encoding_btf_inconsistent_proto
--btf_gen_optimized --lang_exclude=rust  --btf_base /usr/src/linux-
headers-6.14.0-33-generic/vmlinux hello.ko; /usr/src/linux-
headers-6.14.0-33-generic/tools/bpf/resolve_btfids/resolve_btfids -b
/usr/src/linux-headers-6.14.0-33-generic/vmlinux hello.ko; fi;

Skipping BTF generation for hello.ko due to unavailability of vmlinux

make[1]: Leaving directory '/tmp/hello-world-kernel-module'

make: Leaving directory '/usr/src/linux-headers-6.14.0-33-generic'


"Skipping BTF generation for hello.ko due to unavailability of vmlinux" says 
vmlinux wasn't found.
Workaround: ln -s /usr/lib/debug/boot/vmlinux-$(uname -r) 
/usr/src/linux-headers-$(uname -r)/vmlinux it seems to work.

** Affects: linux-nvidia-6.17 (Ubuntu)
     Importance: Undecided
         Status: New

** Description changed:

  When building out-of-tree kernel modules (via DKMS or manual module
  build) on systems with the debuginfo package (`linux-image-*-dbgsym`)
  installed, BTF (BPF Type Format) generation is skipped due to vmlinux
  not being found in the expected location. This prevents BPF-based
  tracing tools (bpftrace, BCC) from attaching kprobes/kfuncs to out-of-
  tree module functions.
  
- 
  steps to reproduce:
  
  git clone https://github.com/ivbakula/hello-world-kernel-module
- 
- Cloning into 'hello-world-kernel-module'...
- 
- remote: Enumerating objects: 11, done.
- 
- remote: Counting objects: 100% (11/11), done.
- 
- remote: Compressing objects: 100% (9/9), done.
- 
- remote: Total 11 (delta 1), reused 8 (delta 1), pack-reused 0 (from 0)
- 
- Receiving objects: 100% (11/11), 13.63 KiB | 218.00 KiB/s, done.
- 
- Resolving deltas: 100% (1/1), done.
  
  $ cd hello-world-kernel-module
  
  $ make -C /usr/src/linux-headers-6.14.0-33-generic/ M=$PWD modules V=1
  
  make: Entering directory '/usr/src/linux-headers-6.14.0-33-generic'
- 
- make  -C /tmp/hello-world-kernel-module \
-       -f /usr/src/linux-headers-6.14.0-33-generic/Makefile modules
- 
- make[1]: Entering directory '/tmp/hello-world-kernel-module'
- 
- make --no-print-directory -C /tmp/hello-world-kernel-module \
-       -f /usr/src/linux-headers-6.14.0-33-generic/Makefile modules
- 
- warning: the compiler differs from the one used to build the kernel
-   The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 
13.3.0-6ubuntu2~24.04) 13.3.0
-   You are using:           gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
- 
- make -f /usr/src/linux-headers-6.14.0-33-generic/scripts/Makefile.build
- obj=. need-builtin=1 need-modorder=1
- 
- # CC [M]  hello.o
- 
-   gcc-13 -Wp,-MMD,./.hello.o.d -nostdinc -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/generated -I/usr/src/linux-
- headers-6.14.0-33-generic/include -I/usr/src/linux-
- headers-6.14.0-33-generic/include -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/uapi -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/generated/uapi
- -I/usr/src/linux-headers-6.14.0-33-generic/include/uapi
- -I/usr/src/linux-headers-6.14.0-33-generic/include/generated/uapi
- -include /usr/src/linux-
- headers-6.14.0-33-generic/include/linux/compiler-version.h -include
- /usr/src/linux-headers-6.14.0-33-generic/include/linux/kconfig.h
- -I/usr/src/linux-headers-6.14.0-33-generic/ubuntu/include -include
- /usr/src/linux-headers-6.14.0-33-generic/include/linux/compiler_types.h
- -D__KERNEL__ -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-
- PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
- -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387
- -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup
- -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-
- asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-
- branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-
- extern -fno-jump-tables -mharden-sls=all -fpatchable-function-
- entry=16,16 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-
- races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-
- sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection
- -fzero-call-used-regs=used-gpr -pg -mrecord-mcount -mfentry
- -DCC_USING_FENTRY -falign-functions=16 -fstrict-flex-arrays=3 -fno-
- strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen
- -Wall -Wextra -Wundef -Werror=implicit-function-declaration
- -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-
- format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-
- packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-
- larger-than=1024 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign
- -Wcast-function-type -Wno-array-bounds -Wno-stringop-overflow -Wno-
- alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time
- -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-
- conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-
- variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-
- truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-
- field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-
- maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -gdwarf-5
- -fsanitize=bounds-strict -fsanitize=shift -fsanitize=bool
- -fsanitize=enum    -DMODULE  -DKBUILD_BASENAME='"hello"'
- -DKBUILD_MODNAME='"hello"' -D__KBUILD_MODNAME=kmod_hello -c -o hello.o
- hello.c   ; /usr/src/linux-
- headers-6.14.0-33-generic/tools/objtool/objtool --hacks=jump_label
- --hacks=noinstr --hacks=skylake --retpoline --rethunk --sls --stackval
- --static-call --uaccess --prefix=16   --module hello.o
- 
- # cmd_gen_objtooldep hello.o
- 
-    { echo ; echo 'hello.o: $(wildcard /usr/src/linux-
- headers-6.14.0-33-generic/tools/objtool/objtool)' ; } >> ./.hello.o.cmd
- 
- # cmd_gen_symversions_c hello.o
- 
-   if nm hello.o 2>/dev/null | grep -q ' __export_symbol_'; then  nm
- hello.o | sed -n 's/.* __export_symbol_\(.*\)/^A/p' | /usr/src/linux-
- headers-6.14.0-33-generic/scripts/gendwarfksyms/gendwarfksyms   hello.o
- >> ./.hello.o.cmd; fi
- 
- # cmd_mod hello.mod
- 
-   printf '%s\n'   hello.o | awk '!x[$0]++ { print("./"$0) }' > hello.mod
- 
- # cmd_gen_order modules.order
- 
-   {   echo hello.o; :; } > modules.order
- 
- sh /usr/src/linux-headers-6.14.0-33-generic/scripts/modules-check.sh
- modules.order
- 
- make -f /usr/src/linux-
- headers-6.14.0-33-generic/scripts/Makefile.modpost
- 
- # MODPOST Module.symvers
- 
-    /usr/src/linux-headers-6.14.0-33-generic/scripts/mod/modpost -M -m -b
- -x -a      -o Module.symvers -T modules.order -i /usr/src/linux-
- headers-6.14.0-33-generic/Module.symvers -e
- 
- make -f /usr/src/linux-
- headers-6.14.0-33-generic/scripts/Makefile.modfinal
- 
- # CC [M]  hello.mod.o
- 
-   gcc-13 -Wp,-MMD,./.hello.mod.o.d -nostdinc -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/generated -I/usr/src/linux-
- headers-6.14.0-33-generic/include -I/usr/src/linux-
- headers-6.14.0-33-generic/include -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/uapi -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/generated/uapi
- -I/usr/src/linux-headers-6.14.0-33-generic/include/uapi
- -I/usr/src/linux-headers-6.14.0-33-generic/include/generated/uapi
- -include /usr/src/linux-
- headers-6.14.0-33-generic/include/linux/compiler-version.h -include
- /usr/src/linux-headers-6.14.0-33-generic/include/linux/kconfig.h
- -I/usr/src/linux-headers-6.14.0-33-generic/ubuntu/include -include
- /usr/src/linux-headers-6.14.0-33-generic/include/linux/compiler_types.h
- -D__KERNEL__ -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-
- PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
- -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387
- -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup
- -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-
- asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-
- branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-
- extern -fno-jump-tables -mharden-sls=all -fpatchable-function-
- entry=16,16 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-
- races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-
- sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection
- -fzero-call-used-regs=used-gpr -pg -mrecord-mcount -mfentry
- -DCC_USING_FENTRY -falign-functions=16 -fstrict-flex-arrays=3 -fno-
- strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen
- -Wall -Wextra -Wundef -Werror=implicit-function-declaration
- -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-
- format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-
- packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-
- larger-than=1024 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign
- -Wcast-function-type -Wno-array-bounds -Wno-stringop-overflow -Wno-
- alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time
- -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-
- conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-
- variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-
- truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-
- field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-
- maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -gdwarf-5
- -fsanitize=bounds-strict -fsanitize=shift -fsanitize=bool
- -fsanitize=enum    -DMODULE  -DKBUILD_BASENAME='"hello.mod"'
- -DKBUILD_MODNAME='"hello"' -D__KBUILD_MODNAME=kmod_hello -c -o
- hello.mod.o hello.mod.c   ; /usr/src/linux-
- headers-6.14.0-33-generic/tools/objtool/objtool --hacks=jump_label
- --hacks=noinstr --hacks=skylake --retpoline --rethunk --sls --stackval
- --static-call --uaccess --prefix=16   --module hello.mod.o
- 
- # cmd_gen_objtooldep hello.mod.o
- 
-    { echo ; echo 'hello.mod.o: $(wildcard /usr/src/linux-
- headers-6.14.0-33-generic/tools/objtool/objtool)' ; } >>
- ./.hello.mod.o.cmd
- 
- # CC [M]  .module-common.o
- 
-   gcc-13 -Wp,-MMD,./..module-common.o.d -nostdinc -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/generated -I/usr/src/linux-
- headers-6.14.0-33-generic/include -I/usr/src/linux-
- headers-6.14.0-33-generic/include -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/uapi -I/usr/src/linux-
- headers-6.14.0-33-generic/arch/x86/include/generated/uapi
- -I/usr/src/linux-headers-6.14.0-33-generic/include/uapi
- -I/usr/src/linux-headers-6.14.0-33-generic/include/generated/uapi
- -include /usr/src/linux-
- headers-6.14.0-33-generic/include/linux/compiler-version.h -include
- /usr/src/linux-headers-6.14.0-33-generic/include/linux/kconfig.h
- -I/usr/src/linux-headers-6.14.0-33-generic/ubuntu/include -include
- /usr/src/linux-headers-6.14.0-33-generic/include/linux/compiler_types.h
- -D__KERNEL__ -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-
- PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
- -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387
- -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup
- -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-
- asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-
- branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-
- extern -fno-jump-tables -mharden-sls=all -fpatchable-function-
- entry=16,16 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-
- races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-
- sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection
- -fzero-call-used-regs=used-gpr -pg -mrecord-mcount -mfentry
- -DCC_USING_FENTRY -falign-functions=16 -fstrict-flex-arrays=3 -fno-
- strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen
- -Wall -Wextra -Wundef -Werror=implicit-function-declaration
- -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-
- format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-
- packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-
- larger-than=1024 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign
- -Wcast-function-type -Wno-array-bounds -Wno-stringop-overflow -Wno-
- alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time
- -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-
- conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-
- variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-
- truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-
- field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-
- maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -gdwarf-5
- -fsanitize=bounds-strict -fsanitize=shift -fsanitize=bool
- -fsanitize=enum    -DMODULE  -DKBUILD_BASENAME='".module_common"'
- -DKBUILD_MODNAME='".module_common.o"'
- -D__KBUILD_MODNAME=kmod_.module_common.o -c -o .module-common.o
- /usr/src/linux-headers-6.14.0-33-generic/scripts/module-common.c   ;
- /usr/src/linux-headers-6.14.0-33-generic/tools/objtool/objtool
- --hacks=jump_label --hacks=noinstr --hacks=skylake --retpoline --rethunk
- --sls --stackval --static-call --uaccess --prefix=16   --module .module-
- common.o
- 
- # cmd_gen_objtooldep .module-common.o
- 
-    { echo ; echo '.module-common.o: $(wildcard /usr/src/linux-
- headers-6.14.0-33-generic/tools/objtool/objtool)' ; } >> ./..module-
- common.o.cmd
+ <snip>
  
  # LD [M]  hello.ko
  
-   ld -r -m elf_x86_64 -z noexecstack --no-warn-rwx-segments --build-
+   ld -r -m elf_x86_64 -z noexecstack --no-warn-rwx-segments --build-
  id=sha1  -T /usr/src/linux-headers-6.14.0-33-generic/scripts/module.lds
  -o hello.ko hello.o hello.mod.o .module-common.o
  
  # BTF [M] hello.ko
  
-   if [ ! -f /usr/src/linux-headers-6.14.0-33-generic/vmlinux ]; then
+   if [ ! -f /usr/src/linux-headers-6.14.0-33-generic/vmlinux ]; then
  printf "Skipping BTF generation for %s due to unavailability of
  vmlinux\n" hello.ko 1>&2; else LLVM_OBJCOPY="objcopy" pahole -J
  --btf_gen_floats -j --skip_encoding_btf_inconsistent_proto
  --btf_gen_optimized --lang_exclude=rust  --btf_base /usr/src/linux-
  headers-6.14.0-33-generic/vmlinux hello.ko; /usr/src/linux-
  headers-6.14.0-33-generic/tools/bpf/resolve_btfids/resolve_btfids -b
  /usr/src/linux-headers-6.14.0-33-generic/vmlinux hello.ko; fi;
  
  Skipping BTF generation for hello.ko due to unavailability of vmlinux
  
  make[1]: Leaving directory '/tmp/hello-world-kernel-module'
  
  make: Leaving directory '/usr/src/linux-headers-6.14.0-33-generic'
+ 
+ 
+ "Skipping BTF generation for hello.ko due to unavailability of vmlinux" says 
vmlinux wasn't found.
+ Workaround: ln -s /usr/lib/debug/boot/vmlinux-$(uname -r) 
/usr/src/linux-headers-$(uname -r)/vmlinux it seems to work.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2133794

Title:
  BTF Generation Fails for Out-of-Tree Modules with Debuginfo Package

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux-nvidia-6.17/+bug/2133794/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to