Skip to content

Commit

Permalink
kldxref: Make use of libelf to be a portable cross tool
Browse files Browse the repository at this point in the history
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-arch
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
Reviewed by:	imp
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42966
  • Loading branch information
bsdjhb committed Dec 12, 2023
1 parent c40fa3d commit 0299afd
Show file tree
Hide file tree
Showing 13 changed files with 1,685 additions and 925 deletions.
9 changes: 3 additions & 6 deletions usr.sbin/kldxref/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
PACKAGE= runtime
PROG= kldxref
MAN= kldxref.8
SRCS= kldxref.c ef.c ef_obj.c
SRCS= kldxref.c ef.c ef_obj.c elf.c
SRCS+= ef_aarch64.c ef_amd64.c ef_i386.c ef_mips.c ef_powerpc.c ef_riscv.c

WARNS?= 2

.if exists(ef_${MACHINE_CPUARCH}.c)
SRCS+= ef_${MACHINE_CPUARCH}.c
.else
SRCS+= ef_nop.c
.endif
LIBADD= elf

.include <bsd.prog.mk>
Loading

0 comments on commit 0299afd

Please sign in to comment.