Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1547857rdb; Mon, 8 Jan 2024 02:51:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmSya7EYeIJ9Qiiv+DEsJcmGIHLMcuVhsHFDCJhog70tWMK5T4Ol/L9yT6MzMpQ8EGxgLl X-Received: by 2002:ac8:5893:0:b0:429:9b76:1350 with SMTP id t19-20020ac85893000000b004299b761350mr435500qta.5.1704711076827; Mon, 08 Jan 2024 02:51:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704711076; cv=none; d=google.com; s=arc-20160816; b=PU7M0WsHpoYaDATweK5PisjsiXRzqVJAfRQDCMSbdmBMQYwmix0FlwBDEUOURN3g9p /Q++1DrwrrDeNs6TBcaoDnHyVGwoQQi2oC4bBNfc3aE2N3ZJ/vtSBEszq5IGkBB2AUIz LCuBTtt3qSRa1XTESWYE6bhHN9qv98vNjuLwecDSVdR/iG819tKlHpQsejmX0Twvhuqw i0DKY+MNjVsrhYNKPyplbJ+ySeZddtUyarQ+4X1PchoOjTBtmOkjRIquERTkrvodPCoS ZBSdQrhQe6NAGCD4aHliyOEb/GglsK4T2HOz8GpOQ9RNTsAIGsvqWi1X5Q+W4nGNmiQ2 sDbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=AX0i9T6VWtxtPX/5/3l+aBCSxMfOe3pyrjd3f8ltuEQ=; fh=0lJHN/erCokOs+4Idc3m0EJ3QvrDMhz3SAWrB8jywfs=; b=kkcy89YHUGTsLgxS9SnH/ACMrNU7AtJzPO3UB+7VZBRg2FBbZ493WNUbxGYFDWDtSi b8gftmIiIGorbb0qEMGq941zQziN+F2qOeEMWuZG8mFWXrCANU1DpkRupoMVPPphY48B qDfT+j2hW3pYIiv5lOF+k2WADbF07JHAvvdku6mvtnsgnJzsjdIzfHDOjaIGITQAT2Ck RIXoGExZ4suC8rLpP0CTUmQHBfVUGm0mSa1abGNWf9Tn7ZDwFfpcaIqCvcGPA6AlPUSz ufmkuI7DlZAa+qS8UEgYMRiVRNncAdT1l9d7P/Mg20imElXaEvm4GVvc4+N1nAJwRPbW YIkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o15-20020a05622a044f00b00428372b408fsi7513810qtx.730.2024.01.08.02.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 02:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 91F081C22149 for ; Mon, 8 Jan 2024 10:51:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 824341400A; Mon, 8 Jan 2024 10:51:13 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11F0113FF9 for ; Mon, 8 Jan 2024 10:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55EA32F4; Mon, 8 Jan 2024 02:51:56 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.89.149]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7BE343F5A1; Mon, 8 Jan 2024 02:51:09 -0800 (PST) Date: Mon, 8 Jan 2024 10:51:03 +0000 From: Mark Rutland To: richard clark Cc: gcc-help@gcc.gnu.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: undefined reference to `__aarch64_cas4_sync' error on arm64 native build Message-ID: References: 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Jan 08, 2024 at 09:28:56AM +0800, richard clark wrote: > On Fri, Jan 5, 2024 at 2:18 AM Mark Rutland wrote: > > On Tue, Jan 02, 2024 at 04:53:53PM +0800, richard clark wrote: > > > But don't know why the native aarch64 toolchain doesn't have those > > > builtin atomic functions... > > > > I suspect this is down to your toolchain enabling -moutline-atomics by default; > > that expands the builtins into calls to out-of-line functions. I suspect your > > cross-compile toolchain doesn't enable that by default. > > > > As above, since nothing should be using the builtins, we don't implement > > out-of-line versions nor do we override the option. > > > AFAIK, the native build for the kernel will not link to the libc.so > but the userland application does, the builtin atomic primitives are > implemented in the glibc: > target-host $ objdump -t /lib/aarch64-linux-gnu/libc.so.6 | grep __aarch64_cas4 > 0000000000130950 l F .text 0000000000000034 __aarch64_cas4_relax > 0000000000130a10 l F .text 0000000000000034 __aarch64_cas4_rel > 0000000000130990 l F .text 0000000000000034 __aarch64_cas4_acq > seems the '__sync_val_compare_and_swap' used in the application will > be renamed to _aarch64_cas4_{relax, rel, acq}. so the kernel will > complain it will > link to an 'undefined reference'. But interesting, why the > cross-compile kernel will not generate the 'undefined reference', the > cross-compile/build kernel will link to the glibc? This is due to a difference in default options between the two compilers; the kernel isn't linked against libc in either case. Your native compiler evidently has -moutline-atomics enabled in its default options. With that enabled, the builtin atomics generate calls to out-of-line functions which the kernel itself does not provide, and hence those result in a link-time error. Your cross-compiler evidently does not have -moutline-atomics enabled in its default options. Without that enabled, the builtin atomics generate inline atomic instructions rather than function calls. Since these don't depend on external functions there's no link-time error. If you pass 'mno-outline-atomics' to your native compiler, the problem should disappear. Mark.