From owner-freebsd-toolchain@freebsd.org Thu Aug 13 13:39:15 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 7F7DA37A2D6 for ; Thu, 13 Aug 2020 13:39:15 +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 4BS72q218Cz4JqT for ; Thu, 13 Aug 2020 13:39:15 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id 44FCC37A2D5; Thu, 13 Aug 2020 13:39:15 +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 44C2B37A34B for ; Thu, 13 Aug 2020 13:39:15 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 4BS72p3HVTz4JqS; Thu, 13 Aug 2020 13:39:14 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: by mail-lj1-f179.google.com with SMTP id v12so6205851ljc.10; Thu, 13 Aug 2020 06:39:14 -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=yClLALqjsfOMGC6vW1zSKn+Vj8kN8tqKRuyH9sf48Us=; b=cJtnvDLBz3i7X/29o5MIaOeEHchwLAUY3OrA2J6C494H6pnDkvq21Utm6KwVFnOfmz l+XvBfPNLvlKLUHM9wtxSrc2a4i8qfM9fYePODmzKQygR99LuhyBY1oU/HCdaR3U79M1 mdGxqkMbUew5JEKURoXWUfyjUKbOfpGZKQI0CzJtDNOlSpVz9I20gE4mzOKdbgxnRUEq EQ42BAh3xEyunIZpZzE4W8L8WMEvEnYLVliv0Yf6I4E5jls+2fwr4DVdPxkvbfrsdFgV KLON0R+rhIN9pkjbj6NYPyF+8SpHR8SLRRWmeS9u53BRR/uO5hTSL2FPr2l13nACj6xa Nvbw== X-Gm-Message-State: AOAM530eKB+NCG4lbrZMcgcM+hiOjEu0qsGRcgnxfbWRBHeMY+A8wycd 6CNL3zWDpfH7RBec7VIwhdniPBSeGQA= X-Google-Smtp-Source: ABdhPJzeNQLrNTfiyopNPWSckPJtyQA0oAPsqS39r0IKywkYaGrp42I3IBm8PrPSV+tTx+ZamxMwxQ== X-Received: by 2002:a2e:9111:: with SMTP id m17mr2312003ljg.263.1597325952451; Thu, 13 Aug 2020 06:39:12 -0700 (PDT) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id r14sm1108514ljm.92.2020.08.13.06.39.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Aug 2020 06:39:12 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id h19so6194203ljg.13; Thu, 13 Aug 2020 06:39:12 -0700 (PDT) X-Received: by 2002:a2e:b0db:: with SMTP id g27mr2192513ljl.69.1597325951783; Thu, 13 Aug 2020 06:39:11 -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> <20200812134158.249dc5ca@FreeBSD.org> In-Reply-To: <20200812134158.249dc5ca@FreeBSD.org> From: Gleb Popov Date: Thu, 13 Aug 2020 17:38:41 +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: 4BS72p3HVTz4JqS X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of 6yearold@gmail.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=6yearold@gmail.com X-Spamd-Result: default: False [-1.28 / 15.00]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[freebsd.org]; NEURAL_HAM_LONG(-0.94)[-0.941]; NEURAL_SPAM_SHORT(0.43)[0.429]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.208.179:from]; NEURAL_HAM_MEDIUM(-0.77)[-0.772]; FORGED_SENDER(0.30)[arrowd@freebsd.org,6yearold@gmail.com]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.208.179:from]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[arrowd@freebsd.org,6yearold@gmail.com]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FREEMAIL_CC(0.00)[gmail.com,freebsd.org] 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: Thu, 13 Aug 2020 13:39:15 -0000 On Wed, Aug 12, 2020 at 3:42 PM T=C4=B3l Coosemans wrote= : > 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/atom= ic.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/atom= ic.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 t= he > >> correct fix in this case? > > > > I just noticed that Clang emits these warnings (and the call instructio= n) > > 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. > Yep, your suggested workaround worked, many thanks. Still, I'm curious where I can get __atomic_load_n in an i386 case, if I don't want to pull in gcc?