Date: Tue, 20 Jan 2026 16:21:15 +0000 From: Jessica Clarke <jrtc27@freebsd.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: "src-committers@freebsd.org" <src-committers@freebsd.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@freebsd.org> Subject: Re: git: 96acaa960023 - main - compat32: provide a type and a macro for (u)int64_t handling on non-x86 arches Message-ID: <4D876814-AA9D-4007-A165-4E0B7881B5C2@freebsd.org> In-Reply-To: <aW-oVnLtJYRlY5AN@kib.kiev.ua> References: <696f9463.f398.7ea9495a@gitrepo.freebsd.org> <7F0190E5-8B20-40A5-9D31-1D56BCF39E71@freebsd.org> <aW-oVnLtJYRlY5AN@kib.kiev.ua>
index | next in thread | previous in thread | raw e-mail
On 20 Jan 2026, at 16:07, Konstantin Belousov <kostikbel@gmail.com> wrote: > > On Tue, Jan 20, 2026 at 04:05:19PM +0000, Jessica Clarke wrote: >> On 20 Jan 2026, at 14:42, Konstantin Belousov <kib@FreeBSD.org> wrote: >>> >>> The branch main has been updated by kib: >>> >>> URL: https://cgit.FreeBSD.org/src/commit/?id=96acaa960023c20e852e04e7cc5c6a5faca36c67 >>> >>> commit 96acaa960023c20e852e04e7cc5c6a5faca36c67 >>> Author: Konstantin Belousov <kib@FreeBSD.org> >>> AuthorDate: 2026-01-12 04:45:36 +0000 >>> Commit: Konstantin Belousov <kib@FreeBSD.org> >>> CommitDate: 2026-01-20 14:42:35 +0000 >>> >>> compat32: provide a type and a macro for (u)int64_t handling on non-x86 arches >>> >>> uint64_t is 4-byte aligned on i386, but is 8-bytes aligned on all other >>> 32bit arches FreeBSD supports. Provide the freebsd32_uint64_t type and >>> the FU64_CP() macro, which are intended to be used where 32bit ABI uses >>> (u)int64_t type, and do proper layout and copying for the aggregate type. >>> >>> Reviewed by: des, emaste >>> Sponsored by: The FreeBSD Foundation >>> MFC after: 1 week >>> Differential revision: https://reviews.freebsd.org/D54663 >>> --- >>> sys/compat/freebsd32/freebsd32.h | 11 ++++++++++- >>> sys/sys/abi_compat.h | 8 ++++++++ >>> 2 files changed, 18 insertions(+), 1 deletion(-) >>> >>> diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebsd32.h >>> index 9d724c93fee7..7324f9adf70c 100644 >>> --- a/sys/compat/freebsd32/freebsd32.h >>> +++ b/sys/compat/freebsd32/freebsd32.h >>> @@ -36,8 +36,17 @@ >>> #include <sys/_ffcounter.h> >>> >>> /* >>> - * i386 is the only arch with a 32-bit time_t >>> + * i386 is the only arch with a 32-bit time_t. >>> + * Also it is the only arch with (u)int64_t having 4-bytes alignment. >>> */ >>> +typedef struct { >>> +#ifdef __amd64__ >>> + uint32_t val[2]; >>> +#else >>> + uint64_t val; >>> +#endif >>> +} freebsd32_uint64_t; >> >> Any reason not to use: >> >> typedef uint64_t freebsd32_uint64_t __aligned(4); >> >> on amd64 (and normal typedef elsewhere)? Then you can just use the >> normal CP. See for example https://godbolt.org/z/svseWv7xo. > Yes, this way it uses only std C instead of the GNU extension, and not > depend on compiler properly handle unaligned types. > > IMO it is better that way, and all machinery is hidden under the typedef+ > the macro. Well, except (a) the kernel uses GNU C for all manner of things already (b) unaligned types are already well-supported otherwise packed structs wouldn’t work, which we’re happy to use (c) your structure approach hides less as you have to use the magic FU64_CP macro so is less abstracted than my proposal. Also, I just thought to check Linux, and it uses the same GNU C aligned trick, so we’re in good company and any issues with it would show up there, especially given people do use Clang to build Linux in production these days. So I disagree with your assessment entirely. Jessicahome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4D876814-AA9D-4007-A165-4E0B7881B5C2>
