From nobody Wed Jul 2 18:25:53 2025 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 4bXSyF1nqPz60lr8; Wed, 02 Jul 2025 18:25:57 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from omta004.cacentral1.a.cloudfilter.net (omta002.cacentral1.a.cloudfilter.net [3.97.99.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bXSyD4cdxz3GdM; Wed, 02 Jul 2025 18:25:56 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of cy.schubert@cschubert.com designates 3.97.99.33 as permitted sender) smtp.mailfrom=cy.schubert@cschubert.com; dmarc=permerror reason="p tag has invalid value: quarantine rua=mailto:p[ostmaster@cschubert.com" header.from=cschubert.com (policy=permerror) Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTPS id X1ywucVG85MqyX29buX4R3; Wed, 02 Jul 2025 18:25:55 +0000 Received: from spqr.komquats.com ([70.66.136.217]) by cmsmtp with ESMTPSA id X29auNoocJhBPX29buCVlP; Wed, 02 Jul 2025 18:25:55 +0000 X-Auth-User: cschuber X-Authority-Analysis: v=2.4 cv=QY3Fvdbv c=1 sm=1 tr=0 ts=686579b3 a=h7br+8Ma+Xn9xscxy5znUg==:117 a=h7br+8Ma+Xn9xscxy5znUg==:17 a=kj9zAlcOel0A:10 a=Wb1JkmetP80A:10 a=6I5d2MoRAAAA:8 a=EkcXrb_YAAAA:8 a=YxBL1-UpAAAA:8 a=c5oBaWCnqlhLl9_hoNcA:9 a=CjuIK1q_8ugA:10 a=LK5xJRSDVpKd5WXXoEvA:22 a=Ia-lj3WSrqcvXOmTRaiG:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTP id 17D737F; Wed, 02 Jul 2025 11:25:54 -0700 (PDT) Received: by slippy.cwsent.com (Postfix, from userid 1000) id F0431281; Wed, 02 Jul 2025 11:25:53 -0700 (PDT) X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.8+dev Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Mark Johnston cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: aefae931820f - main - linker: Improve handling of ifuncs when fetching symbol metadata Comments: In-reply-to Cy Schubert message dated "Wed, 02 Jul 2025 11:19:00 -0700." 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=us-ascii Date: Wed, 02 Jul 2025 11:25:53 -0700 Message-Id: <20250702182553.F0431281@slippy.cwsent.com> X-CMAE-Envelope: MS4xfE7QseIP9fyypDmiLgW3m33H7FyI6h56sY6Q6eNz/mcAJLWD7WlqjBwFEzRYMqwzeOwAy/5EVFRa/1BdO5E6A7N6BMWc2Va+9/GQPKww6FGod15fGENH zF1tBBBnkUflBZnxdicfphXCYxYtqK10T/ja/UsAoJ9ZWlMFoqjB5vKiw5Vqu1ccjFPJ6i7Aoa5IBtzaKNSZMHkvcJAxo4IjmLFtpSJAt4H/hOR/Z4vA29sn z7KgQsP2eTrnAnfx0vUlZxZ+dsSwzOFKYis5aJXR7s6Cx+k+01LSN/qZjIQO3DfTsuoOFdjrnH8DSsZP9Qa36oCP7cvNiEnjpGH7PvphauQ= X-Spamd-Result: default: False [2.25 / 15.00]; FAKE_REPLY(1.00)[]; NEURAL_SPAM_LONG(0.99)[0.994]; NEURAL_SPAM_MEDIUM(0.94)[0.936]; NEURAL_HAM_SHORT(-0.78)[-0.779]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:3.97.99.32/31]; RCVD_IN_DNSWL_LOW(-0.10)[3.97.99.33:from]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:16509, ipnet:3.96.0.0/15, country:US]; RCVD_COUNT_THREE(0.00)[4]; R_DKIM_NA(0.00)[]; HAS_REPLYTO(0.00)[Cy.Schubert@cschubert.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DMARC_BAD_POLICY(0.00)[cschubert.com : p tag has invalid value: quarantine rua=mailto:p[ostmaster@cschubert.com]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-main@freebsd.org,dev-commits-src-all@freebsd.org]; REPLYTO_EQ_FROM(0.00)[] X-Rspamd-Queue-Id: 4bXSyD4cdxz3GdM X-Spamd-Bar: ++ Cy Schubert writes: > In message <202507021341.562DfuEh023668@gitrepo.freebsd.org>, Mark Johnston > wri > tes: > > The branch main has been updated by markj: > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=aefae931820fe1e93a318552968510 > 29 > > 8c7941a0 > > > > commit aefae931820fe1e93a318552968510298c7941a0 > > Author: Mark Johnston > > AuthorDate: 2025-07-02 13:34:47 +0000 > > Commit: Mark Johnston > > CommitDate: 2025-07-02 13:34:47 +0000 > > > > linker: Improve handling of ifuncs when fetching symbol metadata > > > > When looking up symbol values, we map ifunc symbols to the value > > returned by the resolver. However, the returned symbol size is still > > that of the resolver. Be consistent and provide the size of the > > implementation symbol as well. > > > > This fixes an inconsistency in dtrace's FBT provider, which enumerates > > all function symbols and disassembles their values, using the symbol > > size as the bound for the disassembly loop. In particular, for ifuncs, > > we were not creating return probes. > > > > Reviewed by: kib > > MFC after: 2 weeks > > Sponsored by: Innovate UK > > Differential Revision: https://reviews.freebsd.org/D50683 > > --- > > sys/kern/link_elf.c | 38 ++++++++++++++++++++++++++++++++++---- > > sys/kern/link_elf_obj.c | 31 +++++++++++++++++++++++++++++-- > > 2 files changed, 63 insertions(+), 6 deletions(-) > > > > diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c > > index 53af1e164980..bbebadc4c395 100644 > > --- a/sys/kern/link_elf.c > > +++ b/sys/kern/link_elf.c > > @@ -1628,6 +1628,30 @@ link_elf_lookup_debug_symbol_ctf(linker_file_t lf, c > on > > st char *name, > > return (i < ef->ddbsymcnt ? link_elf_ctf_get_ddb(lf, lc) : ENOENT); > > } > > > > +static void > > +link_elf_ifunc_symbol_value(linker_file_t lf, caddr_t *valp, size_t *sizep > ) > > +{ > > + c_linker_sym_t sym; > > + elf_file_t ef; > > + const Elf_Sym *es; > > + caddr_t val; > > + long off; > > + > > + val = *valp; > > + ef = (elf_file_t)lf; > > + > > + /* Provide the value and size of the target symbol, if available. */ > > + val = ((caddr_t (*)(void))val)(); > > + if (link_elf_search_symbol(lf, val, &sym, &off) == 0 && off == 0) { > > + es = (const Elf_Sym *)sym; > > + *valp = (caddr_t)ef->address + es->st_value; > > + *sizep = es->st_size; > > + } else { > > + *valp = val; > > + *sizep = 0; > > + } > > +} > > + > > static int > > link_elf_symbol_values1(linker_file_t lf, c_linker_sym_t sym, > > linker_symval_t *symval, bool see_local) > > @@ -1635,6 +1659,7 @@ link_elf_symbol_values1(linker_file_t lf, c_linker_sy > m_ > > t sym, > > elf_file_t ef; > > const Elf_Sym *es; > > caddr_t val; > > + size_t size; > > > > ef = (elf_file_t)lf; > > es = (const Elf_Sym *)sym; > > @@ -1644,9 +1669,11 @@ link_elf_symbol_values1(linker_file_t lf, c_linker_s > ym > > _t sym, > > symval->name = ef->strtab + es->st_name; > > val = (caddr_t)ef->address + es->st_value; > > if (ELF_ST_TYPE(es->st_info) == STT_GNU_IFUNC) > > - val = ((caddr_t (*)(void))val)(); > > + link_elf_ifunc_symbol_value(lf, &val, &size); > > + else > > + size = es->st_size; > > symval->value = val; > > - symval->size = es->st_size; > > + symval->size = size; > > return (0); > > } > > return (ENOENT); > > @@ -1668,6 +1695,7 @@ link_elf_debug_symbol_values(linker_file_t lf, c_link > er > > _sym_t sym, > > elf_file_t ef = (elf_file_t)lf; > > const Elf_Sym *es = (const Elf_Sym *)sym; > > caddr_t val; > > + size_t size; > > > > if (link_elf_symbol_values1(lf, sym, symval, true) == 0) > > return (0); > > @@ -1678,9 +1706,11 @@ link_elf_debug_symbol_values(linker_file_t lf, c_lin > ke > > r_sym_t sym, > > symval->name = ef->ddbstrtab + es->st_name; > > val = (caddr_t)ef->address + es->st_value; > > if (ELF_ST_TYPE(es->st_info) == STT_GNU_IFUNC) > > - val = ((caddr_t (*)(void))val)(); > > + link_elf_ifunc_symbol_value(lf, &val, &size); > > + else > > + size = es->st_size; > > symval->value = val; > > - symval->size = es->st_size; > > + symval->size = size; > > return (0); > > } > > return (ENOENT); > > diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c > > index 02fd4caffcd9..3d18aed2b1c0 100644 > > --- a/sys/kern/link_elf_obj.c > > +++ b/sys/kern/link_elf_obj.c > > @@ -1510,6 +1510,30 @@ link_elf_lookup_debug_symbol_ctf(linker_file_t lf, c > on > > st char *name, > > return (link_elf_ctf_get_ddb(lf, lc)); > > } > > > > +static void > > +link_elf_ifunc_symbol_value(linker_file_t lf, caddr_t *valp, size_t *sizep > ) > > +{ > > + c_linker_sym_t sym; > > + elf_file_t ef; > > + const Elf_Sym *es; > > + caddr_t val; > > + long off; > > + > > + val = *valp; > > + ef = (elf_file_t)lf; > > + > > + /* Provide the value and size of the target symbol, if available. */ > > + val = ((caddr_t (*)(void))val)(); > > + if (link_elf_search_symbol(lf, val, &sym, &off) == 0 && off == 0) { > > + es = (const Elf_Sym *)sym; > > + *valp = (caddr_t)ef->address + es->st_value; > > + *sizep = es->st_size; > > + } else { > > + *valp = val; > > + *sizep = 0; > > + } > > +} > > + > > static int > > link_elf_symbol_values1(linker_file_t lf, c_linker_sym_t sym, > > linker_symval_t *symval, bool see_local) > > @@ -1517,6 +1541,7 @@ link_elf_symbol_values1(linker_file_t lf, c_linker_sy > m_ > > t sym, > > elf_file_t ef; > > const Elf_Sym *es; > > caddr_t val; > > + size_t size; > > > > ef = (elf_file_t) lf; > > es = (const Elf_Sym*) sym; > > @@ -1527,9 +1552,11 @@ link_elf_symbol_values1(linker_file_t lf, c_linker_s > ym > > _t sym, > > symval->name = ef->ddbstrtab + es->st_name; > > val = (caddr_t)es->st_value; > > if (ELF_ST_TYPE(es->st_info) == STT_GNU_IFUNC) > > - val = ((caddr_t (*)(void))val)(); > > + link_elf_ifunc_symbol_value(lf, &val, &size); > > + else > > + size = es->st_size; > > symval->value = val; > > - symval->size = es->st_size; > > + symval->size = size; > > return (0); > > } > > return (ENOENT); > > > > This commit may have caused a panic loading linux.ko. > > #0 __curthread () at /opt/src/git-src/sys/amd64/include/pcpu_aux.h:57 > #1 doadump (textdump=textdump@entry=1) > at /opt/src/git-src/sys/kern/kern_shutdown.c:399 > #2 0xffffffff806fad1e in kern_reboot (howto=260) > at /opt/src/git-src/sys/kern/kern_shutdown.c:519 > #3 0xffffffff806fb247 in vpanic (fmt=0xffffffff80b2e000 "%s", > ap=ap@entry=0xfffffe008c8e2450) > at /opt/src/git-src/sys/kern/kern_shutdown.c:974 > #4 0xffffffff806fb073 in panic (fmt=) > at /opt/src/git-src/sys/kern/kern_shutdown.c:887 > #5 0xffffffff80aa8e7a in trap_fatal (frame=, > eva=) at /opt/src/git-src/sys/amd64/amd64/trap.c:974 > #6 0xffffffff80aa8e7a in trap_pfault (frame=0xfffffe008c8e24d0, > usermode=false, signo=, ucode=) > #7 > #8 fbt_provide_module_function (lf=lf@entry=0xfffff80126035900, > symindx=symindx@entry=753, symval=symval@entry=0xfffffe008c8e25f0, > opaque=opaque@entry=0xfffffe008c8e2640) > at /opt/src/git-src/sys/cddl/dev/fbt/x86/fbt_isa.c:205 > #9 0xffffffff80ac870d in link_elf_each_function_nameval ( > file=0xfffff80126035900, > callback=0xffffffff81d916a0 , > opaque=0xfffffe008c8e2640) at /opt/src/git-src/sys/kern/link_elf_obj.c:1 > 685 > --Type for more, q to quit, c to continue without paging--c > #10 0xffffffff81d9035f in fbt_provide_module (arg=, > lf=0xfffff80126035900) at /opt/src/git-src/sys/cddl/dev/fbt/fbt.c:221 > #11 0xffffffff81cc87fb in dtrace_module_loaded (ctl=0xfffff80126035900) > at /opt/src/git-src/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrac > e.c:16709 > #12 dtrace_kld_load (arg=, lf=0xfffff80126035900) > at /opt/src/git-src/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrac > e.c:16894 > #13 0xffffffff806c4ecb in linker_load_file ( > filename=0xfffff80054e6d500 "/boot/kernel/linux.ko", > result=) at /opt/src/git-src/sys/kern/kern_linker.c:518 > #14 linker_load_module (kldname=kldname@entry=0x0, > modname=0xfffff8005437c800 "linux", parent=parent@entry=0x0, > verinfo=verinfo@entry=0x0, lfpp=lfpp@entry=0xfffffe008c8e2da0) > at /opt/src/git-src/sys/kern/kern_linker.c:2292 > #15 0xffffffff806c69f5 in kern_kldload (td=td@entry=0xfffff8005ce3c780, > file=file@entry=0xfffff8005437c800 "linux", > fileid=fileid@entry=0xfffffe008c8e2de4) > at /opt/src/git-src/sys/kern/kern_linker.c:1236 > #16 0xffffffff806c6b09 in sys_kldload (td=0xfffff8005ce3c780, > uap=0xfffff8005ce3cba8) at /opt/src/git-src/sys/kern/kern_linker.c:1259 > #17 0xffffffff80aa97d6 in syscallenter (td=0xfffff8005ce3c780) > at /opt/src/git-src/sys/amd64/amd64/../../kern/subr_syscall.c:193 > #18 amd64_syscall (td=0xfffff8005ce3c780, traced=0) > at /opt/src/git-src/sys/amd64/amd64/trap.c:1215 > #19 > #20 0x00000ce63ecf8c3a in ?? () Confirmed. kldload linux causes the panic. -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org e**(i*pi)+1=0