From nobody Thu Nov 16 16:23:43 2023 X-Original-To: dev-commits-src-main@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 4SWQMd2GZkz50qBW for ; Thu, 16 Nov 2023 16:23:57 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SWQMd0QRyz3F8r for ; Thu, 16 Nov 2023 16:23:57 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5446c9f3a77so1583128a12.0 for ; Thu, 16 Nov 2023 08:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1700151835; x=1700756635; darn=freebsd.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Ul71DMB38dRb2fdMdYU8/uCEP5/5Cd8NQv+fxz7R6uI=; b=U19zhW5zEwKt0nnMOHpN9PnC9/2qyfQG4uk+1PvvK9odvU8SEoMaifz0voqebycUsQ wncTpnF16w6C1peQAuL7NPY6aAm0O4Mpb2XVof+fF1gg2duMzf9fH2B2DZGxv1VtJPKy r8HDbRPvJ3Wpa5L05GylSenwfWkJOOLpX2gAW/yQUHc3i99KR/46Mo3xm629sAZzbVwg HdO5/vqOB24Y8BUWCu/TN0HavtNzRTUaOUVGUYmg9xa/XCPIngk3dmjjd3Xrl74PNSFB hBUTYSC+Myo+xhvRi6jjqcnGX+NmBeppmpN4FVAz3nhJgenHnT9QyqqbMuLTXAHNDgR4 wSrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700151835; x=1700756635; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ul71DMB38dRb2fdMdYU8/uCEP5/5Cd8NQv+fxz7R6uI=; b=eek8i0Rw3VdG6nLXUleDQOSZ0rRKW78StA/uRuShany0azNdtBVkj81EIQymETRQuj RURrsDsfxc94NbWTpB52w3fDEm208A5iEK/GAFHahbckx/AWsPevvqeERa4uApXCo+c0 QeYaG5pIcPEvGvOvDBkOJp86Vxq5qU7hGUjENenlR0qsANMekcCcnOxcRrIbr8Svq+J7 wmSYgbj4oXmoB57WiwWvgzIAHdxB1qI1HXa++vIb8u8QLfmCcFCt0g+5JIl3htL7aitG 4+F+Ec3mAE5I+IcAqJATh//nSdaHQVHEeGQPiwTNvz4gXXt+xLkrNKM2ayCsrzDqgayJ LSww== X-Gm-Message-State: AOJu0YyOIkdtMxtqjNp2TXCJogByfXiC3zFrGDegC3x7n8Zx3eMHVGw8 ckeb/lfAAcuqmQIeBxKToO14kYxdZpDtQqcitrkBbBgP9Pdtr2MU X-Google-Smtp-Source: AGHT+IFD4ex9VvUz7TsWeekIb7MbWqovjW4D7XuSBknRME9BpEsjDac2vKbTTqKJvBWWLkfqQm96dkpU2Rz0bguZbTM= X-Received: by 2002:a05:6402:4416:b0:547:6601:d46 with SMTP id y22-20020a056402441600b0054766010d46mr11022810eda.30.1700151835027; Thu, 16 Nov 2023 08:23:55 -0800 (PST) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 References: <202311161507.3AGF7kgx070201@gitrepo.freebsd.org> <39921E4A-4C15-4D8F-BA9F-D0C53AD62CD1@freebsd.org> In-Reply-To: <39921E4A-4C15-4D8F-BA9F-D0C53AD62CD1@freebsd.org> From: Warner Losh Date: Thu, 16 Nov 2023 09:23:43 -0700 Message-ID: Subject: Re: git: accfb4cc9346 - main - genoffset.sh: stop using a temporary file To: Jessica Clarke Cc: "Jonathan T. Looney" , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Type: multipart/alternative; boundary="00000000000030fa20060a477232" X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US] X-Rspamd-Queue-Id: 4SWQMd0QRyz3F8r --00000000000030fa20060a477232 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Nov 16, 2023 at 9:07=E2=80=AFAM Jessica Clarke = wrote: > On 16 Nov 2023, at 15:07, Jonathan T. Looney wrote: > > > > The branch main has been updated by jtl: > > > > URL: > https://cgit.FreeBSD.org/src/commit/?id=3Daccfb4cc9346b23f6d6383dfc98d2c9= 7ae18ce0d > > > > commit accfb4cc9346b23f6d6383dfc98d2c97ae18ce0d > > Author: Jonathan T. Looney > > AuthorDate: 2023-11-16 15:02:32 +0000 > > Commit: Jonathan T. Looney > > CommitDate: 2023-11-16 15:02:32 +0000 > > > > genoffset.sh: stop using a temporary file > > > > Instead, use a here document for the input. This allows us to run th= e > > while loop in the main script so we can build the list of asserts in > > a shell variable. We then print out the list of asserts at the end o= f > > the loop. > > > > Reviewed by: imp > > Sponsored by: Netflix > > Differential Revision: https://reviews.freebsd.org/D42407 > > --- > > sys/kern/genoffset.sh | 15 +++++++-------- > > 1 file changed, 7 insertions(+), 8 deletions(-) > > > > diff --git a/sys/kern/genoffset.sh b/sys/kern/genoffset.sh > > index fda27998ca79..c974a7d52e8c 100644 > > --- a/sys/kern/genoffset.sh > > +++ b/sys/kern/genoffset.sh > > @@ -35,16 +35,13 @@ usage() > > > > work() > > ( > > - local last off x1 x2 x3 struct field type lastoff lasttype > > + local last off x1 x2 x3 struct field type lastoff lasttype asserts > > > > echo "#ifndef _OFFSET_INC_" > > echo "#define _OFFSET_INC_" > > echo "#if !defined(GENOFFSET) && (!defined(KLD_MODULE) || > defined(KLD_TIED))" > > last=3D > > - temp=3D$(mktemp -d genoffset.XXXXXXXXXX) > > - trap "rm -rf ${temp}" EXIT > > - # Note: we need to print symbol values in decimal so the numeric > sort works > > - ${NM:=3D'nm'} ${NMFLAGS} -t d "$1" | grep __assym_offset__ | sed -= e > 's/__/ /g' | sort -k 4 -k 1 -n | > > + asserts=3D > > while read off x1 x2 struct field type x3; do > > off=3D$(echo "$off" | sed -E 's/^0+//') > > if [ "$last" !=3D "$struct" ]; then > > @@ -60,12 +57,14 @@ work() > > printf "%b" "\t${type}\t${field};\n" > > lastoff=3D"$off" > > lasttype=3D"$type" > > - echo "_SA(${struct}, ${field}, ${off});" >> "$temp/asserts" > > - done > > + asserts=3D"${asserts}_SA(${struct}, ${field}, ${off});\n" > > + done < > +$(${NM:=3D'nm'} ${NMFLAGS} -t d "$1" | grep __assym_offset__ | sed -e > 's/__/ /g' | sort -k 4 -k 1 -n) > > +EOT > > echo "};" > > echo "#define _SA(s,f,o) _Static_assert(__builtin_offsetof(struct s > ## _lite, f) =3D=3D o, \\" > > printf '\t"struct "#s"_lite field "#f" not at offset "#o)\n' > > - cat "$temp/asserts" > > + echo -e "${asserts}\c" > > This isn=E2=80=99t POSIX, and isn=E2=80=99t supported by macOS=E2=80=99s = sh, so breaks the > build there. Please fix or revert promptly. > echo "${asserts}" is semantically the same for C. A stray newline doesn't matter in this context. It's not worth the effort to remove it. Sadly, echo -n doesn't work (it's not posix, and posix defines it specifically as implementation defined). `echo "fred\c"' works on macos, but not FreeBSD's shell echo built-in (but somehow does for /bin/echo). macos doesn't implement -e at all (it's also not posix). FreeBSD's shell echo build-in is not posix compliant. So, to be portable, just echo it, and cope with the extra newline. That's what I'd do :) Warner > Jess > > > echo "#undef _SA" > > echo "#endif" > > echo "#endif" > > --00000000000030fa20060a477232 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Nov 16, 2023 at 9:07=E2=80=AF= AM Jessica Clarke <jrtc27@freebsd.= org> wrote:
On 16 Nov 2023, at 15:07, Jonathan T. Looney <jtl@FreeBSD.org> wro= te:
>
> The branch main has been updated by jtl:
>
> URL: https://= cgit.FreeBSD.org/src/commit/?id=3Daccfb4cc9346b23f6d6383dfc98d2c97ae18ce0d<= /a>
>
> commit accfb4cc9346b23f6d6383dfc98d2c97ae18ce0d
> Author:=C2=A0 =C2=A0 =C2=A0Jonathan T. Looney <jtl@FreeBSD.org><= br> > AuthorDate: 2023-11-16 15:02:32 +0000
> Commit:=C2=A0 =C2=A0 =C2=A0Jonathan T. Looney <jtl@FreeBSD.org><= br> > CommitDate: 2023-11-16 15:02:32 +0000
>
>=C2=A0 =C2=A0 genoffset.sh: stop using a temporary file
>
>=C2=A0 =C2=A0 Instead, use a here document for the input. This allows u= s to run the
>=C2=A0 =C2=A0 while loop in the main script so we can build the list of= asserts in
>=C2=A0 =C2=A0 a shell variable. We then print out the list of asserts a= t the end of
>=C2=A0 =C2=A0 the loop.
>
>=C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 imp
>=C2=A0 =C2=A0 Sponsored by:=C2=A0 =C2=A0Netflix
>=C2=A0 =C2=A0 Differential Revision:=C2=A0
https://reviews.fre= ebsd.org/D42407
> ---
> sys/kern/genoffset.sh | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/sys/kern/genoffset.sh b/sys/kern/genoffset.sh
> index fda27998ca79..c974a7d52e8c 100644
> --- a/sys/kern/genoffset.sh
> +++ b/sys/kern/genoffset.sh
> @@ -35,16 +35,13 @@ usage()
>
> work()
> (
> -=C2=A0 =C2=A0 local last off x1 x2 x3 struct field type lastoff lastt= ype
> +=C2=A0 =C2=A0 local last off x1 x2 x3 struct field type lastoff lastt= ype asserts
>
>=C2=A0 =C2=A0 =C2=A0echo "#ifndef _OFFSET_INC_"
>=C2=A0 =C2=A0 =C2=A0echo "#define _OFFSET_INC_"
>=C2=A0 =C2=A0 =C2=A0echo "#if !defined(GENOFFSET) && (!def= ined(KLD_MODULE) || defined(KLD_TIED))"
>=C2=A0 =C2=A0 =C2=A0last=3D
> -=C2=A0 =C2=A0 temp=3D$(mktemp -d genoffset.XXXXXXXXXX)
> -=C2=A0 =C2=A0 trap "rm -rf ${temp}" EXIT
> -=C2=A0 =C2=A0 # Note: we need to print symbol values in decimal so th= e numeric sort works
> -=C2=A0 =C2=A0 ${NM:=3D'nm'} ${NMFLAGS} -t d "$1" | = grep __assym_offset__ | sed -e 's/__/ /g' | sort -k 4 -k 1 -n |
> +=C2=A0 =C2=A0 asserts=3D
>=C2=A0 =C2=A0 =C2=A0while read off x1 x2 struct field type x3; do
> off=3D$(echo "$off" | sed -E 's/^0+//')
> if [ "$last" !=3D "$struct" ]; then
> @@ -60,12 +57,14 @@ work()
> printf "%b" "\t${type}\t${field};\n"
> lastoff=3D"$off"
> lasttype=3D"$type"
> - echo "_SA(${struct}, ${field}, ${off});" >> "$t= emp/asserts"
> -=C2=A0 =C2=A0 done
> + asserts=3D"${asserts}_SA(${struct}, ${field}, ${off});\n"<= br> > +=C2=A0 =C2=A0 done <<EOT
> +$(${NM:=3D'nm'} ${NMFLAGS} -t d "$1" | grep __assym= _offset__ | sed -e 's/__/ /g' | sort -k 4 -k 1 -n)
> +EOT
>=C2=A0 =C2=A0 =C2=A0echo "};"
>=C2=A0 =C2=A0 =C2=A0echo "#define _SA(s,f,o) _Static_assert(__buil= tin_offsetof(struct s ## _lite, f) =3D=3D o, \\"
>=C2=A0 =C2=A0 =C2=A0printf '\t"struct "#s"_lite fiel= d "#f" not at offset "#o)\n'
> -=C2=A0 =C2=A0 cat "$temp/asserts"
> +=C2=A0 =C2=A0 echo -e "${asserts}\c"

This isn=E2=80=99t POSIX, and isn=E2=80=99t supported by macOS=E2=80=99s sh= , so breaks the
build there. Please fix or revert promptly.

=
echo "${asserts}"

is semantically t= he same for C. A stray newline doesn't matter in this context. It's= not worth the effort to remove it.

Sadly, echo -n= doesn't work (it's not posix, and posix defines it specifically as= implementation defined). `echo "fred\c"' works on macos, but= not FreeBSD's shell echo built-in (but somehow does for /bin/echo). ma= cos doesn't implement -e at all (it's also not posix). FreeBSD'= s shell echo build-in is not posix compliant. So, to be portable, just echo= it, and cope with the extra newline.

That's w= hat I'd do :)

Warner
=C2=A0
Jess

>=C2=A0 =C2=A0 =C2=A0echo "#undef _SA"
>=C2=A0 =C2=A0 =C2=A0echo "#endif"
>=C2=A0 =C2=A0 =C2=A0echo "#endif"

--00000000000030fa20060a477232--