From owner-freebsd-toolchain@freebsd.org Wed Aug 12 11:42:04 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 429AA37D66D for ; Wed, 12 Aug 2020 11:42:04 +0000 (UTC) (envelope-from tijl@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4BRSV40ryDz3Xpb for ; Wed, 12 Aug 2020 11:42:04 +0000 (UTC) (envelope-from tijl@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id 1D23E37D3F6; Wed, 12 Aug 2020 11:42:04 +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 1CE5F37D562 for ; Wed, 12 Aug 2020 11:42:04 +0000 (UTC) (envelope-from tijl@freebsd.org) Received: from mailrelay106.isp.belgacom.be (mailrelay106.isp.belgacom.be [195.238.20.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "relay.skynet.be", Issuer "GlobalSign RSA OV SSL CA 2018" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BRSV3417tz3YB2; Wed, 12 Aug 2020 11:42:03 +0000 (UTC) (envelope-from tijl@freebsd.org) IronPort-SDR: YcoKsz0aeSad9lKH08LBFK8rFWiBHLn/ZNwZg3+w88g/gQGqSW/YTjNHHQCO/TVP9h0LFH/LaK 39xVfJzcGy77UClYLOybJwkZeVYUTbqreqLiq2EzlbPPvmKeCgTFSMJIM6LXL1MtNImps8cs8N N5c+4H2MUYljybccO1BH2TSubaOstJWSe0CCAQX/D1iVJjPeqFUSbhU6AS5YvBK/5rVi9clk0k g2bN1T1psTByQmT1PTGvAPwRMZW8pRSJcNRynRXBu0w1A4rjb6+/LcNisN16XBWA5r9nmugOeh IWQ= X-Belgacom-Dynamic: yes IronPort-PHdr: =?us-ascii?q?9a23=3Aw7PZaxfrQ2qpywuZj1u5VftTlGMj4u6mDksu8p?= =?us-ascii?q?Mizoh2WeGdxcW4YR7h7PlgxGXEQZ/co6odzbaP7eaxAydcuN6oizMrSNR0TR?= =?us-ascii?q?gLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ?= =?us-ascii?q?/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vLRi6twHcutcZjYZtN6o61w?= =?us-ascii?q?fErGZPd+lK321jOEidnwz75se+/Z5j9zpftvc8/MNeUqv0Yro1Q6VAADspL2?= =?us-ascii?q?466svrtQLeTQSU/XsTTn8WkhtTDAfb6hzxQ4r8vTH7tup53ymaINH2QLUpUj?= =?us-ascii?q?ms86tnVBnlgzoBOjUk8m/Yl9ZwgbpVrhyhuRJx3o3ab4ObNPVxYqzTcsgXRX?= =?us-ascii?q?ZDU8tLSyBNHp+wY5UJAuEcPehYtY79p14WoBWgAAusAP7kxyFPhn/xxq01ze?= =?us-ascii?q?EhHhvA3Aw7AtkDt2jUrNT3NKcWSu27zLPIwivdYP5LxDnz5pLEchc7ofGDRL?= =?us-ascii?q?99d9faxkYzGQ3flFqQtZDlMC2P1uQLq2WW8fRtWf+xh2M5pQx8ojiiyMcsh4?= =?us-ascii?q?TGiI8bxFPJ+Dt9zYs0J9C1SFJ2bMOkHpZQtCyXKZV7T80tTmxsuSs21LMItJ?= =?us-ascii?q?imdyYJ0JQq3x3SZ+Gdf4SW7R/vSPydLDh6iX5/Zb6ygxK//E69wePmTMa0yk?= =?us-ascii?q?xFri9dn9nJsXACygLc59CcSvt44kehwTGP1x3P6u1cIUA7i67bK5k5z74zjJ?= =?us-ascii?q?UTtUXDHirol0Xsi6+abFkk+umq6+TjeLnpupicN4hvig7gN6QhgMq/Af8iPg?= =?us-ascii?q?gJRWib9vyw1Lzl/ULnXLVHlv47nrTDvJzEKskXurS1DgBX34o59hqyCzOr3M?= =?us-ascii?q?wdnXYdLVJFfByHj5LuO1HLOP34Efa/g1aokDpwyfDGJKPuDYvWIXjYjbjtZ7?= =?us-ascii?q?F961RTyAYr19BQ+4pUCq0dIPL0QkLxqNvYDhg9MwOow+boEtR91oUFVGKBGK?= =?us-ascii?q?+WLr3dvkST5u0yOeWMY5UVuDnlIfg/+/HulWM5mUMafaSx3psXb2u4HuhnI0?= =?us-ascii?q?WaenXjnNMBHHwFvgo7VuPqiVmCXSRPaHa1WqI2/is7B56+DYffWoCth6SM0z?= =?us-ascii?q?2hHp1MYWBHBE2DHGzmd4WeRfgDdjmdItR8nTAeUrihUYAhhlmSs1rVz7dtZt?= =?us-ascii?q?LT4ioG/cbqzsJy+OH7mws/+DZvA4KayW7bHE9umWZde9gylIt4pldwz16Fyu?= =?us-ascii?q?Asn/1aEfR9/f5EeDwWc5nGwLopWJjJRgvdc4LRGx6dSdK8DGRpQw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2BrAgBE1DNf/8cv8FFgHAEBAQEBAQc?= =?us-ascii?q?BARIBAQQEAQFAB4EyBAEBCwEBgwNoAUkVjTeGC4IQiwaJYIcrCwEBAQEBAQE?= =?us-ascii?q?BATcEAQGETAKCNSU3Bg4CAwEBAQMCBQEBBgEBAQEBAQUEAYYPRUMBAQQLAYF?= =?us-ascii?q?iIoMZAQU6HCMQCw4KLlcGExuGDLJigTSFUoN4gQWBOAGNKYIAhCE+ijQEkj6?= =?us-ascii?q?IXZsNgmyaCjCgFS2zR4F7TTAIgyRQGQ2caD8DMDcCBggBAQMJgm2CNYttAQE?= X-IPAS-Result: =?us-ascii?q?A2BrAgBE1DNf/8cv8FFgHAEBAQEBAQcBARIBAQQEAQFAB?= =?us-ascii?q?4EyBAEBCwEBgwNoAUkVjTeGC4IQiwaJYIcrCwEBAQEBAQEBATcEAQGETAKCN?= =?us-ascii?q?SU3Bg4CAwEBAQMCBQEBBgEBAQEBAQUEAYYPRUMBAQQLAYFiIoMZAQU6HCMQC?= =?us-ascii?q?w4KLlcGExuGDLJigTSFUoN4gQWBOAGNKYIAhCE+ijQEkj6IXZsNgmyaCjCgF?= =?us-ascii?q?S2zR4F7TTAIgyRQGQ2caD8DMDcCBggBAQMJgm2CNYttAQE?= Received: from 199.47-240-81.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([81.240.47.199]) by relay.skynet.be with ESMTP; 12 Aug 2020 13:42:01 +0200 Received: from localhost (localhost [127.0.0.1]) by kalimero.tijl.coosemans.org (8.16.1/8.16.1) with ESMTP id 07CBfxSB087728; Wed, 12 Aug 2020 13:42:00 +0200 (CEST) (envelope-from tijl@FreeBSD.org) Date: Wed, 12 Aug 2020 13:41:58 +0200 From: =?UTF-8?B?VMSzbA==?= Coosemans To: Gleb Popov Cc: Konstantin Belousov , toolchain@freebsd.org Subject: Re: Undefined reference to __atomic_store_8 Message-ID: <20200812134158.249dc5ca@FreeBSD.org> In-Reply-To: References: <20200807212855.GB2551@kib.kiev.ua> <20200808133000.GC2551@kib.kiev.ua> <20200809143742.430764e7@FreeBSD.org> <20200809154312.GH2551@kib.kiev.ua> <20200811235210.41049ad1@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4BRSV3417tz3YB2 X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [0.00 / 15.00]; ASN(0.00)[asn:5432, ipnet:195.238.0.0/19, country:BE]; local_wl_from(0.00)[freebsd.org] 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 11:42:04 -0000 On Wed, 12 Aug 2020 09:44:25 +0400 Gleb Popov wrote: > On Wed, Aug 12, 2020 at 9:21 AM Gleb Popov wrote: >> 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? > > I just noticed that Clang emits these warnings (and the call instruction) > only for functions handling StgWord64 type. For the same code with > StgWord32, like > > StgWord > hs_atomicread32(StgWord x) > { > #if HAVE_C11_ATOMICS > return __atomic_load_n((StgWord32 *) x, __ATOMIC_SEQ_CST); > #else > return __sync_add_and_fetch((StgWord32 *) x, 0); > #endif > } > > no warning is emitted as well as no call. > > How does clang infer alignment in these cases? What's so special about > StgWord64? StgWord64 is uint64_t which is unsigned long long which is 4 byte aligned on i386. Clang wants 8 byte alignment to use the fildll instruction. You could change the definition of the StgWord64 type to look like: typedef uint64_t StgWord64 __attribute__((aligned(8))); But this only works if all calls to hs_atomicread64 pass a StgWord64 as argument and not some other 64 bit value. Another solution I already mentioned in a previous message: replace HAVE_C11_ATOMICS with 0 in hs_atomicread64 so it uses __sync_add_and_fetch instead of __atomic_load_n. That uses the cmpxchg8b instruction which doesn't care about alignment. It's much slower but I guess 64 bit atomic loads are rare enough that this doesn't matter much.