From nobody Tue Oct 08 04:29:33 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XN32P4PxHz5YvHL; Tue, 08 Oct 2024 04:29:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XN32P3t1rz4c8q; Tue, 8 Oct 2024 04:29:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728361773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5adWVJsFLJq8QZMFhbgw3EIXpqSHi1s+Ozl5Vi2aOO0=; b=DFEObXstDLEEo0zBimOHVUs76g1UczNsuk23RCl1/1rK6mHbI6BMTaj+eANft2+X+lGaew G1G7LL8yEsKPV2QHN25rWPTWHegJLJ6XsG6j4WAO1PdLQR/wpnC3qYD511wVFRp3jkd9Tr OobfmNEZz7XMhsaWNgKSQMwe5XPvAYM59MufQ5xWKGT3ZDUzpGC7Vonh7eX+ZgEqfpYlWy O+IdS+9vSipYBwOZ3B9vlYMUKt+v9039sEevaGPp5DKvn641czN7FxHydU07413aJRRyYt NCpGZuGmE8ZliF9Jk/yMza4+ABaVaq8PVN5YF55SOk4D9McMdlVJotYEff4Ijg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728361773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5adWVJsFLJq8QZMFhbgw3EIXpqSHi1s+Ozl5Vi2aOO0=; b=ARayQl5QDX6o3yxrRjxSGEeXZwA5LpO21UEYZ97K1nSKQLVD6Ak58NiGg805rqzOX2wHp+ USRG3O17UcBsMnoa5PdycnVdnU3FHdTFvN/rGW6bKGKVURAq6HfhccdOEKCCc7pRImjCna KAuh47i/MHRcIjaonhr4GbE/wSuCsS+Yt4kpSGdLD7MKZYJkhonbERHsQYhKIokmeicwN0 bRwXZ71HJ3D3vdRNTjp99BrWvegFODZXGqB5MluoYe5EXuCggss7/ByOXZxxMRkk9v0Sho rAjVUfQ0OYfDVDnK4Px5/vSX+Mi9KJDXMnrPpnPxTwMV06PkcRvwrmQYtE90sw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728361773; a=rsa-sha256; cv=none; b=hl+EbBecsozXNhRzp5cBEaG9z8BZeXRoX23tSJXVm3IIY7MHG6IAgqnLh54D8NnRrqVnB5 SOp5MpVKii8MN6NlM5YyB+5oVUQffuVWaPNN59SkaNwmxWir2WGGwnxPX9MhucJGXjGSrv FRfpb0T5f2cn0RTyhSGv2tnlR+8NmUdYSQTyyOiv9o8Z2VaYDGoFjjIcq3VOJNec5QekSM ZqtIhP2dwvr7gCoJI5USbkcBPBM2cF9mF5uNlOCeAetPicXlgJZZIwy1sBLAxgcmsa9eLM zf8dLnTGxT8lCjp1z8bLl/wq81GQnFcbqRunDLLFICX7xu5hWw3bEizfCUtVZg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XN32P3TKfzG3d; Tue, 8 Oct 2024 04:29:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4984TX0R079647; Tue, 8 Oct 2024 04:29:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4984TXnM079644; Tue, 8 Oct 2024 04:29:33 GMT (envelope-from git) Date: Tue, 8 Oct 2024 04:29:33 GMT Message-Id: <202410080429.4984TXnM079644@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ka Ho Ng Subject: git: 0a2cfd653e86 - main - libkldelf: add a private library for kernel/kld-related ELF parsing List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0a2cfd653e86ac41c4e6e32a449d133c0ee6d677 Auto-Submitted: auto-generated The branch main has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=0a2cfd653e86ac41c4e6e32a449d133c0ee6d677 commit 0a2cfd653e86ac41c4e6e32a449d133c0ee6d677 Author: Ka Ho Ng AuthorDate: 2024-10-08 04:24:07 +0000 Commit: Ka Ho Ng CommitDate: 2024-10-08 04:24:07 +0000 libkldelf: add a private library for kernel/kld-related ELF parsing 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 --- Makefile.inc1 | 11 +++++++++-- lib/Makefile | 1 + lib/libkldelf/Makefile | 21 +++++++++++++++++++++ lib/libkldelf/Makefile.depend | 16 ++++++++++++++++ {usr.sbin/kldxref => lib/libkldelf}/ef.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_aarch64.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_amd64.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_arm.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_i386.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_mips.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_obj.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_powerpc.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/ef_riscv.c | 2 +- {usr.sbin/kldxref => lib/libkldelf}/elf.c | 2 +- usr.sbin/kldxref/ef.h => lib/libkldelf/kldelf.h | 6 +++--- share/mk/src.libnames.mk | 2 ++ usr.sbin/kldxref/Makefile | 13 ++++--------- usr.sbin/kldxref/kldxref.c | 2 +- 18 files changed, 67 insertions(+), 25 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 557bbc825625..118e864b69b8 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -2509,8 +2509,12 @@ ${_bt}-lib/libdwarf: ${_bt_m4_depend} _bt_libelf_depend=${_bt}-lib/libelf .endif +_libkldelf= lib/libkldelf +${_bt}-lib/libkldelf: ${_bt_libelf_depend} +_bt_libkldelf_depend=${_bt}-lib/libkldelf + _kldxref= usr.sbin/kldxref -${_bt}-usr.sbin/kldxref: ${_bt_libelf_depend} +${_bt}-usr.sbin/kldxref: ${_bt_libelf_depend} ${_bt_libkldelf_depend} # flua is required to regenerate syscall files. It first appeared during the # 13.0-CURRENT cycle, thus needs to be built on -older releases and stable @@ -2773,6 +2777,7 @@ bootstrap-tools: ${_bt}-links .PHONY ${_cat} \ ${_kbdcontrol} \ ${_elftoolchain_libs} \ + ${_libkldelf} \ ${_kldxref} \ lib/libopenbsd \ usr.bin/mandoc \ @@ -3216,7 +3221,8 @@ _prebuild_libs= ${_kerberos5_lib_libasn1} \ lib/libfigpar \ ${_lib_libgssapi} \ lib/libjail \ - lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \ + lib/libkiconv lib/libkldelf lib/libkvm \ + lib/liblzma lib/libmd lib/libnv \ lib/libzstd \ ${_lib_casper} \ lib/ncurses/tinfo \ @@ -3251,6 +3257,7 @@ _prebuild_libs+= lib/libregex .endif lib/libgeom__L: lib/libexpat__L lib/libsbuf__L +lib/libkldelf__L: lib/libelf__L lib/libkvm__L: lib/libelf__L .if ${MK_RADIUS_SUPPORT} != "no" diff --git a/lib/Makefile b/lib/Makefile index 221eac74ee26..e4a4aa95a1ef 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -66,6 +66,7 @@ SUBDIR= ${SUBDIR_BOOTSTRAP} \ libiscsiutil \ libjail \ libkiconv \ + libkldelf \ libkvm \ liblua \ liblzma \ diff --git a/lib/libkldelf/Makefile b/lib/libkldelf/Makefile new file mode 100644 index 000000000000..0d1716f17fca --- /dev/null +++ b/lib/libkldelf/Makefile @@ -0,0 +1,21 @@ +.include + +PACKAGE= runtime +LIB= kldelf +PRIVATELIB= yes + +SRCS= ef.c \ + ef_obj.c \ + elf.c \ + ef_aarch64.c \ + ef_arm.c \ + ef_amd64.c \ + ef_i386.c \ + ef_mips.c \ + ef_powerpc.c \ + ef_riscv.c +WARNS?= 2 + +LIBADD= elf + +.include diff --git a/lib/libkldelf/Makefile.depend b/lib/libkldelf/Makefile.depend new file mode 100644 index 000000000000..b0aa274151ad --- /dev/null +++ b/lib/libkldelf/Makefile.depend @@ -0,0 +1,16 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + include/xlocale \ + lib/${CSU_DIR} \ + lib/libc \ + lib/libcompiler_rt \ + lib/libelf \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/usr.sbin/kldxref/ef.c b/lib/libkldelf/ef.c similarity index 99% rename from usr.sbin/kldxref/ef.c rename to lib/libkldelf/ef.c index 975626e46046..052798ee31e4 100644 --- a/usr.sbin/kldxref/ef.c +++ b/lib/libkldelf/ef.c @@ -41,7 +41,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" #define MAXSEGS 16 struct ef_file { diff --git a/usr.sbin/kldxref/ef_aarch64.c b/lib/libkldelf/ef_aarch64.c similarity index 99% rename from usr.sbin/kldxref/ef_aarch64.c rename to lib/libkldelf/ef_aarch64.c index b61de3b032ab..d2db29f22891 100644 --- a/usr.sbin/kldxref/ef_aarch64.c +++ b/lib/libkldelf/ef_aarch64.c @@ -31,7 +31,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/ef_amd64.c b/lib/libkldelf/ef_amd64.c similarity index 99% rename from usr.sbin/kldxref/ef_amd64.c rename to lib/libkldelf/ef_amd64.c index fde032dcabc2..7295835f75b3 100644 --- a/usr.sbin/kldxref/ef_amd64.c +++ b/lib/libkldelf/ef_amd64.c @@ -33,7 +33,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/ef_arm.c b/lib/libkldelf/ef_arm.c similarity index 99% rename from usr.sbin/kldxref/ef_arm.c rename to lib/libkldelf/ef_arm.c index cc5e265f821e..657294dc9fb0 100644 --- a/usr.sbin/kldxref/ef_arm.c +++ b/lib/libkldelf/ef_arm.c @@ -34,7 +34,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/ef_i386.c b/lib/libkldelf/ef_i386.c similarity index 99% rename from usr.sbin/kldxref/ef_i386.c rename to lib/libkldelf/ef_i386.c index 962ed2bc0664..ae571e2d50f2 100644 --- a/usr.sbin/kldxref/ef_i386.c +++ b/lib/libkldelf/ef_i386.c @@ -33,7 +33,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/ef_mips.c b/lib/libkldelf/ef_mips.c similarity index 99% rename from usr.sbin/kldxref/ef_mips.c rename to lib/libkldelf/ef_mips.c index e4aeedb5c08b..99790e11a9c3 100644 --- a/usr.sbin/kldxref/ef_mips.c +++ b/lib/libkldelf/ef_mips.c @@ -36,7 +36,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/ef_obj.c b/lib/libkldelf/ef_obj.c similarity index 99% rename from usr.sbin/kldxref/ef_obj.c rename to lib/libkldelf/ef_obj.c index ac83137cd394..e09bd036b71e 100644 --- a/usr.sbin/kldxref/ef_obj.c +++ b/lib/libkldelf/ef_obj.c @@ -43,7 +43,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" typedef struct { GElf_Addr addr; diff --git a/usr.sbin/kldxref/ef_powerpc.c b/lib/libkldelf/ef_powerpc.c similarity index 99% rename from usr.sbin/kldxref/ef_powerpc.c rename to lib/libkldelf/ef_powerpc.c index f72cc1d85e20..33f09c0d69ef 100644 --- a/usr.sbin/kldxref/ef_powerpc.c +++ b/lib/libkldelf/ef_powerpc.c @@ -33,7 +33,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/ef_riscv.c b/lib/libkldelf/ef_riscv.c similarity index 99% rename from usr.sbin/kldxref/ef_riscv.c rename to lib/libkldelf/ef_riscv.c index 46b9b66bee58..bda04bb2c39a 100644 --- a/usr.sbin/kldxref/ef_riscv.c +++ b/lib/libkldelf/ef_riscv.c @@ -36,7 +36,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" /* * Apply relocations to the values obtained from the file. `relbase' is the diff --git a/usr.sbin/kldxref/elf.c b/lib/libkldelf/elf.c similarity index 99% rename from usr.sbin/kldxref/elf.c rename to lib/libkldelf/elf.c index f98c39b69c0b..da319ffc6c98 100644 --- a/usr.sbin/kldxref/elf.c +++ b/lib/libkldelf/elf.c @@ -44,7 +44,7 @@ #include #include -#include "ef.h" +#include "kldelf.h" SET_DECLARE(elf_reloc, struct elf_reloc_data); diff --git a/usr.sbin/kldxref/ef.h b/lib/libkldelf/kldelf.h similarity index 99% rename from usr.sbin/kldxref/ef.h rename to lib/libkldelf/kldelf.h index 9d3dc1b1b435..e0a8cc627ff2 100644 --- a/usr.sbin/kldxref/ef.h +++ b/lib/libkldelf/kldelf.h @@ -32,8 +32,8 @@ * SUCH DAMAGE. */ -#ifndef _EF_H_ -#define _EF_H_ +#ifndef _KLDELF_H_ +#define _KLDELF_H_ #include #include @@ -312,4 +312,4 @@ int elf_reloc(struct elf_file *ef, const void *reldata, Elf_Type reltype, __END_DECLS -#endif /* _EF_H_*/ +#endif /* _KLDELF_H_*/ diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk index 1e0a04e83fe3..092e1b444beb 100644 --- a/share/mk/src.libnames.mk +++ b/share/mk/src.libnames.mk @@ -27,6 +27,7 @@ _PRIVATELIBS= \ gtest_main \ heimipcc \ heimipcs \ + kldelf \ ldns \ sqlite3 \ ssh \ @@ -312,6 +313,7 @@ _DP_bsnmp= crypto .endif _DP_geom= bsdxml sbuf _DP_cam= sbuf +_DP_kldelf= elf _DP_kvm= elf _DP_casper= nv _DP_cap_dns= nv diff --git a/usr.sbin/kldxref/Makefile b/usr.sbin/kldxref/Makefile index fc9b0b4215fc..c41517a78904 100644 --- a/usr.sbin/kldxref/Makefile +++ b/usr.sbin/kldxref/Makefile @@ -1,17 +1,12 @@ PACKAGE= runtime PROG= kldxref MAN= kldxref.8 -SRCS= kldxref.c ef.c ef_obj.c elf.c -SRCS+= ef_aarch64.c \ - ef_arm.c \ - ef_amd64.c \ - ef_i386.c \ - ef_mips.c \ - ef_powerpc.c \ - ef_riscv.c +SRCS= kldxref.c + +CFLAGS+=-I${SRCTOP}/lib/libkldelf WARNS?= 2 -LIBADD= elf +LIBADD= elf kldelf .include diff --git a/usr.sbin/kldxref/kldxref.c b/usr.sbin/kldxref/kldxref.c index 6bb0469a9ff5..eed754e1e730 100644 --- a/usr.sbin/kldxref/kldxref.c +++ b/usr.sbin/kldxref/kldxref.c @@ -51,7 +51,7 @@ #include #include -#include "ef.h" +#include #define MAXRECSIZE (64 << 10) /* 64k */ #define check(val) if ((error = (val)) != 0) break