History log of /freebsd-current/usr.sbin/kldxref/ef.h
Revision Date Author Comments
# 785600d0 18-Mar-2024 John Baldwin <jhb@FreeBSD.org>

kldxref: Properly handle reading strings near the end of an ELF file

If a string is at or near the end of an input file and the amount of
remaining data in the file is smaller than the maximum string size,
the pread(2) system call would return a short read which is treated as
an error. Instead, add a new helper function for reading a string
which permits short reads so long as the data read from the file
contains a terminated string.

Reported by: jrtc27
Reviewed by: jrtc27
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D44419


# 6631e2f9 09-Jan-2024 John Baldwin <jhb@FreeBSD.org>

kldxref: Workaround incorrect PT_DYNAMIC in existing powerpc kernels

Existing powerpc kernels include additional sections beyond .dynamic
in the PT_DYNAMIC segment. Relax the requirement for an exact size
match of the section and segment for PowerPC files as a workaround.

Reported by: jrtc27
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D43123


# 97530894 13-Dec-2023 Baptiste Daroussin <bapt@FreeBSD.org>

kldxref: fix build on 32 bits arches


# 0299afdf 12-Dec-2023 John Baldwin <jhb@FreeBSD.org>

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

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


# 087c4c90 12-Dec-2023 John Baldwin <jhb@FreeBSD.org>

kldxref: Add a copyright and license statement to ef.h

This uses the statement from other files in kldxref when the tool was
first imported in commit 9c6f92408c29a8980e7aec26a2590087c3b3d8ed.

Reviewed by: kevans
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D42963


# 2a63c3be 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c comment pattern

Remove /^/[*/]\s*\$FreeBSD\$.*\n/


# da67e6e6 16-Jan-2018 Ed Maste <emaste@FreeBSD.org>

kldxref: handle modules with md_cval at the end of allocated sections

Attempting to retrieve an md_cval string from a kernel module with
kldxref would throw a offset error for modules created using lld, since
this value would be placed at the end of all allocated sections.

Add an ef_read_seg_string method to the ef interface, to allow reading
strings of varying size without attempting to read beyond the segment's
bounds.

PR: 224875
Submitted by: Mitchell Horne <mhorne063@gmail.com>
Reviewed by: cem, kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D13923


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 757686b1 17-Dec-2005 Marcel Moolenaar <marcel@FreeBSD.org>

Make our ELF64 type definitions match standards. In particular this
means:
o Remove Elf64_Quarter,
o Redefine Elf64_Half to be 16-bit,
o Redefine Elf64_Word to be 32-bit,
o Add Elf64_Xword and Elf64_Sxword for 64-bit entities,
o Use Elf_Size in MI code to abstract the difference between
Elf32_Word and Elf64_Word.
o Add Elf_Ssize as the signed counterpart of Elf_Size.

MFC after: 2 weeks


# 9dba198b 28-Aug-2004 Ian Dowse <iedowse@FreeBSD.org>

Explicitly pass in the relocation base and data offset into ef_reloc()
rather than relying on a trick that happens to work for the current
relocation schemes. Also add some comments and improve variable
naming.


# 9772dc2a 26-Aug-2004 Ian Dowse <iedowse@FreeBSD.org>

Call the file format specific code through a table of function
pointers and remove knowledge of the file format from kldxref.c.
This will make it possible to support more than one file format.


# 1eed250a 20-Jan-2003 Jake Burkholder <jake@FreeBSD.org>

Fix kldxref on sparc64 by allowing non-trivial relocations to be performed
on variables read out of raw kld files. Unlike other platforms the value
will be in an Elf_Rela, not in the data section of the elf file.

Submitted by: Hartmut Brandt <brandt@fokus.gmd.de>
PR: 46730
Tested on: alpha (obrien), i386, sparc64


# f23aa297 11-Apr-2002 Peter Wemm <peter@FreeBSD.org>

Make kldxref work for Elf64 (which has 32 bit hash tables)


# 9c6f9240 10-Sep-2001 Peter Wemm <peter@FreeBSD.org>

Add kldxref(8), for maintaining the linker.hints file for translating
module->pathname.ko. It supports only ELF for now.

Submitted by: bp (with some minor tweaks)