Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1375841pxb; Fri, 6 Nov 2020 08:06:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzJOBdgCqeGZjMurq/F5VmGQcAfEKoFJpqWljlEfvJr0/oK+ugVIrvbqBBqIlpSNzo/mDk X-Received: by 2002:a17:906:7c4a:: with SMTP id g10mr2648435ejp.545.1604678811387; Fri, 06 Nov 2020 08:06:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604678811; cv=none; d=google.com; s=arc-20160816; b=Hvypv91imoCVz6SFW+fHUb7V+g3xnMMqyXtL5O1SmwARdc81SGj82FJqTNsTQWGTRF vyx+E3XgfGoHfalmAjj0hMViPHpehn8fx2/vea7WMa3E7zRld5vN3MgFBfotxH9trCJ6 vMqdoLZZzki7BCITFNNpz/TPPEyIbHyiqrojKJkFQ9JnFAf+s5DHLl1OJojRTlvoxdqJ 3/cgUyEYWfJ8rxnH3vSnFdVfNeygIZ59c9Mz5HDGXfj45hVnzokQQgZJtl2pZOI4hO03 oI3lGioOT7NMUNnxtvk5u+QJbISpbT/1dBKz8if08iWdcmXO2SFvlTmI5l4G53nag5L5 kO5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=EYK+J+nFdAu5CEbJrfqWZq4PGL/t0JmQeodkAruc60E=; b=ZUKB6E/Y28s62oUP6QKjsJWTvH2bDPn1jO548Cf6W0kT1Z/0RLjiriGgsGWzzyI8L4 awrly9nd54DIKUQ2ib8MRzSQf5BmWgJMK94lciyOaYRVv4dQ1ruflRKVFRgvLmPvvyVg 1OyhWw+RrL5iYRK4gjdvBGbdtzXS+Rfrilbi0BNv21mQ5bXufq51yvMfmqb5oofegaC5 YR9PrDe27roZuisAFqL2L7CqcRhHPw8NQcXw2LQyY7ntXpn1P9wJpSZfEscf30/BGgSN dpjsUTrJ83wnSsz05LIWsltp646o/ZewvDM24NrZ6quoRBuEmrIJ0Wy6WJtNri4TvimI QyEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UHM7wJvE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si1263355eds.110.2020.11.06.08.06.21; Fri, 06 Nov 2020 08:06:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UHM7wJvE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbgKFQDx (ORCPT + 99 others); Fri, 6 Nov 2020 11:03:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:59278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726831AbgKFQDx (ORCPT ); Fri, 6 Nov 2020 11:03:53 -0500 Received: from linux-8ccs.fritz.box (p57a236d4.dip0.t-ipconnect.de [87.162.54.212]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B04C2208C7; Fri, 6 Nov 2020 16:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604678632; bh=EYK+J+nFdAu5CEbJrfqWZq4PGL/t0JmQeodkAruc60E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UHM7wJvE07Wa3hVRkhdkb/75xQO+HuXaQzce6E9FNDwyZx8Ir43LvS03WIcGblB9g d3AIuBzRmSgG0IzSUhJ6wzw1/3RUJqRw7XbEIr42GbzU0BdgAZlH/J+UP3/sqC5wtf dZeLHsfiaIqhYWLbBMKlhFwnF+4FqwH7VDiXUOso= Date: Fri, 6 Nov 2020 17:03:45 +0100 From: Jessica Yu To: Johan Hovold Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Rob Herring , Frank Rowand , Greg Kroah-Hartman , Nick Desaulniers , Arnd Bergmann , Geert Uytterhoeven , Dmitry Torokhov , David Miller , Jakub Jelinek , Peter Zijlstra , Thomas Gleixner , Steven Rostedt , Daniel Kurtz , linux-arch@vger.kernel.org, linux-m68k@lists.linux-m68k.org Subject: Re: [PATCH 0/8] linker-section array fix and clean ups Message-ID: <20201106160344.GA12184@linux-8ccs.fritz.box> References: <20201103175711.10731-1-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20201103175711.10731-1-johan@kernel.org> X-OS: Linux linux-8ccs 4.12.14-lp150.12.61-default x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Johan Hovold [03/11/20 18:57 +0100]: >We rely on the linker to create arrays for a number of things including >kernel parameters and device-tree-match entries. > >The stride of these linker-section arrays obviously needs to match the >expectations of the code accessing them or bad things will happen. > >One thing to watch out for is that gcc is known to increase the >alignment of larger objects with static extent as an optimisation (on >x86), but this can be suppressed by using the aligned attribute when >declaring entries. > >We've been relying on this behaviour for 16 years for kernel parameters >(and other structures) and it indeed hasn't changed since the >introduction of the aligned attribute in gcc 3.1 (see align_variable() >in [1]). > >Occasionally this gcc optimisation do cause problems which have instead >been worked around in various creative ways including using indirection >through an array of pointers. This was originally done for tracepoints >[2] after a number of failed attempts to create properly aligned arrays, >and the approach was later reused for module-version attributes [3] and >earlycon entries. >[2] https://lore.kernel.org/lkml/20110126222622.GA10794@Krystal/ Hi Johan, So unfortunately, I am not familiar enough with the semantics of gcc's aligned attribute. AFAICT from the patch you linked in [2], the original purpose of the pointer indirection workaround was to avoid relying on (potentially inconsistent) compiler-specific behavior with respect to the aligned attribute. The main concern was potential up-alignment being done by gcc (or the linker) despite the desired alignment being specified. Indeed, the gcc documentation also states that the aligned attribute only specifies the *minimum* alignment, although there's no guarantee that up-alignment wouldn't occur. So I guess my question is, is there some implicit guarantee that specifying alignment by type via __alignof__ that's supposed to prevent gcc from up-aligning? Or are we just assuming that gcc won't increase the alignment? The gcc docs don't seem to clarify this unfortunately. Thanks, Jessica