From nobody Fri Sep 3 11:29:01 2021 X-Original-To: freebsd-ports@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 08F3E17A0286 for ; Fri, 3 Sep 2021 11:29:05 +0000 (UTC) (envelope-from SRS0=snGT=NZ=klop.ws=ronald-lists@realworks.nl) Received: from smtp-relay-int.realworks.nl (smtp-relay-int.realworks.nl [194.109.157.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4H1FtR6rPLz4Qx8; Fri, 3 Sep 2021 11:29:03 +0000 (UTC) (envelope-from SRS0=snGT=NZ=klop.ws=ronald-lists@realworks.nl) Date: Fri, 3 Sep 2021 13:29:01 +0200 (CEST) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=klop.ws; s=rw1; t=1630668541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vUS0TVkqSVg3bjQq8BfO/nOKEIhVe7jfUKjUWSQK9r8=; b=DacRckjw3AB8JwMM/8S10VxVXdHenV/J9Z0AczLbr++D3ZTwlbGFEb0PEg1O16c24cc/Im 9YVK3wd3N2/rxNAw== From: Ronald Klop To: mmel@freebsd.org Cc: Ed Maste , Michal Meloun , FreeBSD Ports , Dimitry Andric Message-ID: <1572411201.2.1630668541601@mailrelay> In-Reply-To: References: <2089802880.12287.1627193420123@localhost> <671841132.16.1630657914506@mailrelay> Subject: Re: (solved) Re: undefined symbol: __aarch64_ldadd8_acq_rel since llvm12 (mongodb44) List-Id: Porting software to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-ports List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-ports@freebsd.org X-BeenThere: freebsd-ports@freebsd.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_1_7604650.1630668541575" X-Mailer: Realworks (575.792.df76b4d) Importance: Normal X-Priority: 3 (Normal) X-Rspamd-Queue-Id: 4H1FtR6rPLz4Qx8 X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=klop.ws header.s=rw1 header.b=DacRckjw; dmarc=pass (policy=none) header.from=klop.ws; spf=pass (mx1.freebsd.org: domain of "SRS0=snGT=NZ=klop.ws=ronald-lists@realworks.nl" designates 194.109.157.24 as permitted sender) smtp.mailfrom="SRS0=snGT=NZ=klop.ws=ronald-lists@realworks.nl" X-Spamd-Result: default: False [-3.20 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[klop.ws:s=rw1]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:194.109.157.0/24]; NEURAL_HAM_LONG(-1.00)[-1.000]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[multipart/mixed,multipart/alternative,text/plain,text/x-diff]; HAS_ATTACHMENT(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_SHORT(-1.00)[-1.000]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[klop.ws:+]; DMARC_POLICY_ALLOW(-0.50)[klop.ws,none]; HAS_X_PRIO_THREE(0.00)[3]; RCVD_IN_DNSWL_NONE(0.00)[194.109.157.24:from]; FORGED_SENDER(0.30)[ronald-lists@klop.ws,SRS0=snGT=NZ=klop.ws=ronald-lists@realworks.nl]; RCVD_COUNT_ZERO(0.00)[0]; RWL_MAILSPIKE_POSSIBLE(0.00)[194.109.157.24:from]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:~,4:+]; MID_RHS_NOT_FQDN(0.50)[]; ASN(0.00)[asn:3265, ipnet:194.109.0.0/16, country:NL]; FROM_NEQ_ENVFROM(0.00)[ronald-lists@klop.ws,SRS0=snGT=NZ=klop.ws=ronald-lists@realworks.nl]; FREEMAIL_CC(0.00)[freebsd.org,gmail.com,FreeBSD.org] X-ThisMailContainsUnwantedMimeParts: Y ------=_Part_1_7604650.1630668541575 Content-Type: multipart/alternative; boundary="----=_Part_0_1554005313.1630668541475" ------=_Part_0_1554005313.1630668541475 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Van: Michal Meloun Datum: vrijdag, 3 september 2021 12:02 Aan: Dimitry Andric , Ronald Klop CC: FreeBSD Ports , Ed Maste Onderwerp: Re: (solved) Re: undefined symbol: __aarch64_ldadd8_acq_rel since llvm12 (mongodb44) > > > > On 03.09.2021 11:08, Dimitry Andric wrote: > > On 3 Sep 2021, at 10:31, Ronald Klop wrote: > >> > >> Van: Ronald Klop > >> Datum: zondag, 25 juli 2021 08:10 > >> Aan: FreeBSD Ports , Michal Meloun , Dimitry Andric > >> Onderwerp: (solved) Re: undefined symbol: __aarch64_ldadd8_acq_rel since llvm12 (mongodb44) > >> > >> Van: Dimitry Andric > >> Datum: 19 juli 2021 11:01 > >> Aan: Ronald Klop > >> CC: FreeBSD Ports , Michal Meloun > >> Onderwerp: Re: undefined symbol: __aarch64_ldadd8_acq_rel since llvm12 (mongodb44) > >> > >>> > >>> > >>> On 19 Jul 2021, at 09:29, Ronald Klop wrote: > >>>>>> Does anybody have a clue why I get this error since clang 12 on aarch64/arm64? > >>>> Do other ports have the same issue? > >>>>>> Regards, > >>>> Ronald. > >>>>>> Van: Ronald Klop > >>>> Datum: vrijdag, 16 juli 2021 09:43 > >>>> Aan: freebsd-arm@freebsd.org > >>>> Onderwerp: undefined symbol: __aarch64_ldadd8_acq_rel since llvm12 (mongodb44) > >>>>> Hi, > >>>>> I'm also maintaining databases/mongodb44 and this gives undefined symbols since llvm12 (I think). > >>>>> See: http://www.ipv6proxy.net/go.php?u=http://ampere2.nyi.freebsd.org/data/main-arm64-default/pf44e1c1de734_s63ca9ea4f3/logs/errors/mongodb44-4.4.6.log > >>>>> And look for: > >>>>> ld.lld: error: undefined symbol: __aarch64_ldadd8_acq_rel > >>>>> There are a bunch of similar symbols not found while linking. > >>>>> This compiles fine using llvm11 or on amd64. > >>> > >>> It turns out clang 12 now enables -moutline-atomics by default, but we > >>> don't yet expose the necessary functions from compiler-rt. As a > >>> temporary workaround, compile with -mno-outline-atomics. Meanwhile, > >>> adding these functions to the compiler-rt lib is on my TODO list. > > ... > >> Hi Dimitry, > >> > >> I upgraded my poudriere and tried building mongodb50 with -moutline-atomics enabled. > >> [00:00:56] Host OSVERSION: 1400032 > >> [00:00:56] Jail OSVERSION: 1400032 > >> ... > >> > >> [09:33:20] ld.lld: error: undefined hidden symbol: __aarch64_have_lse_atomics > >> [09:33:20] >>> referenced by outline_atomic_cas1_1.S:121 > >> [09:33:20] >>> outline_atomic_cas1_1.o:(__aarch64_cas1_relax) in archive /usr/lib/libgcc.a > >> [09:33:20] >>> referenced by outline_atomic_cas1_1.S:121 > >> [09:33:20] >>> outline_atomic_cas1_1.o:(__aarch64_cas1_relax) in archive /usr/lib/libgcc.a > >> [09:33:20] >>> referenced by outline_atomic_cas1_2.S:121 > >> [09:33:20] >>> outline_atomic_cas1_2.o:(__aarch64_cas1_acq) in archive /usr/lib/libgcc.a > >> [09:33:20] >>> referenced 57 more times > >> [09:33:20] c++: error: linker command failed with exit code 1 (use -v to see invocation) > >> [09:33:22] scons: *** [build/opt/mongo/shell/mongo] Error 1 > >> [09:33:58] ld.lld: error: undefined hidden symbol: __aarch64_have_lse_atomics > >> [09:33:58] >>> referenced by outline_atomic_cas1_1.S:121 > >> [09:33:58] >>> outline_atomic_cas1_1.o:(__aarch64_cas1_relax) in archive /usr/lib/libgcc.a > >> [09:33:58] >>> referenced by outline_atomic_cas1_1.S:121 > >> [09:33:58] >>> outline_atomic_cas1_1.o:(__aarch64_cas1_relax) in archive /usr/lib/libgcc.a > >> [09:33:58] >>> referenced by outline_atomic_cas1_2.S:121 > >> [09:33:58] >>> outline_atomic_cas1_2.o:(__aarch64_cas1_acq) in archive /usr/lib/libgcc.a > >> [09:33:58] >>> referenced 57 more times > >> [09:33:59] c++: error: linker command failed with exit code 1 (use -v to see invocation) > >> [09:33:59] scons: *** [build/opt/mongo/db/mongod] Error 1 > > > > It turns out that this function is defined in > > contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c, which we have > > compiled only for x86 until now. But upstream added the > > __aarch64_have_lse_atomics symbol and an initialization function for it. > > > > I tried simply enabling this file for the libcompiler-rt build on > > aarch64, but it turns out that the implementation is rather Linuxy, and > > does not compile on FreeBSD: > > > > contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c:778:25: error: implicit declaration of function 'getauxval' is invalid in C99 [-Werror,-Wimplicit-function-declaration] > > unsigned long hwcap = getauxval(AT_HWCAP); > > ^ > > 1 error generated. > > > > The implementation looks like: > > > > // LSE support detection for out-of-line atomics > > // using HWCAP and Auxiliary vector > > _Bool __aarch64_have_lse_atomics > > __attribute__((visibility("hidden"), nocommon)); > > #if defined(__has_include) > > #if __has_include() > > #include > > #ifndef AT_HWCAP > > #define AT_HWCAP 16 > > #endif > > #ifndef HWCAP_ATOMICS > > #define HWCAP_ATOMICS (1 << 8) > > #endif > > static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) { > > unsigned long hwcap = getauxval(AT_HWCAP); > > __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0; > > } > > > > but in FreeBSD we don't have getauxval(), and I'm unsure if AT_HWCAP > > works on aarch64. > > > > As this is all outside my domain of knowledge I'd appreciate if somebody > > knows how to retrieve this information on our AArch64 implementation. :) > > > > -Dimitry > > > > We already have elf_aux_info(3) as counterpart to getauxval() and AT_HWCAP and AT_HWCAP2 are supported on arm64 as well, so the fix is trivial. > I'll try do it over the weekend, but I'm having some weird HW issues on my build box so, I'm not sure if it will be possible... > > Michal > > > Hi, Dusted off my rusty C skills and came up with a patch. I hope the attachment comes through. It is currently building mongodb again to see if poudriere becomes happy. Will report back in a couple of hours. Regards, Ronald. ------=_Part_0_1554005313.1630668541475-- ------=_Part_1_7604650.1630668541575 Content-Type: text/x-diff; charset=us-ascii; name=aarch64_have_lse_atomics.diff Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=aarch64_have_lse_atomics.diff diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c b/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c index 51bedd98c3..4691a4dc98 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c @@ -761,6 +761,7 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) { return 0; } #elif defined(__aarch64__) +#include // LSE support detection for out-of-line atomics // using HWCAP and Auxiliary vector _Bool __aarch64_have_lse_atomics @@ -775,7 +776,15 @@ _Bool __aarch64_have_lse_atomics #define HWCAP_ATOMICS (1 << 8) #endif static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) { - unsigned long hwcap = getauxval(AT_HWCAP); + u_long hwcap; + int error; + + error = elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); + if (error != 0) { + warnc(error, "%s:%u: elf_aux_info failed", __FILE__, __LINE__); + return; + } + __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0; } #endif // defined(__has_include) diff --git a/lib/libcompiler_rt/Makefile.inc b/lib/libcompiler_rt/Makefile.inc index aa0a6a6c9e..4e5e1323d3 100644 --- a/lib/libcompiler_rt/Makefile.inc +++ b/lib/libcompiler_rt/Makefile.inc @@ -147,7 +147,7 @@ SRCF+= floatundixf .endif # __cpu_model support, only used on x86 -.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" +.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "aarch64" SRCF+= cpu_model .endif ------=_Part_1_7604650.1630668541575--