Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4272683pxf; Tue, 23 Mar 2021 07:03:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2OGt3n8ntoNObFt1zvZpiqto6aH0vhcCnFQJpiDdsiRahGzG8FPW4+eQNHtH3rKJzSpCV X-Received: by 2002:a17:907:2112:: with SMTP id qn18mr5003061ejb.220.1616508234935; Tue, 23 Mar 2021 07:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616508234; cv=none; d=google.com; s=arc-20160816; b=QuJYMUG2rhHrB3RxO/r0Hp+K+Vuo3o/2yzOW+HFbo86BFc+UNqEGACWZJQRSSY3ef1 fIbyAeEgndIxmlIAOw2cXo4vFb7bOHEcVCtTK9HhLgRlxFchKqMp1sG0jUq9LEB1C9ho AG4Whd+4n21uCw75zmjdeID4EsBHQjfKF5tO1fpNdtMM3QdiPjBt8vYr5haktDm+Mf74 DhqYrxIUIgeZ1O8+2MIfB8lzwGmKaZbgNac/Jg35Gm8OtcvzpU8sa3mKIGaDnSBkcy7q u4rEwlwEdr4wHnVf11E20RNO6JHgxiiX6BtCtjrv/FcuR/cIo4Jqmg0oqBpIJKSESOXN +n5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=UtuzCS9CmRNxqMTT2ThaLucivqheLmn3gug9qTTha34=; b=d13FZh0+FtbqjS7nuMBg9zCNilm9EyBIEzsDRJQ9oGLtniLRSD1lQjRSJylXeGCHEM gft5s4uJxXDXqrYJlooaZHmP+keZbckddJfxJokhIG/JmW2zGR6Af69dYzshbSiJIAWV OTtuxOgbqpDFpAzCpdrXuZ0ywJzP5vRaSMo+2Z4bTD7A4tf3rdVbl2slW5uTavizFUu9 zypUxW0Er6s8jor6SVs98bq87OVDBe+YlN/KVYaDWcm/tDDH+SX/lSuQuxYOX+4AG+N7 CxlgECcSmBgbrfXu6pPcl63fcakq36/Rk1Yg1OouxhQk/dcdUQisA1qKVgObEMlmdazx yUeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=DmKe3X3V; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si14160922ejy.320.2021.03.23.07.03.27; Tue, 23 Mar 2021 07:03:54 -0700 (PDT) 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=@rasmusvillemoes.dk header.s=google header.b=DmKe3X3V; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231928AbhCWOBb (ORCPT + 99 others); Tue, 23 Mar 2021 10:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231760AbhCWOA7 (ORCPT ); Tue, 23 Mar 2021 10:00:59 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 425DBC061574 for ; Tue, 23 Mar 2021 07:00:58 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id kt15so17783570ejb.12 for ; Tue, 23 Mar 2021 07:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UtuzCS9CmRNxqMTT2ThaLucivqheLmn3gug9qTTha34=; b=DmKe3X3VOGMyfKmshTEP9QGJ9m/sVjP51LviM546gS2zP7nN5ojhQhD8024mG+qhQf r+YA/in+dNwg4XvZdP4Wh3rxtddHvNCD8elddk9HfQdpQaPjCjBwY5DwX3sAXEQMA8dH L1wWqBBqxRkTFIcIDYUftL3DC4e/9vzzNwRBo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UtuzCS9CmRNxqMTT2ThaLucivqheLmn3gug9qTTha34=; b=Npb1Rwc+B3kt3QDAcNEzzNgkQBu+HXTNdSLSvbOLfn0wbiZ57lGAd/v03Ox1U0vrJr ELsLVVMELaii5a68GYOrbj+r65yR7WAQ42qnUZtZj79wzS1aa4H8mMbmJH3W5PW9OIIA wgFUsm/AlkhXeN6bcaM1KvgHzFuSIhSVZUMCV6YyTy9594JFu3MWs08jOElKJq6Fz6lm pVVozlfoiRYOsgqXzEk/y3KQ1Jlfubtvw+2u06fK3uQMVd7Yx1pJFsigVJy+sFY1n2NZ ztEFVlx/1KwMPYlH60u95hBzdCJ9zokXF7WvZNsJZ5g1/vGx++k4Kp12zUmXIFkl35ZW hX8Q== X-Gm-Message-State: AOAM5330Dbgn29MFaICknUPs+Edzu6V8xV9EJ/xnXcXDiNr+5x4m4Qm5 x0/eL6ppbczS8TCZFBIOqDX4YA== X-Received: by 2002:a17:907:7699:: with SMTP id jv25mr4882200ejc.363.1616508056929; Tue, 23 Mar 2021 07:00:56 -0700 (PDT) Received: from [192.168.1.149] ([80.208.71.248]) by smtp.gmail.com with ESMTPSA id y9sm11168283ejd.110.2021.03.23.07.00.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 07:00:56 -0700 (PDT) Subject: Re: [kbuild-all] Re: include/linux/compiler_types.h:315:38: error: call to '__compiletime_assert_536' declared with attribute error: BUILD_BUG_ON failed: offsetof(struct can_frame, len) != offsetof(struct canfd_frame, len) || offsetof(struct can_frame, data) != offsetof(struc... To: Oliver Hartkopp , Marc Kleine-Budde , Rong Chen , Patrick Menschel Cc: kernel test robot , kbuild-all@lists.01.org, linux-kernel@vger.kernel.org, linux-can References: <202103210435.I0fiBGAC-lkp@intel.com> <7f4f7e1c-194b-a903-d474-e3b742556a55@intel.com> <20210323073437.yo63wreqnubbeqby@pengutronix.de> <7ff6bfd3-6b4b-045a-abb7-485927909587@hartkopp.net> <080d9e5c-fe1f-4a64-2938-8ca6d8a98d78@hartkopp.net> From: Rasmus Villemoes Message-ID: <0a8e8e95-c1a2-ede6-9f87-1ab7a0a155e3@rasmusvillemoes.dk> Date: Tue, 23 Mar 2021 15:00:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <080d9e5c-fe1f-4a64-2938-8ca6d8a98d78@hartkopp.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/03/2021 13.49, Oliver Hartkopp wrote: > > > On 23.03.21 12:36, Rasmus Villemoes wrote: >> >> and more directly from the horse's mouth: >> >> https://developer.arm.com/documentation/dui0067/d/arm-compiler-reference/c-and-c---implementation-details/structures--unions--enumerations--and-bitfields >> >> >> Field alignment >> >>      Structures are arranged with the first-named component at the lowest >> address. Fields are aligned as follows: >> >>          A field with a char type is aligned to the next available byte. >> >>          A field with a short type is aligned to the next even-addressed >> byte. >> >>          Bitfield alignment depends on how the bitfield is declared. See >> Bitfields in packed structures for more information. >> >>          All other types are aligned on word boundaries. >> >> That anonymous union falls into the "All other types" bullet. >> >> __packed is the documented and standard way to overrule the >> compiler's/ABI's layout decisions. > > So why is there a difference between > > gcc version 10.2.0 > > and > > gcc version 10.2.1 20210110 (Debian 10.2.1-6) I'm guessing there's no difference between those (in this respect), but they are invoked differently. > Would this mean that either STRUCTURE_SIZE_BOUNDARY or the command line > option -mstructure_size_boundary= > > are set differently? Yes, though very likely -mstructure_size_boundary is not set explicitly but via some other option. gcc has a rather helpful but almost unknown feature that one can actually query for lots of different parameters and their default/current values. So on my Ubuntu system (20.04, gcc 9.3), for example, if I do $ arm-linux-gnueabihf-gcc -O2 -Q --help=target | grep struct -mstructure-size-boundary= 8 So that would seem to say that the union should work as expected. However, when I actually try to compile with the .config that kbuild reports failing, I do see that BUILD_BUG_ON triggering. So let us inspect the actual command line used to build some other random .o file in net/can; look at net/can/.bcm.o.cmd cmd_net/can/bcm.o := arm-linux-gnueabihf-gcc -Wp,-MMD,net/can/.bcm.o.d -nostdinc -isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include -I./arch/arm/include -I./arch/arm/include/generated -I./include -I./arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -I./arch/arm/mach-footbridge/include -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -mno-unaligned-access -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=apcs-gnu -mno-thumb-interwork -marm -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=4 -march=armv4 -mtune=strongarm110 -msoft-float -Uarm -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -Wimplicit-fallthrough -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-inline-functions-called-once -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fsanitize-coverage=trace-pc -DKBUILD_MODFILE='"net/can/can-bcm"' -DKBUILD_BASENAME='"bcm"' -DKBUILD_MODNAME='"can_bcm"' -D__KBUILD_MODNAME=kmod_can_bcm -c -o net/can/bcm.o net/can/bcm.c Lots of gunk. But just to see if one of those options have affected the -mstructure-size-boundary= value, just take that whole command line and throw in -Q --help=target at the end, and we get -mstructure-size-boundary= 32 So let us guess that it's the ABI choice -mabi=apcs-gnu $ arm-linux-gnueabihf-gcc -O2 -msoft-float -mabi=apcs-gnu -Q --help=target | grep struct -mstructure-size-boundary= 32 Bingo. (-msoft-float is also included just as in the real command line because gcc barfs otherwise). Now what CONFIG_* knobs are responsible for putting -mabi=apcs-gnu in CFLAGS is left as an exercise for the reader. Regardless, it is not a bug in the compiler. The error is the assumption that this language "Aggregates and Unions Structures and unions assume the alignment of their most strictly aligned component. Each member is assigned to the lowest available offset with the appropriate alignment. The size of any object is always a multiple of the object‘s alignment." from the x86-64 ABI applies on all other architectures/ABIs. > I'm not a compiler expert but this does not seem to be consistent. > > Especially as we only have byte sizes (inside and outside of the union) > and "A field with a char type is aligned to the next available byte." Yes, and that's exactly what you got before the anon union was introduced. > The union is indeed aligned to the word boundary - but the following > byte is not aligned to the next available byte. Yes it is, because the union occupies 4 bytes. The first byte is shared by the two char members, the remaining three bytes are padding. Rasmus