Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1376183rdb; Sun, 7 Jan 2024 17:29:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEU7lSCbUyZ5ZV4QUfeRLawDIQm3cMP1lrJw5KaR1kpkN2mWkR0eG3KES5hV8zniSavf3K2 X-Received: by 2002:ac8:5996:0:b0:429:97ab:f8a5 with SMTP id e22-20020ac85996000000b0042997abf8a5mr623640qte.14.1704677386001; Sun, 07 Jan 2024 17:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704677385; cv=none; d=google.com; s=arc-20160816; b=a7oWntsaPhzkXCF/yXSRtqzD6KcqoCfe7+GeQN+FXDiU3xLhBWsydw73yUbxgHs9+r wZJxxRG+icTmcRuH0eElyO+JrhXDjN0641kGLRiDrS/UCUW9Kt8o2fFJRZG5VvVID0qZ 4QskptRHX/1OP3x1D17sa04Wf8h0UkU1HIRb71zeVQakL9j0n/TSQ2MiSQVgvB8ElNNg h3KTlQKyIzwfG/vH2hgkDg2uLXnxt5cl7lKEUADQcQh4zZ72UzIyOiI9zqISvkvGM8V8 cUFDPtx6nZPO8VcQkd6ubGCOdW98T/xmX6pTau2RfNnMngN2ckiK2QNWV/Ie2icDyEqK EjuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=u4/ImgrVn500fYf+pZOgi0NiVJH/UHbc5pjYLxHng6Y=; fh=UdB0m562Z+wQ3Qj30x3kgJQ26LHZlnL3l1NYdYCfTUk=; b=x6ehEQN2oVFXWI9cWTLVgM+61aF0jponi+Y/YOcTbl7umiJF43zuyLTNGIBqVmCunX WbF0CEfU0thkVO7k5DpvflGD5hTMy7xzskTwOK80TLZjsFrusZNMNGLJrrwlLaQRXHCP zR40h9aUZ7+RGmnPfcorGrcSeks9p6+XSU7WJ/rypcP6DEKPY06ULq0xO7l48Wkp4Zch oKtM5ISLaFja6QUr/Vgz0t0hTNK+tGIz9IcXxfW3EFB2/I92QM/VcPCQNuuzTXVRRlz7 YghbSe7IYx6qaJhNP2ZvSX+JcPxfUFWp2ow2G4CDABIMIbd8uTmVqNxub1pKYkgWQCxz pBNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Byp5a365; spf=pass (google.com: domain of linux-kernel+bounces-19039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19039-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g14-20020ac87f4e000000b00428fb6a6900si6799674qtk.4.2024.01.07.17.29.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 17:29:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Byp5a365; spf=pass (google.com: domain of linux-kernel+bounces-19039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19039-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 9193C1C217CC for ; Mon, 8 Jan 2024 01:29:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B49007481; Mon, 8 Jan 2024 01:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Byp5a365" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58D957F for ; Mon, 8 Jan 2024 01:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-336788cb261so1341097f8f.3 for ; Sun, 07 Jan 2024 17:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704677348; x=1705282148; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=u4/ImgrVn500fYf+pZOgi0NiVJH/UHbc5pjYLxHng6Y=; b=Byp5a365JmAleQ+TNYVgZncVx8YhZEoAn/uX9uEg/48C7rrJ2ax/3apxn+k+W+TpJx kIh31h9Oke+FpdskBkJuisRnGL/hiR0kaUCyc4p1wAaTTWnaD5FGEi5gaZUXbnKqWmpL q3Uo7t+hjbTrSIkbsj/wKvTdpiW7vR/vZPLP1cQTBob5wY2SLqb03onov6YM2t5h1g+8 Yi/hq3vBBKFh629S2VawbUGEQltWz9ujjQutaoBHUgSbv9lellq+flGpvtkOIQ6cNRXf PfTxukzjmpwpSO1lvPT/iKX+yP8iRqr6CZcWPYepGuQwpXBLVQdmAweWKcFY/kqzGyS+ vIFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704677348; x=1705282148; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u4/ImgrVn500fYf+pZOgi0NiVJH/UHbc5pjYLxHng6Y=; b=xG90Rpyctmwk3uX9hyDPVb1q2sa/qFGomdHHQfquupUtx6+t+KAWM/Xgz5tAfyMlL3 v55ul+98wOA/EwbQMlJoOKr9m8GU7HdkBFUNWFMtBnrQkO4fCyEDJLHeyonXVgy/Nzke VrHRG+QdZ1B0//BDp7nMVRsoHKPbaos0qwPThWqFgrkeCNzOb+HHARtzRYiHi1k1f92R QSdl+f0D7Fj5NCtCGwN4S/Kctf+vyCe/RX3pPnj5wxklv/BhOOd2F+6BRSDTjwvZxHTj vw1nH1pf6ep4pKSkt2dgg1if9Cdc4jRg+FW71jQK5JCKpmu/BFTn1tawH8fm3BCmdvtS YXKQ== X-Gm-Message-State: AOJu0Ywrszzp6lTm+TJMDA4m2z8oz2449snA+uPvAsd0No8G/l9jPW5e P9bk2glT8EwD4KJq3zM5DpRPS60JaRM9zGyAHWGL62d+CCM= X-Received: by 2002:adf:ec4b:0:b0:336:a5db:e7cf with SMTP id w11-20020adfec4b000000b00336a5dbe7cfmr1593157wrn.47.1704677348119; Sun, 07 Jan 2024 17:29:08 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: richard clark Date: Mon, 8 Jan 2024 09:28:56 +0800 Message-ID: Subject: Re: undefined reference to `__aarch64_cas4_sync' error on arm64 native build To: Mark Rutland Cc: gcc-help@gcc.gnu.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Mark, On Fri, Jan 5, 2024 at 2:18=E2=80=AFAM Mark Rutland = wrote: > > On Tue, Jan 02, 2024 at 04:53:53PM +0800, richard clark wrote: > > Ah, the driver is trying to use the native gcc built atomic ops like: > > __sync_val_compare_and_swap, but it seems the native aarch64 doesn't > > provide these builtin atomic primitives while they are in the cross > > compile toolchain. > > The issue can be resolved by replacing the > > **__sync_val_compare_and_swap** with **atomic_cmpxchg**. > > Yup, that's the right thing to do; drivers *shouldn't* use the builtins > directly, and *should* use the kernel's native atomic*() API. > Right, that's the way I did to fix that. > > > 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 de= fault; > 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? > > Mark. > > > On Tue, Jan 2, 2024 at 11:29=E2=80=AFAM richard clark > > wrote: > > > > > > Hi, > > > > > > I have a strong power arm64 box, and the linux distro is ubuntu 22.04= , > > > the native gcc version is: > > > > > > $ gcc --version > > > gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 > > > Copyright (C) 2021 Free Software Foundation, Inc. > > > This is free software; see the source for copying conditions. There = is NO > > > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PU= RPOSE. > > > > > > It will abort the kernel build with the complaint by 'make Image': > > > ld: Unexpected GOT/PLT entries detected! > > > ld: Unexpected run-time procedure linkages detected! > > > ld: ID map text too big or misaligned > > > ld: drivers/net/nvidia_eth.o: in function `osi_lock_irq_enabled': > > > osi_hal.c:(.text+0x3cc): undefined reference to `__aarch64_cas4_sync' > > > ... > > > > > > But the cross-compile with aarch64-linux-gnu-gcc on the x86 box > > > doesn't show the above error message. > > > Any comments/suggestions? Thanks very much! > > > > > > Richard > >