From owner-freebsd-toolchain@freebsd.org Wed Aug 12 05:22:06 2020 Return-Path: Delivered-To: freebsd-toolchain@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9C8103BE3F6 for ; Wed, 12 Aug 2020 05:22:06 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: from mailman.nyi.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id 4BRJ3f1vfWz4SRW for ; Wed, 12 Aug 2020 05:22:06 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id 31B1B3BE068; Wed, 12 Aug 2020 05:22:06 +0000 (UTC) Delivered-To: toolchain@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 316883BE550 for ; Wed, 12 Aug 2020 05:22:06 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BRJ3d5Z96z4SK0; Wed, 12 Aug 2020 05:22:05 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: by mail-lf1-f49.google.com with SMTP id 140so487668lfi.5; Tue, 11 Aug 2020 22:22:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=k5wmAKvQJPeR395XCJflnNYBT6vuSS/ItoquIrAHh0U=; b=OFGHmwZGxNqV3fwDJ3aJo4E5L1US3M/5DaXf1HA5LQz7owNYwn/NHkzNAKluaKqzOD 5ylzYP0gM8oAoc2uS7qCbwo3ujp4QXRyUHHvjHqRJGhqZzNCBmE1OEjHGZwtknaFw+WP 6qa34iGRx6TfJWvstt+/0qHuxTKeolmz4wRvqdfUsR7DVhU1d60doder0UbwhQgUazq4 P3vWi4sJS5+7lWOY3eOQomJ/NOHc0z4AxgVs7BoUSIu0TA7Q/A3jpg9NdJjm/ys13rUX 2ehZfEr8bvSdWfThSZ71i10EVGn38vAYDTGre+u7MU1ee4gF+YigHvPal91xEn691L2r vsJA== X-Gm-Message-State: AOAM532XNs2JdAVcrvkjCQbNIrcpyP79uQfD76WpowFI1Pf0RhE2xhvx ia2RzDcBXB8Ndwy9PhMzhjzEeUI8+x8= X-Google-Smtp-Source: ABdhPJw3CHqIJ/Yo2DMdbtObHEg7rAu8BY2LX4M3/0QTd3D1rwej/NY0oU7/rQZBA+fo2JXmbXy6+g== X-Received: by 2002:a19:7710:: with SMTP id s16mr4831254lfc.162.1597209723915; Tue, 11 Aug 2020 22:22:03 -0700 (PDT) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com. [209.85.167.42]) by smtp.gmail.com with ESMTPSA id o68sm201144lff.57.2020.08.11.22.22.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Aug 2020 22:22:03 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id b30so471055lfj.12; Tue, 11 Aug 2020 22:22:03 -0700 (PDT) X-Received: by 2002:a05:6512:3253:: with SMTP id c19mr4605109lfr.139.1597209722855; Tue, 11 Aug 2020 22:22:02 -0700 (PDT) MIME-Version: 1.0 References: <20200807212855.GB2551@kib.kiev.ua> <20200808133000.GC2551@kib.kiev.ua> <20200809143742.430764e7@FreeBSD.org> <20200809154312.GH2551@kib.kiev.ua> <20200811235210.41049ad1@FreeBSD.org> In-Reply-To: <20200811235210.41049ad1@FreeBSD.org> From: Gleb Popov Date: Wed, 12 Aug 2020 09:21:36 +0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Undefined reference to __atomic_store_8 To: =?UTF-8?Q?T=C4=B3l_Coosemans?= Cc: Konstantin Belousov , toolchain@freebsd.org X-Rspamd-Queue-Id: 4BRJ3d5Z96z4SK0 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Aug 2020 05:22:06 -0000 On Wed, Aug 12, 2020 at 1:52 AM T=C4=B3l Coosemans wrote= : > On Tue, 11 Aug 2020 15:56:35 +0400 Gleb Popov wrote: > > On Sun, Aug 9, 2020 at 7:43 PM Konstantin Belousov > > wrote: > > > > > I do not believe there were any change in the toolchain between p2 an= d > p7, > > > this is more likely indicates some fluctuation in the build. The onl= y > > > change that could be even remotely declared as possibly related is > > > EN-20:10.build r360473. > > > > > > > Right, I was using a wrong set of port's OPTIONS that hide the problem. > > > > Indeed you need to look at the .o files that reference _8 symbol. I > would > > > closely look at the compilation command used for them, for start. > > > > > > > After digging it a bit I found that the following command > > > > cc -x c > > > /wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/ghc-prim/cbits/atom= ic.c > > -o /tmp/ghc_1.s -fno-PIC -Wimplicit -S \ > > -include > > > /wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/includes/dist-install/build/g= hcversion.h > > -I/usr/local/include \ > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/base/include \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/base/dist-install= /build/include > > \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/base/dist-install= /build/dist-install/build/include > > \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/integer-gmp/inclu= de > > \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/integer-gmp/dist-= install/build/include > > \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/integer-gmp/dist-= install/build/dist-install/build/include > > \ > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/rts/dist/build > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/includes \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/includes/dist-derivedconsta= nts/header > > \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/includes/dist-install/build= \ > > -march=3Di686 -U__i686 > > > > produce an assembly file with > > > > calll __atomic_load_8 > > > > instruction. > > > > The value of -march flag seems to be ignored. > > > > Interestingly, previous version of GHC calls C compiler in the followin= g > > way: > > > > cc -U__i686 '-march=3Di686' -fno-stack-protector -DTABLES_NEXT_TO_CODE > > '-march=3Di686' -x c > > > /wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/ghc-prim/cbits/atom= ic.c > > -o /tmp/ghc_1.s -Wimplicit -S \ > > -include > > > /wrkdirs/usr/ports/lang/ghc/work/ghc-8.6.5-boot/lib/ghc-8.6.5/include/ghc= version.h > > \ > > -I/usr/local/include \ > > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.6.5-boot/lib/ghc-8.6.5/base-4.12= .0.0/include > > \ > > -I/wrkdirs/usr/ports/lang/ghc/work/ghc-8.6.5-boot/lib/ghc-8.6.5/include > > > > And this command produces an assembly without calls to __atomic_load_8 > > > > Any ideas what makes it appear? > > Looking at atomic.c one possibility is that in the first command > HAVE_C11_ATOMICS is defined and not in the second. > > Apparently gcc always uses fild/fistp for __atomic_load_8 while clang > only uses it if the address is 8 byte aligned and generates a function > call otherwise. > Indeed, this looks like a culprit! When compiling using first command line (the long one) I get following warnings: /wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/ghc-prim/cbits/atomic= .c:369:10: warning: misaligned atomic operation may incur significant performance penalty [-Watomic-alignment] return __atomic_load_n((StgWord64 *) x, __ATOMIC_SEQ_CST); ^ /wrkdirs/usr/ports/lang/ghc/work/ghc-8.10.1/libraries/ghc-prim/cbits/atomic= .c:417:3: warning: misaligned atomic operation may incur significant performance penalty [-Watomic-alignment] __atomic_store_n((StgWord64 *) x, (StgWord64) val, __ATOMIC_SEQ_CST); ^ 2 warnings generated. I guess this basically means "I'm emitting a call there". So, what's the correct fix in this case?