From nobody Tue May 23 12:55:32 2023 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 4QQZ6s2ZxRz4CSM5; Tue, 23 May 2023 12:55: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QQZ6r62cbz3qYY; Tue, 23 May 2023 12:55:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684846532; 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=j9CFgrZUPS77tzXyhqocRedGamuUEe9VnLuw6vuACDw=; b=yVOIrbXypjFl8p4I1ajzRLfHR6WG7TYyCelsgqAvjZFadD/TdnS4GMXb7CExo9zPiFaR09 o+6IDcXfQ+RbQydtbvz+2NdefLd6HZo0qq9DEoGC/8eHTjkQBe8XJ4xPrVDfoTgGu6BnaD MLzRydHpdrHcB8nw8boQYxU4d7VUjclhNa/HsqXUruapaNLo0x3/g1e+rLU3i4ryZG98KK 78stjv5RVo7+UU0B1tpQryvSUdWPYaCoFzhrQEYtqCOCjeUbyu8KUlOoSCJAjih2Kj7fxa Ql0XwKtTUnPVssJXYBRnjPlvRQvxguYANjw11waKAI2taSRLu/M8wQYz7XPw1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684846532; 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=j9CFgrZUPS77tzXyhqocRedGamuUEe9VnLuw6vuACDw=; b=L7DvZkL7fD/uQfgkgNo4E7gWWCjGo+APfYmm4w/tm23/LJzAAyOhbp4Ndc7UAoW2QTUnno 0QsaXSNFV81IQqPhSgHc94/vrbkbfqg89e0XGwQj3W3vwOYDBiZ0bT0vVo4Pz7poT4g/IB j84BaQ0Hd9n9E/kv1bnP5DujjY9m07LaqfVhA1w+acfuzgbtGHPbLRzqOd2knYRnwcOAME LAKCt7vod66Qnij/6qp0vwgy5AfSh+P15PlXzgbDH+n9FfJh7IGDn1+huDF07ahdry8We/ ijF0IheDYIUCdsA0IpPLxg0WHOTHiE5BplJgAYjDUTLWaDFOiTpiqmc2n4YmnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684846532; a=rsa-sha256; cv=none; b=T3FbZO3KU91WApUgrwqBSk9/bZCc1Or3h12jsEE6rkNYZTWP8XVz5M9q8yZA7VOoGSrUqQ cGzreZr66oLNoHKzGdSejmUdJ7G7p1OmsKnMvht8iWzrJiOGzTBPzHwNg2AiwePHilsdWg AkpeoZUmJfY3sa/hRnMhv3cHxxFa2AsbyJsjDoUbgkqdTvOYpZHuB736LaWMlJATV7DE0b qCCa0+J2YNceq/Br/RJfrCUHrtI9HBfFdjqjqru0M3TBSL5uOWAsJutAluA0Lx+0TU5bdC w1opCP5io2iDlHY+qRi1dzpsS85LCI0uj5InaON8MPXU4cLeW4TdL4x4MRY3aw== 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 4QQZ6r5679z11DB; Tue, 23 May 2023 12:55:32 +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 34NCtWhA066881; Tue, 23 May 2023 12:55:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34NCtWsM066880; Tue, 23 May 2023 12:55:32 GMT (envelope-from git) Date: Tue, 23 May 2023 12:55:32 GMT Message-Id: <202305231255.34NCtWsM066880@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 6265da14c913 - main - libdtrace: get rid of illumos ifdefs in dt_module_update(), fix dm_file and dm_modid 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: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6265da14c913e41827aa20a096103717243a1c1b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=6265da14c913e41827aa20a096103717243a1c1b commit 6265da14c913e41827aa20a096103717243a1c1b Author: Christos Margiolis AuthorDate: 2023-05-23 12:54:58 +0000 Commit: Christos Margiolis CommitDate: 2023-05-23 12:54:58 +0000 libdtrace: get rid of illumos ifdefs in dt_module_update(), fix dm_file and dm_modid Because dt_module_update() is highly OS-specific, the ifdefs make it hard to read and follow what is going on. Also handle dm_modid, and remove handling of the ".filename" section, since we can easily fetch the filename from the module's pathname (k_stat->pathname). Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39177 --- .../opensolaris/lib/libdtrace/common/dt_module.c | 30 +++------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c index b9408944f8c5..281c787de533 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c @@ -1129,33 +1129,21 @@ dt_module_getctflib(dtrace_hdl_t *dtp, dt_module_t *dmp, const char *name) * including the path. */ static void -#ifdef illumos -dt_module_update(dtrace_hdl_t *dtp, const char *name) -#else dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) -#endif { char fname[MAXPATHLEN]; struct stat64 st; int fd, err, bits; -#ifdef __FreeBSD__ struct module_stat ms; dt_kmodule_t *dkmp; uint_t h; int modid; -#endif - dt_module_t *dmp; const char *s; size_t shstrs; GElf_Shdr sh; Elf_Data *dp; Elf_Scn *sp; - -#ifdef illumos - (void) snprintf(fname, sizeof (fname), - "%s/%s/object", OBJFS_ROOT, name); -#else GElf_Ehdr ehdr; GElf_Phdr ph; char name[MAXPATHLEN]; @@ -1165,7 +1153,6 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) (void) strlcpy(name, k_stat->name, sizeof(name)); (void) strlcpy(fname, k_stat->pathname, sizeof(fname)); -#endif if ((fd = open(fname, O_RDONLY)) == -1 || fstat64(fd, &st) == -1 || (dmp = dt_module_create(dtp, name)) == NULL) { @@ -1174,6 +1161,9 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) return; } + (void) strlcpy(dmp->dm_file, fname, sizeof(dmp->dm_file)); + dmp->dm_modid = k_stat->id; + /* * Since the module can unload out from under us (and /system/object * will return ENOENT), tell libelf to cook the entire file now and @@ -1206,7 +1196,6 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) dt_module_destroy(dtp, dmp); return; } -#if defined(__FreeBSD__) mapbase = (uintptr_t)k_stat->address; gelf_getehdr(dmp->dm_elf, &ehdr); is_elf_obj = (ehdr.e_type == ET_REL); @@ -1219,7 +1208,6 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) return; } } -#endif /* * Iterate over the section headers locating various sections of * interest and use their attributes to flesh out the dt_module_t. @@ -1228,7 +1216,6 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) if (gelf_getshdr(sp, &sh) == NULL || sh.sh_type == SHT_NULL || (s = elf_strptr(dmp->dm_elf, shstrs, sh.sh_name)) == NULL) continue; /* skip any malformed sections */ -#if defined(__FreeBSD__) if (sh.sh_size == 0) continue; if (sh.sh_type == SHT_PROGBITS || sh.sh_type == SHT_NOBITS) { @@ -1240,7 +1227,6 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) dmp->dm_sec_offsets[elf_ndxscn(sp)] = sh.sh_addr; mapbase += sh.sh_size; } -#endif if (strcmp(s, ".text") == 0) { dmp->dm_text_size = sh.sh_size; dmp->dm_text_va = sh.sh_addr; @@ -1254,17 +1240,10 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) (dp = elf_getdata(sp, NULL)) != NULL) { bcopy(dp->d_buf, &dmp->dm_info, MIN(sh.sh_size, sizeof (dmp->dm_info))); - } else if (strcmp(s, ".filename") == 0 && - (dp = elf_getdata(sp, NULL)) != NULL) { - (void) strlcpy(dmp->dm_file, - dp->d_buf, sizeof (dmp->dm_file)); } } dmp->dm_flags |= DT_DM_KERNEL; -#ifdef illumos - dmp->dm_modid = (int)OBJFS_MODID(st.st_ino); -#else /* * Include .rodata and special sections into .text. * This depends on default section layout produced by GNU ld @@ -1285,12 +1264,10 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) } } #endif -#endif /* illumos */ if (dmp->dm_info.objfs_info_primary) dmp->dm_flags |= DT_DM_PRIMARY; -#ifdef __FreeBSD__ ms.version = sizeof(ms); for (modid = kldfirstmod(k_stat->id); modid > 0; modid = modnext(modid)) { @@ -1315,7 +1292,6 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) dkmp->dkm_module = dmp; dtp->dt_kmods[h] = dkmp; } -#endif dt_dprintf("opened %d-bit module %s (%s) [%d]\n", bits, dmp->dm_name, dmp->dm_file, dmp->dm_modid);