From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF53222FF22 for ; Sat, 4 Apr 2026 15:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775316588; cv=none; b=Sd7BCTYn627wW4687JJ2yAsspMRRyppmHNdPxqH/LMbfC4c1hcdKiHuKCHc+CvU02/1RQFLsYOi4kk/SXFg/JTFQMdErJha/BmxK4KugCtSDJR6KEhYbSacoHj6DG1zNgXxs6zs9ZeeqwATYL7g7kAWgEZ35DBOGdJTMzvp1aVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775316588; c=relaxed/simple; bh=V2d9bYWPPwtgs/eP7a2LlR3a1bOPX1eTUQBY40rVWNs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J/00Qtka7dY3FKmhjIHgDIfrcl/XjHCcmZVhdEXKRkvzakpl+MZVAooV2DU9HjNz+myexbpjPrwXb9frSdsgsAJCkXv99K/HUzGjfpkFzTy5CKq5Zvu8bKZMOL4U3fOnCo83DHMUbIBXY5KSBEXfhOe5mgjz9KrHVLkm+fjEjtE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D40WjYJs; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D40WjYJs" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-488aa77a06eso19315e9.0 for ; Sat, 04 Apr 2026 08:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775316585; x=1775921385; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Iiqq6XToBaKDMRjjN3GxrXr1l9Zc95DifFOhkAS+oKo=; b=D40WjYJspTRr3J3HCVvv/y/ZengbiLo24vLIZTvavEBL7eO6oLjY5fQbJcFDNzni+F JvmDrocMUYwVLsLr2JufURMBGoAaIw4wCIXeYpNJxeExUh3+eG7sN0pec930DnfxDB2g uJCCnDf/x1sc9PblGE6Nje1TItBgOb5jVz0s7fdK7YHGc0Hnrtyarto7txcFfF/s0Nss oqzyfVM4/i5tvbNogLH6YZKqbdmPcK3KBN28LBI8J/nbn3CCRlPA/4JtRNNjpJ03Evmu quPCgSJvjCW+r7FpAfUre6vCtjGkY5sZSQcMqcCrCC5TJsDfRbKWq7u1h+h0bEBJs3UP wgxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775316585; x=1775921385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Iiqq6XToBaKDMRjjN3GxrXr1l9Zc95DifFOhkAS+oKo=; b=IgiXjO/CUVaWgUzUH7xRBVn5wpkthOhPZkx6PDts5D4C+K0w++9BfntH6zj9kqdTg/ 4RGUkx7JQXQc2wOxqM6OI5C/T4M/cp488kbAdVTIt94tgDc5jOtbKdxXU93kfAh3hW3F TJk5vvIye5nTHiiKg5S0HaAF/qN0zL2Ex5QbMKc9cLCsSaONl1PkAz2F933ASWyEH9pT 9KapkwQffy2j7mhsOgNoBkxTQ8cJ7+wCxDHhqnu8F+fLzlJ9ja3f+AXnGwp3XEwL3GZh jN1UpaZ0GVYzRJBCsZmBokNmtZ+VoE99j70slaKLMqT5pUUwcPm7IiC66Le5CpUsdz/W S3JA== X-Forwarded-Encrypted: i=1; AJvYcCUgm1dJck2hYO0n/89dj8Li4Au3lwX29ynXYjaK1cQBT6dg+rBnShQgAXXffmFWvR5eWo/JZ0FVL9Kuqfk=@vger.kernel.org X-Gm-Message-State: AOJu0YzuSAYO9P4gxwE2CRUA5kCEH75yO0+bULWvn2jw5skh8oU54Ver FS1b+lnFY2uFvxY16B/3xz3SIcWsJSrG0pywyDPpj3dtpf4wuFuoPqKKum8MCJxQkrY= X-Gm-Gg: AeBDieurp/sB6HWpJr7W1+W0RDG+CTiZwAR6f9iu6Vyn5ymn6DY+1EqC9LSkE5FbTqF fdbFUc/peE3FrF4iVHw5BxUmfDW/ENvCbmoE29aFuoLbJHrSGV8qZWbA+uPfRWF3T5YB7fSSlUZ NJ8Lr+RI0YNxItjTqUmTwAj/meteVJ99CFrX8mIU/Ur/SjGmGS3ckBYEIl7x7ih4549U1K/ppMF C2aWqbgeF+8sPtG7j3KiHcOMDKKoNVRvPN5g61S2J01OyPWOk0t0SVAAT8m4h3NJP4A9sVaGmy1 wYLh5wAwf1Ip9wgyNcaKmsrLCz+mbkA5K01Esx2PrTqvygAJPKG0vpuwJ4j99Rl+j87NR7q0W4W b03cSt1cv0t0+2juZIymFnZhiY5vGo4pbrY6HAl4qDeEMKl1ciTeNAEE0wntCNv8SwotGCMxKIo SEqG0XPsC2Kv31p4MEtOZaIL3OCEzG0A== X-Received: by 2002:a05:600c:c116:b0:479:1b0f:dfff with SMTP id 5b1f17b1804b1-4889975f458mr78195255e9.10.1775316585096; Sat, 04 Apr 2026 08:29:45 -0700 (PDT) Received: from pumpkin ([31.55.121.85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4888a7165aasm278253315e9.14.2026.04.04.08.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2026 08:29:44 -0700 (PDT) Date: Sat, 4 Apr 2026 16:29:43 +0100 From: David Laight To: Willy Tarreau Cc: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] tools/nolibc: use __builtin_offsetof() Message-ID: <20260404162943.4037f824@pumpkin> In-Reply-To: References: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> <20260401-nolibc-asprintf-v1-1-46292313439f@weissschuh.net> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, 4 Apr 2026 10:34:24 +0200 Willy Tarreau wrote: > Hi Thomas, >=20 > On Wed, Apr 01, 2026 at 05:07:27PM +0200, Thomas Wei=C3=9Fschuh wrote: > > The current custom implementation of offsetof() fails UBSAN: > > runtime error: member access within null pointer of type 'struct ...' > > This means that all its users, including container_of(), free() and > > realloc(), fail. > >=20 > > Use __builtin_offsetof() instead which does not have this issue and > > has been available since GCC 4 and clang 4. =20 >=20 > Yeah, that's a place where I find the standard ambiguous and ridiculously > absurd (since there's no dereference, only an address calculations), but I > had to do the same in haproxy recently for the same reasons, and I didn't > remember that we had it in nolibc as well. So that's an obvious ack! My guess it is all because the C standard allows NULL to have any bit-pattern. If it isn't the 'all zero' pattern then the arithmetic on the NULL pointer gives the wrong answer. Trouble is pretty much all C assumes that NULL is 0. Even the C for ICL's VME-B used 0 for NULL although the 'native' value would have been ~0. Too much code would have been broken. So it is technically not portable, but will always generate the correct answer. David >=20 > Acked-by: Willy Tarreau >=20 > thanks, > Willy >=20