From nobody Mon Mar 07 15:43:27 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 8BE7A19F0725; Mon, 7 Mar 2022 15:43:27 +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 4KC2mb2lN8z3qZs; Mon, 7 Mar 2022 15:43:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646667807; 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=VaPAaLBcULMkA08NcWiURC3pIRW6t4Qrcr42j0h/2u8=; b=cUZoMvGVmXJs2k4NCB0MhKxHd2Bc8zcy0eQeItAM89NaIk+4d1Qu1hHva0B27zaH93ExlJ eTDA6rk3ZqKBVo4JXu3haRu7VX8MI0UL+qyGgV45jhDHr7ur3XhmRun0+joDLmICulAYkz 33mIrtnwltomDEdPYEUCZQZYLIKsqT8IuJADdHVY1MFaC0knGaSQQxzKOI2G/jKlcEOKdB OgKF11Int8RWB9swetYPiRjH294qHFFdEpF5Ub5VDTuklXZor96dEFhvIv3l06TG5D777a kAUsZDLbTVhz/MHFZl48DAfizM9uU5hSyMPZMYiXNOhG8j50/ZmHHVq+nrT09w== 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 2D60925F6; Mon, 7 Mar 2022 15:43:27 +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 227FhRI2048295; Mon, 7 Mar 2022 15:43:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 227FhRtU048294; Mon, 7 Mar 2022 15:43:27 GMT (envelope-from git) Date: Mon, 7 Mar 2022 15:43:27 GMT Message-Id: <202203071543.227FhRtU048294@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: cab9382a2cdf - main - 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/main X-Git-Reftype: branch X-Git-Commit: cab9382a2cdf88b3027370cbdf73b095598eb7c1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646667807; 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=VaPAaLBcULMkA08NcWiURC3pIRW6t4Qrcr42j0h/2u8=; b=QqKeOSIrZc17aNttxIG5KukGqfjO2axKrp0KHEE5UUZWD3Q59JrvMe/mtkh/XAKK5MhifN LWPgqV3y7IEprsIhbaYwjym5C4ZnQRLki+X4xg8MixdwggxS8HV2XQjQvY0sPhQ1OLDdm7 dkpTdYdjMNPmKCEgBhXkCimStZmebs/4A2SStA4oM3Ilnv37xt4HxntbxK9CjplD9pXBVK 3GENlivmcbecg+ZRrAV0qPjAyLPNqzSS2WJ4VLW1nDqFm41oPi2yYjo63s1kAFDnktaX02 E8XdtjvxiGZfXkiZrlvM5xLZjMhyF99CITKjthZGKTaA37fQXXuc7+pLx8sjQw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646667807; a=rsa-sha256; cv=none; b=Enu3uyqkV0ol4O2qz63xWOG4lj+XOVltJu3FpCcgPgNT2tIwB9+ei8IKKaf6HA4G03Nge7 IDY0iFnbKl61zBaSn7HiQmj8tewyKqFP5OQQhe6Ce9Nzwte5AeUSyiEr5M5PlDZQ4ZsvdM b5TOQUA/tjMoeb+s/hP8pSyJL9bjfiYFs2BLJ4UP9PfQFpcHycDr+sB2pSnfqM1+V4hZbj baV9epsVxtaXhhHvC9CYHqh7GI/FxNfSBTGTE3E3Y6nbeIUPhkAheHix1XuCNMdWSMVlpZ R+4ugW+WLDnf/RCxj+k4ArMX5FHI9JgU+uxrw12cWBhSmnQcWj1/+GzLoXN5SQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cab9382a2cdf88b3027370cbdf73b095598eb7c1 commit cab9382a2cdf88b3027370cbdf73b095598eb7c1 Author: Mark Johnston AuthorDate: 2022-03-07 13:43:42 +0000 Commit: Mark Johnston CommitDate: 2022-03-07 15:43:18 +0000 linker: Simplify CTF container handling Use sys/ctf.h to provide various definitions required to parse the CTF header. No functional change intended. Reviewed by: Domagoj Stolfa, emaste MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34359 --- 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 bd2186693f0b..e9a4f98a98dc 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; }