From nobody Mon Apr 18 16:39:26 2022 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 C1D1011D4257; Mon, 18 Apr 2022 16:39:26 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kht1p4c5qz4v5k; Mon, 18 Apr 2022 16:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650299966; 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=1dXQrw0wePXPfXsiWG4JkL5a5hh4F3cdh3x+ssfLhb0=; b=HU5CDT1Q7dzCczO320CTP/5/MS+uoDCZtOeL7F+rVq+4+dSyVc3Kw1XuxVkFxNi/TVabdM iMEvZsyEW4KDNK3H8JW0DA7jwQtbpWJ3PySjlOaZerCwYbuPOrwcgFH3byEkNgIiEN2r5t ATynJwnZieiFRXOdH30oFuKrvQt3DuypqTyTKsTrk8MmIw+y8IHJYiUlASh0AZVEJ0MV2t WkmZ5CvrAwCIYRuLEWC+WDNBkUooDEAmLkvv6acRbNvFOE5Tdn6gqDEUMwM4wxDsPUgaHa i8e3rOEvvrJObSq4dUhJro/6hVyJ2PvMk164W9IWJiITfhJ2ZxepFFh544/cGw== 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 7684216459; Mon, 18 Apr 2022 16:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23IGdQeR085730; Mon, 18 Apr 2022 16:39:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23IGdQgb085729; Mon, 18 Apr 2022 16:39:26 GMT (envelope-from git) Date: Mon, 18 Apr 2022 16:39:26 GMT Message-Id: <202204181639.23IGdQgb085729@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 30700bc80e8e - releng/13.1 - linker: Simplify CTF container handling 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 30700bc80e8e156672acec9f880b09825a1ebb05 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650299966; 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=1dXQrw0wePXPfXsiWG4JkL5a5hh4F3cdh3x+ssfLhb0=; b=BQIOYct5AlKbKUHOJ9aZA9X0QEAMwjsYBgtOBwR5RRJpyWQXKnCV+5sHc4DXozGLAWHIST azOb4y5WnNt8xuyRU/Gv4vC4gIeZI6BlkptAh82JVpM/P9+imvGRGHT3uuygrtNs2qinme +mfRR/HmcvOxe9SlXwKgBhIwmEHfheeb+Qk9tZc+/d0fKsZhUR8FWnhoco+4Hnby+ogH1r Qg61m7kE8VCCB2DS0PY3SwzZZIlGKd2AG0Y3HWe9bKuBXaWHKQ/orusfj0OPYfh3MkEj1y fDfegASIEg8FVnDSancCa6w9N7sruFrttaEnTbZ9T2Hxr4HmsvB/jEFgAnQnpw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650299966; a=rsa-sha256; cv=none; b=BxIxk2u91IsWUwv7QCXZdxQyn1aaFTwg5fBXjJS+Lk+B3sOubOouApZQBHNvZtlavFAmXF VHcFnd7geT3Jxti2imT6SVHaBgzD8kEjMIbmN9vOfG0KIN39VuefsVxxh1aSpGEK2avdzF Qy6U6pUDc65Bm1vtbbn0bqqNLOOboTuN8yOvmCjEp5BuRvJFcA3+TZkQegCcpoT73VGBGi kTggcrjesTd2bMkPF1ksROS5BoKRK0e8gA+fEJxhJSaeltKgF+wm+t83uDiUbUW5NzQEfR Op8+YjTDbqjfmUWK1UIvg8Gve2FcRw75XumrkkdHwhAOwnV7vgk9ihd5V6nTSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=30700bc80e8e156672acec9f880b09825a1ebb05 commit 30700bc80e8e156672acec9f880b09825a1ebb05 Author: Mark Johnston AuthorDate: 2022-03-07 13:43:42 +0000 Commit: Mark Johnston CommitDate: 2022-04-18 16:38:14 +0000 linker: Simplify CTF container handling Use sys/ctf.h to provide various definitions required to parse the CTF header. No functional change intended. Approved by: re (gjb) Reviewed by: Domagoj Stolfa, emaste Sponsored by: The FreeBSD Foundation (cherry picked from commit cab9382a2cdf88b3027370cbdf73b095598eb7c1) (cherry picked from commit 24597a09b946ccaec4c7e43eae45c81b21d247a3) --- sys/kern/kern_ctf.c | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/sys/kern/kern_ctf.c b/sys/kern/kern_ctf.c index ee7576ab6fb9..55e73b78c8ed 100644 --- a/sys/kern/kern_ctf.c +++ b/sys/kern/kern_ctf.c @@ -28,16 +28,11 @@ * $FreeBSD$ */ +#include + /* * Note this file is included by both link_elf.c and link_elf_obj.c. - * - * The CTF header structure definition can't be used here because it's - * (annoyingly) covered by the CDDL. We will just use a few bytes from - * it as an integer array where we 'know' what they mean. */ -#define CTF_HDR_SIZE 36 -#define CTF_HDR_STRTAB_U32 7 -#define CTF_HDR_STRLEN_U32 8 #ifdef DDB_CTF #include @@ -59,7 +54,7 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) size_t sz; struct nameidata nd; struct thread *td = curthread; - uint8_t ctf_hdr[CTF_HDR_SIZE]; + struct ctf_header cth; #endif int error = 0; @@ -174,17 +169,13 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) } /* Read the CTF header. */ - if ((error = vn_rdwr(UIO_READ, nd.ni_vp, ctf_hdr, sizeof(ctf_hdr), + if ((error = vn_rdwr(UIO_READ, nd.ni_vp, &cth, sizeof(cth), shdr[i].sh_offset, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, NULL, td)) != 0) goto out; /* Check the CTF magic number. */ -#ifdef __LITTLE_ENDIAN__ - if (ctf_hdr[0] != 0xf1 || ctf_hdr[1] != 0xcf) { -#else - if (ctf_hdr[0] != 0xcf || ctf_hdr[1] != 0xf1) { -#endif + if (cth.cth_magic != CTF_MAGIC) { printf("%s(%d): module %s has invalid format\n", __func__, __LINE__, lf->pathname); error = EFTYPE; @@ -192,27 +183,24 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) } /* Check if version 2. */ - if (ctf_hdr[2] != 2) { + if (cth.cth_version != CTF_VERSION_2) { printf("%s(%d): module %s CTF format version is %d " "(2 expected)\n", - __func__, __LINE__, lf->pathname, ctf_hdr[2]); + __func__, __LINE__, lf->pathname, cth.cth_version); error = EFTYPE; goto out; } /* Check if the data is compressed. */ - if ((ctf_hdr[3] & 0x1) != 0) { - uint32_t *u32 = (uint32_t *) ctf_hdr; - + if ((cth.cth_flags & CTF_F_COMPRESS) != 0) { /* * The last two fields in the CTF header are the offset * from the end of the header to the start of the string - * data and the length of that string data. se this + * data and the length of that string data. Use this * information to determine the decompressed CTF data * buffer required. */ - sz = u32[CTF_HDR_STRTAB_U32] + u32[CTF_HDR_STRLEN_U32] + - sizeof(ctf_hdr); + sz = cth.cth_stroff + cth.cth_strlen + sizeof(cth); /* * Allocate memory for the compressed CTF data, including @@ -251,14 +239,14 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) * The header isn't compressed, so copy that into the * CTF buffer first. */ - bcopy(ctf_hdr, ctftab, sizeof(ctf_hdr)); + bcopy(&cth, ctftab, sizeof(cth)); - destlen = sz - sizeof(ctf_hdr); - ret = uncompress(((uint8_t *) ctftab) + sizeof(ctf_hdr), - &destlen, ((uint8_t *) raw) + sizeof(ctf_hdr), - shdr[i].sh_size - sizeof(ctf_hdr)); + destlen = sz - sizeof(cth); + ret = uncompress(ctftab + sizeof(cth), &destlen, + raw + sizeof(cth), shdr[i].sh_size - sizeof(cth)); if (ret != Z_OK) { - printf("%s(%d): zlib uncompress returned %d\n", __func__, __LINE__, ret); + printf("%s(%d): zlib uncompress returned %d\n", + __func__, __LINE__, ret); error = EIO; goto out; }