Page MenuHomeFreeBSD

kldxref: Make use of libelf to be a portable cross tool
ClosedPublic

Authored by jhb on Dec 7 2023, 7:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 11 2024, 12:34 PM
Unknown Object (File)
Oct 6 2024, 3:00 PM
Unknown Object (File)
Sep 28 2024, 5:22 AM
Unknown Object (File)
Sep 28 2024, 3:20 AM
Unknown Object (File)
Sep 18 2024, 5:00 PM
Unknown Object (File)
Sep 8 2024, 9:34 PM
Unknown Object (File)
Aug 25 2024, 5:39 PM
Unknown Object (File)
Aug 25 2024, 5:39 PM
Subscribers

Details

Summary

This allows kldxref to operate on kernel objects from any
architecture, not just the native architecture. In particular, this
will permit generating linker.hints files as part of a cross-release
build.

  • elf.c is a new file that includes various wrappers around libelf including routines to read ELF data structures such as program and section headers and ELF relocations into the "generic" forms described in <gelf.h>. This file also provides routines for converting a linker set into an array of addresses (GElf_Addr) as well as reading architecture-specific mod_* structures and converting them into "generic" Gmod_* forms where pointers are replaced with addresses.
  • The various architecture-specific reloc handlers now use GElf_* types for most values (including GElf_Rel and GElf_Rela for relocation structures) and use routines from <sys/endian.h> to read and write target values. A new linker set matches reloc handlers to specific ELF (class, encoding, machine) tuples.
  • The bits of kldxref.c that write out linker.hints now use the encoding (ELFDATA2[LM]SB) of the first file encountered in a directory to set the endianness of the output file. Input files with a different architecture in the same directory are skipped with a warning. In addition, the initial version record for the file must be deferred until the first record is finished since the architecture of the output file is not known until then.
  • Various places that used 'sizeof(void *)' throughout now use 'elf_pointer_size()' to determine the size of a pointer in the target architecture.

Tested by: amd64 binary on both amd64 and i386 /boot/kernel
Sponsored by: DARPA

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 54857
Build 51746: arc lint + arc unit

Event Timeline

Rebase and a few small tidy fixes

You know this works when you can generate aarch64 xref files on powerpc. Or armv7 from powerpc64 :)
Or vice versa I guess....
This looks fine, but I don't have time to do an extensive review.

This revision is now accepted and ready to land.Dec 11 2023, 2:58 AM