From mboxrd@z Thu Jan 1 00:00:00 1970 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.