Re: kldxref: /boot/kernel/kernel: no ELF relocation table found

From: Jessica Clarke <jrtc27_at_freebsd.org>
Date: Mon, 02 Sep 2024 17:57:05 UTC
On 2 Sep 2024, at 11:54, Dennis Clarke <dclarke@blastwave.org> wrote:
> 
> 
> All:
> 
>    Ye ol "make installkernel" starts nicely but ends a little odd :
> 
> 
> e# make installkernel
> --------------------------------------------------------------
> >>> Install check kernel
> --------------------------------------------------------------
> --------------------------------------------------------------
> >>> Installing kernel GENERIC on Mon Sep  2 10:10:05 UTC 2024
> --------------------------------------------------------------
> cd /usr/obj/usr/src/riscv.riscv64/sys/GENERIC;  MACHINE_ARCH=riscv64 MACHINE=riscv  CPUTYPE= CC="cc -target riscv64-unknown-freebsd15.0 --sysroot=/usr/obj/usr/src/riscv.riscv64/tmp -B/usr/obj/usr/src/riscv.riscv64/tmp/usr/bin" CXX="c++  -target riscv64-unknown-freebsd15.0 --sysroot=/usr/obj/usr/src/riscv.riscv64/tmp -B/usr/obj/usr/src/riscv.riscv64/tmp/usr/bin"  CPP="cpp -target riscv64-unknown-freebsd15.0 --sysroot=/usr/obj/usr/src/riscv.riscv64/tmp -B/usr/obj/usr/src/riscv.riscv64/tmp/usr/bin"  AS="as" AR="ar" ELFCTL="elfctl" LD="ld"  LLVM_LINK="" NM=nm OBJCOPY="objcopy" RANLIB=ranlib STRINGS=  SIZE="size" STRIPBIN="strip" PATH=/usr/obj/usr/src/riscv.riscv64/tmp/bin:/usr/obj/usr/src/riscv.riscv64/tmp/usr/sbin:/usr/obj/usr/src/riscv.riscv64/tmp/usr/bin:/usr/obj/usr/src/riscv.riscv64/tmp/legacy/usr/sbin:/usr/obj/usr/src/riscv.riscv64/tmp/legacy/usr/bin:/usr/obj/usr/src/riscv.riscv64/tmp/legacy/bin:/usr/obj/usr/src/riscv.riscv64/tmp/legacy/usr/libexec::/sbin:/bin:/usr/sbin:/usr/bin  make  KERNEL=kernel METALOG=  install
> thiskernel=`sysctl -n kern.bootfile || echo /boot/kernel/kernel` ;  if [ ! "`dirname "$thiskernel"`" -ef /boot/kernel ] ; then  chflags -R noschg /boot/kernel ;  rm -rf /boot/kernel ;  rm -rf /usr/lib/debug/boot/kernel ;  else  if [ -d /boot/kernel.old ] ; then  chflags -R noschg /boot/kernel.old ;  rm -rf /boot/kernel.old ;  fi ;  mv /boot/kernel /boot/kernel.old ;  if [ -n "/usr/lib/debug" -a  -d /usr/lib/debug/boot/kernel ]; then  rm -rf /usr/lib/debug/boot/kernel.old ;  mv /usr/lib/debug/boot/kernel /usr/lib/debug/boot/kernel.old ;  fi ;  sysctl kern.bootfile=/boot/kernel.old/"`basename "$thiskernel"`" ;  fi
> kern.bootfile: /boot/kernel/kernel -> /boot/kernel.old/kernel
> mkdir -p /boot/kernel
> install -p -m 444 -o root -g wheel kernel /boot/kernel/
> mkdir -p /usr/lib/debug/boot/kernel
> install -p -m 444 -o root -g wheel kernel.debug /usr/lib/debug/boot/kernel/
> cd /usr/src/sys/modules; MAKEOBJDIRPREFIX=/usr/obj/usr/src/riscv.riscv64/sys/GENERIC/modules KMODDIR=/boot/kernel MACHINE_CPUARCH=riscv MACHINE=riscv MACHINE_ARCH=riscv64 MODULES_EXTRA="dtb/sifive" WITHOUT_MODULES="" ARCH_FLAGS="" DEBUG_FLAGS="-g" __MPATH="" KERNBUILDDIR="/usr/obj/usr/src/riscv.riscv64/sys/GENERIC" SYSDIR="/usr/src/sys" MODULE_TIED=yes WITH_CTF="1" make  install
> ===> accf_data (install)
> install -T release -o root -g wheel -m 444   accf_data.ko /boot/kernel/
> install -T dbg -o root -g wheel -m 444   accf_data.ko.debug /usr/lib/debug/boot/kernel/
> ===> accf_dns (install)
> install -T release -o root -g wheel -m 444   accf_dns.ko /boot/kernel/
> install -T dbg -o root -g wheel -m 444   accf_dns.ko.debug /usr/lib/debug/boot/kernel/
> .
> .
> .  etc etc etc
> .
> .
> ===> xz (install)
> install -T release -o root -g wheel -m 444   xz.ko /boot/kernel/
> install -T dbg -o root -g wheel -m 444   xz.ko.debug /usr/lib/debug/boot/kernel/
> ===> zfs (install)
> install -T release -o root -g wheel -m 444   zfs.ko /boot/kernel/
> install -T dbg -o root -g wheel -m 444   zfs.ko.debug /usr/lib/debug/boot/kernel/
> ===> zlib (install)
> install -T release -o root -g wheel -m 444   zlib.ko /boot/kernel/
> install -T dbg -o root -g wheel -m 444   zlib.ko.debug /usr/lib/debug/boot/kernel/
> kldxref /boot/kernel
> kldxref: /boot/kernel/kernel: no ELF relocation table found
> 
> --------------------------------------------------------------
> >>> Installing kernel GENERIC completed on Mon Sep  2 10:13:55 UTC 2024
> --------------------------------------------------------------
> 
> 
> 
> 
> So then ... "no ELF relocation table found"?
> 
> Looking at https://cgit.freebsd.org/src/tree/usr.sbin/kldxref/ef.c#n220
> and then downwards to line 367 :
> 
>    if (rel_off == 0 && rela_off == 0) {
>        warnx("%s: no ELF relocation table found\n", ef->ef_name);
>        error = EFTYPE;
>        goto out;
>    }
> 
> Which makes me wonder about the ( I hope ) harmless output from this :
> 
> 
> # kldxref -dv /boot/kernel
> /boot/kernel/accf_data.ko
>  module accf_data
>  depends on kernel.1500023 (1500023,1500023)
>  interface accf_data.1
> /boot/kernel/accf_dns.ko
>  module accf_dns
>  depends on kernel.1500023 (1500023,1500023)
>  interface accf_dns.1
> .
> .
> .
> /boot/kernel/kern_testfrwk.ko
>  module kern_testframework
>  interface kern_testframework.1
>  depends on kernel.1500023 (1500023,1500023)
> /boot/kernel/kernel
> kldxref: /boot/kernel/kernel: no ELF relocation table found
> 
> kldxref: /boot/kernel/kernel: not a valid DSO or object file: Inappropriate file type or format
> /boot/kernel/kgssapi.ko
>  module kgssapi
>  depends on kernel.1500023 (1500023,1500023)
>  depends on xdr.1 (1,1)
>  depends on krpc.1 (1,1)
>  interface kgssapi.1
> .
> .
> .
> 
> etc etc
> 
> .
> .
> .
> 
> 
> 
> 
> 
> Also I do see this was created :
> 
> e# ls -lapb /boot/kernel/linker.hints
> -rw-r--r--  1 root wheel 212416 Sep  2 10:13 /boot/kernel/linker.hints
> e#
> 
> Looking over the output from "readelf -delV /boot/kernel.old/kernel" as
> well as this new kernel they both look very similar. Addresses and some
> other bits changed of course.
> 
> So therefore the situation :
> 
>    ( 1 )  well understood and just a normal red herring[1]
> 
>    ( 2 )  ignore it
> 
>    ( 3 )  huh? that's weird. never saw that before.
> 
> Curious what is going on there.

It’s a harmless warning from an overly-careful set of checks. The tool
was refactored and this case went from being ignored to warning. Cc’ing
jhb@ to remind him of this as I pointed it out a while ago.

Jess