aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/kldxref
Commit message (Collapse)AuthorAgeFilesLines
* mips: remove mips leftoversMinsoo Choo2026-01-061-1/+0
| | | | | Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me> Pull-request: https://github.com/freebsd/freebsd-src/pull/1909
* libkldelf: add a private library for kernel/kld-related ELF parsingKa Ho Ng2024-10-1813-2812/+24
| | | | | | | | | | | | | | | | | | | | | | The libkldelf library was originally a part of kldxref(8). It exposed ELF parsing helpers specialized in parsing KLDs and the kernel executable. The library can be used to read metadata such as linker_set, mod_depend, mod_version and PNP match info, and raw data from the ELF. To promote the reuse of the facilities the ELF parsing code is separated from kldxref(8) into a new private library. For now, libkldelf's source files will be compiled into kldxref(8) directly if kldxref is built during bootstrapping phase. The reason is linking kldxref(8) against the libkldelf static library has an unwanted side effect which renders the linker sets inside the libkldelf implementation empty if the static library is not build by ld -r all the .o files into a single .o before producing the static library. Sponsored by: Juniper Networks, Inc. Reviewed by: markj Suggested by: jrtc27, markj Differential Revision: https://reviews.freebsd.org/D46719
* Update Makefile.depend filesSimon J. Gerraty2024-10-141-0/+1
| | | | | | | After building packages we have a number of new and updated Makefile.depend files Reviewed by: stevek
* Revert "libkldelf: add a private library for kernel/kld-related ELF parsing"Ka Ho Ng2024-10-0813-5/+2813
| | | | This reverts commit 0a2cfd653e86ac41c4e6e32a449d133c0ee6d677.
* libkldelf: add a private library for kernel/kld-related ELF parsingKa Ho Ng2024-10-0813-2813/+5
| | | | | | | | | | | | | | | | The libkldelf library was originally a part of kldxref(8). It exposed ELF parsing helpers specialized in parsing KLDs and the kernel executable. The library can be used to read metadata such as linker_set, mod_depend, mod_version and PNP match info, and raw data from the ELF. To promote the reuse of the facilities the ELF parsing code is separated from kldxref(8) into a new private library. kldxref(8) is modified to link against the libkldelf library. Sponsored by: Juniper Networks, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D46719
* kldxref: Don't warn and skip file if no relocations are foundJessica Clarke2024-09-101-5/+0
| | | | | | | | | | | This case is hit for the kernel itself on riscv64, and did not used to be checked. Since the code here can already handle missing Elf_Rel and/or Elf_Rela just delete the check. Reviewed by: jhb, imp Fixes: 0299afdff145 ("kldxref: Make use of libelf to be a portable cross tool") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D46517
* kldxref: Clarify ambiguous commentJessica Clarke2024-08-121-2/+2
| | | | | | | This previously read, to me at least, as if the not only applied to ending with ".ko", not to the entire rest of the sentence, and thus the implementation looked wrong. The history of D43507 however shows that the behaviour is as intended.
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* cross-tools: fts has different types for cmp routineWarner Losh2024-05-261-1/+1
| | | | | | | | | | | | | | | | fts has different types for its compare rotuine. Other systems, not 4.4BSD based, have a non-const version. Before we tested against __GLIBC__, but now we test against __linux__ because that's Linux's API and musl doesn't define __GLIBC__. In addition, link against libftl on this platform since musl doesn't include ftl routines in libc, but rather in libftl. Co-authored-by: Val Packett <val@packett.cool> Sponsored by: Netflix Pull Request: https://github.com/freebsd/freebsd-src/pull/1066 Reviewed by: val_packett.cool Differential Revision: https://reviews.freebsd.org/D45349
* kldxref: Prefer sys/cdefs.h __unreachable over the builtinCollin Funk2024-04-121-1/+1
| | | | | | | | | | | | | | The __builtin_unreachable macro provided by Clang and GCC is a hint to the compiler used for optimization. The programs work fine even if the compiler doesn't support it. The sys/cdefs.h has had __unreachable for 9 years (commit 732b31de5d9244bd1cc98192e09ee1881e9f55e9). It expands to the builtin if it is available. In the rare case that it is unsupported it expands to a null statement so compilation does not fail. Signed-off-by: Collin Funk <collin.funk1@gmail.com> Reviewed by: imp, freebsd@igalic.co Pull Request: https://github.com/freebsd/freebsd-src/pull/1117
* usr.sbin: Remove repeated wordsElyes Haouas2024-04-111-1/+1
| | | | | | Signed-off-by: Elyes Haouas <ehaouas@noos.fr> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/887
* kldxref: Properly handle reading strings near the end of an ELF fileJohn Baldwin2024-03-194-16/+24
| | | | | | | | | | | | | | 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
* kldxref: Fix bootstrapping on macOS with Clang 16 / Apple Clang 15Jessica Clarke2024-03-161-1/+1
| | | | | | | | | macOS, like Linux, does not include an outer const qualifier for its fts_open callback arguments, so -Wincompatible-function-pointer-types also picks this up and breaks the build now Clang 16 makes it an error by default. Extend the existing Linux support to fix this. MFC after: 1 week
* kldxref: Fix maketempfile function's way of finding the root dirMina Galić2024-02-021-5/+2
| | | | | | | | | | | | | Rather than assuming that the "root" is passed as directory and will be marked by a trailing slash, we just assume that the directory, which has been checked previously to be a directory, is a directory. This fixes an inconsistency between `kldxref /boot/modules`, which tries to create the temp file in `/boot/`, and `kldxref /boot/modules/`, which tries to create it in `/boot/modules/` itself. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1093
* kldxref: Be more conservative about what we reject.Warner Losh2024-01-292-11/+10
| | | | | | | | | kldxref anything whose name doesn't end in .ko or that has no dots (eg the kernel). Sponsored by: Netflix Reviewed by: jrtc27, jhb Differential Revision: https://reviews.freebsd.org/D43507
* kldxref: Workaround incorrect PT_DYNAMIC in existing powerpc kernelsJohn Baldwin2024-01-092-1/+11
| | | | | | | | | | 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
* kldxref: Correct contract number in license ACKJohn Baldwin2024-01-091-1/+1
| | | | | | Reviewed by: brooks Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43371
* kldxref: fix bootstrapping on Linux with Clang 16Alex Richardson2024-01-021-0/+4
| | | | | | The glibc fts_open() callback type does not have the second const qualifier and it appears that Clang 16 errors by default for mismatched function pointer types. Add an ifdef to handle this case.
* kldxref: Appease a Coverity warningJohn Baldwin2023-12-221-0/+1
| | | | | | | | | | | | | | While parsing .dynamic, nsym is set when parsing the symbol table from .dynsym. That parsing also sets ef->ef_symtab to a non-NULL value. The value of nsym isn't validated until after a check for ef->ef_symtab being NULL, so nsym always has a valid value when it is read. However, that chain of events is a bit much for static analysis to follow, so initialize nsym to 0 before parsing sections to quiet the warning. Reported by: Coverity Scan CID: 1532339 Sponsored by: DARPA
* kldxref: Simplify handling of ELF object filesJohn Baldwin2023-12-221-81/+65
| | | | | | | | | | | | | Unlike the backend for ELF DSOs, the object file backend allocated an aligned chunk of memory and read all of the in-memory sections from the file into this memory even though most of the file contents were never used. Instead, just track a set of virtual addresses (based at 0) that each loaded section would be loaded at and only read the necessary bits from the backing file when needed. Reviewed by: imp Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43126
* kldxref: Simplify elf_read_raw_dataJohn Baldwin2023-12-221-5/+1
| | | | | | | | | | | Use pread as a valid offset is always passed now. Originally the DSO code read the .hash section in two separate requests and relied on the implicit offset for the second read, but now the hash table is fetched in a single call. Reviewed by: imp Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43125
* kldxref: Tidy error handling for invalid addressesJohn Baldwin2023-12-221-3/+3
| | | | | | | | | | - Don't print an offset value that's always zero. - ef_get_offset can't return -1. Reviewed by: imp Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43124
* kldxref: Reduce divergence between per-architecture filesJessica Clarke2023-12-147-79/+83
| | | | | | | | | | | | Note that relbase is always 0 for DSOs so its omission for __KLD_SHARED architectures was not a bug in practice. Whilst here, also parenthesise the dest offset for where to avoid transiently creating an out-of-bounds pointer, which is UB (though even on CHERI architectures, where capability bounds compression can result in that creating invalid capabilities that will trap on dereference, optimisation will reassociate to the correct form in practice and thus work just fine).
* kldxref: Implement aarch64 R_AARCH64_AB64 relocationJessica Clarke2023-12-141-2/+5
| | | | | | Doing nothing seems to be sufficient but is strange, inconsistent with other architectures, and not necessary when it's easy to support properly.
* kldxref: Fix MIPS Elf_Rel addend computationJessica Clarke2023-12-141-1/+0
| | | | Fixes: 0299afdff145 ("kldxref: Make use of libelf to be a portable cross tool")
* kldxref: Add arm supportJessica Clarke2023-12-142-0/+95
|
* kldxref: Put each ef_CPUARCH.c on its own line to prepare for ef_arm.cJessica Clarke2023-12-141-1/+6
| | | | | Adding ef_arm.c would push this past 80 columns, so prepare for its addition by splitting the line up.
* kldxref: Fix for 32-bit powerpcJessica Clarke2023-12-141-1/+2
| | | | | | | R_PPC_RELATIVE lost its 32-bit handling in the libelf conversion. Reported by: bapt Fixes: 0299afdff145 ("kldxref: Make use of libelf to be a portable cross tool")
* kldxref: Cast rtype to int in ef_aarch64.c in warningJohn Baldwin2023-12-131-1/+1
| | | | | | | | This is consistent with the other architecture-specific relocation handlers. Reported by: mjg Sponsored by: DARPA
* kldxref: fix build on 32 bits archesBaptiste Daroussin2023-12-133-7/+7
|
* kldxref: Make use of libelf to be a portable cross toolJohn Baldwin2023-12-1213-925/+1685
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* kldxref: Refactor PNP entry parsing, no functional changeJohn Baldwin2023-12-121-108/+139
| | | | | | | | | | | | | | | | - Add a free_pnp_list to complement parse_pnp_list. Add freeing of 'new_desc' which was previously leaked. - Move body of loop that checked a single pnp list element against a table entry into a parse_pnp_entry function to reduce indentation and split parse_entry into a smaller function. - Similarly, split out a record_pnp_info function from parse_entry which builds the pnp_list and walks a table. Reviewed by: imp Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42965
* Stop #defining FREEBSD_ELFJohn Baldwin2023-12-123-3/+0
| | | | | | | | | | | | This was originally used (along with FREEBSD_AOUT) to prefer the use of ELF in various tools instead of a.out as part of the a.out to ELF transition in the 3.x days. The last use of it was removed from <link.h> in commit 66422f5b7a1a6055f0b2358268eb902aab6e2e3e back in 2002, but various files still #define it. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42964
* kldxref: Add a copyright and license statement to ef.hJohn Baldwin2023-12-121-0/+33
| | | | | | | | | 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
* usr.sbin: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* Remove my middle name.Dag-Erling Smørgrav2023-08-171-1/+1
|
* Remove $FreeBSD$: one-line bare tagWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-161-1/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-169-18/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-125-5/+5
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* Update/fix Makefile.depend for userlandSimon J. Gerraty2023-04-191-1/+0
|
* kldxref: skip .pkgsave filesMina Galić2023-02-252-7/+19
| | | | | | | | | | | This should help people transitioning from traditional setups to pkgbase experience a lot less friction. We do this by skipping all files containing two dots. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/661 Differential Revision: https://reviews.freebsd.org/D27959
* kldxref: handle R_RISCV_64 relocationMitchell Horne2022-10-201-4/+8
| | | | | | | | | | These are emitted in at least two kmods, and kldxref prints a warning. While here, remove the unneeded local variable 'val'. Reviewed by: jrtc27, imp, emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37038
* kldxref: add R_PPC_ADDR32 handlerAlfredo Dal'Ava Junior2022-02-101-1/+8
| | | | | | | | | | | Implements R_PPC_ADDR32 handler for kldxref, addressing "kldxref: unhandled relocation type 1" when running "kldxref /boot/kernel" on powerpc 32 bits. Reviewed by: luporl MFC after: 2 days Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D33745
* kldxref: add R_PPC64_ADDR64 handlerAlfredo Dal'Ava Junior2021-12-271-1/+5
| | | | | | | | | | | Implements R_PPC64_ADDR64 handler for kldxref, addressing "kldxref: unhandled relocation type 38" when running "kldxref /boot/kernel" Reviewed by: jhibbits MFC after: 1 week Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D33615
* kldxref: do not error out if specified path is not directory, for -d modeKonstantin Belousov2021-05-201-1/+1
| | | | | | | | | | | | | | | | kldxref(8) is the only tool that can dump FreeBSD kernel module metadata, with the -d option. But the command line requirements for that are inconvenient, since parser requires that argv[1] is a directory containing whole set of modules to generate xref file. For -d, allow argv[0] to be a regular file, now it is possible to do e.g. $ kldxref -d /boot/kernel/ufs.ko to see only ufs.ko metadata. Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30368
* kldxref: Avoid buffer overflows in parse_pnp_listJessica Clarke2020-10-151-20/+25
| | | | | | | | | | | | | | | | | We convert a string like "W32:vendor/device" into "I:vendor;I:device", where the output is longer than the input, but only allocate space equal to the length of the input, leading to a buffer overflow. Instead use open_memstream so we get a safe dynamically-grown buffer. Found by: CHERI Reviewed by: imp, jhb (mentor) Approved by: imp, jhb (mentor) Obtained from: CheriBSD Differential Revision: https://reviews.freebsd.org/D26637 Notes: svn path=/head/; revision=366736