Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3299398pxb; Fri, 4 Feb 2022 05:52:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKzw7OmuNXznjMyNLOgFnaKjQPxEn99bKbSEaGUTtm8idEGeZwHqVuHisUnKSJ//jSiNhn X-Received: by 2002:aa7:c659:: with SMTP id z25mr3088379edr.160.1643982762761; Fri, 04 Feb 2022 05:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643982762; cv=none; d=google.com; s=arc-20160816; b=yP9dqLaWvoVCbBH+pWhKdrSwMLkmy1Y5yMM0la6HOWioVJiJ1JzZQz5MEajlHci6Zi Ju0szrIXOOgxRC3dJTO1WrmhVnBGVsBvbuWwaaG5IcNvF0vqVK8X1D5fzrg9WB/iW4Jd HLINVy8LfprU7BvDNkcA63+d1PwpNEOyeBRSe4kLA3lo5iZJKExgmP/NakzskSoYXir3 /fLgzQHHQoFykL3WYoeKCjmU4ZWzKal8rSgNH+YgnLNpwx8dwx0rGl6dhgxLRwzPA+lN 1GEs+CEj7fEhRzEJctV3fiTKztkJ0toIeUVivGLxhG+jbqeJ+mo/D7LOBWbRQuwrZfEj 1nVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ETnKDeiOpwbtdI5wfgwyS9AlH6EKFDBz28cAyBq176w=; b=n3xyYPmO6ej6YxgkuzeCIimJ1bQncDGJgGoYLBFgb1HB09d898CRjBhGo6V5kZzcRm 5KSrFJT4OuO3uvmqip1Su5jlspnJH/wHhI17LMhgQXEva8z8n1hPgqAeS7kph0opS/WU chZC+x8Uti43lEUqJGL4YnPaRQMl5AtICnxS6zEB3+9sUdVG2wFtnr1D2OEXo1RbEzC9 sobaFu8y3UxFGxALq3cnuLk1uCXmH6L4/oDzCYT/Y/+pn3RP4Ik+LnBBMsXpoKP4PgFa HlmjvzUT39sj5UEZzxY8nraIQYb+uFMvAZlpdkKfB3jMY0DNEEogQ0oiDrXjAUvbyNeF Nckg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Z8n6/iQ6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt19si1220669ejc.433.2022.02.04.05.52.17; Fri, 04 Feb 2022 05:52:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Z8n6/iQ6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347307AbiBBUx1 (ORCPT + 99 others); Wed, 2 Feb 2022 15:53:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347294AbiBBUxZ (ORCPT ); Wed, 2 Feb 2022 15:53:25 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2EA7C061714 for ; Wed, 2 Feb 2022 12:53:24 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id c3so301620pls.5 for ; Wed, 02 Feb 2022 12:53:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ETnKDeiOpwbtdI5wfgwyS9AlH6EKFDBz28cAyBq176w=; b=Z8n6/iQ6Ng/iumDQGn5Zu/vWC5/7pLHgLzDZnJkpoNCssZHWsOx9eC6Sb1V2fJCNzQ 6/0govRNCPerrev9lxboz2wl/wAoCyKRc90QsEnQWwXUMfCVwjCe3hu60jurrl1OatSt 3NHG35dR73JSUUn6+43aaOaaymCDSFhkt6Gks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ETnKDeiOpwbtdI5wfgwyS9AlH6EKFDBz28cAyBq176w=; b=pWmLI5I7a/b1T3avPeprKymzZ4YTBZRL7cXu5bPP1M1eU0RnX0GnMqSXdCTwqvMGpH TImYbiWMPe5Pduq5RhEmwqs3yFROrgdQpT95RozzFGdD7woW4otwL2/VwHnsHW+YOub2 CBI+5KAj3FLZbfiqOR/XwRYL4TS0oSOcRT5lezddjJ0Isrm8OmjIg9yBHtuvdCw4ir49 9946qMZrX26/Ao+i6Wo0wMOYam0bNV4I38W/V+pRpkXvQGBjKzRriUx2bGJVKEXtVOdu M5yfsMtw8QiT0/7SO8GMC+0VD6JJgqji4bxhgpEesLfYaJiDOoMy2Y7EnG2RjJwiO23d B60g== X-Gm-Message-State: AOAM533/szxBMJpCchNoPRr4tBFFA6EtAMRyuMyZZfRdUUXl/yHo7dm+ cr2OP4Iz8YhZg6TnAR1sQUvRaPtdzsvhlQ== X-Received: by 2002:a17:90b:1912:: with SMTP id mp18mr10098907pjb.152.1643835204425; Wed, 02 Feb 2022 12:53:24 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p22sm24518460pfw.139.2022.02.02.12.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 12:53:24 -0800 (PST) Date: Wed, 2 Feb 2022 12:53:23 -0800 From: Kees Cook To: Rasmus Villemoes Cc: Nick Desaulniers , Miguel Ojeda , Andrew Morton , Nathan Chancellor , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] include: drop pointless __compiler_offsetof indirection Message-ID: <202202021253.B62C357@keescook> References: <20220202102147.326672-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220202102147.326672-1-linux@rasmusvillemoes.dk> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 02, 2022 at 11:21:47AM +0100, Rasmus Villemoes wrote: > (1) compiler_types.h is unconditionally included via an -include > flag (see scripts/Makefile.lib), and it defines __compiler_offsetof > unconditionally. So testing for definedness of __compiler_offsetof is > mostly pointless. > > (2) Every relevant compiler provides __builtin_offsetof (even sparse > has had that for 14 years), and if for whatever reason one would end > up picking up the poor man's fallback definition (C file compiler with > completely custom CFLAGS?), newer clang versions won't treat the > result as an Integer Constant Expression, so if used in place where > such is required (static initializer or static_assert), one would > get errors like > > t.c:11:16: error: static_assert expression is not an integral constant expression > t.c:11:16: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression > t.c:4:33: note: expanded from macro 'offsetof' > #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) > > So just define offsetof unconditionally and directly in terms of > __builtin_offsetof. > > Signed-off-by: Rasmus Villemoes Yes please. :) Reviewed-by: Kees Cook -- Kees Cook