From patchwork Tue Nov 21 03:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1866466 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xry111.site header.i=@xry111.site header.a=rsa-sha256 header.s=default header.b=F1UkRpcc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZ8Wf4NRTz1ySN for ; Tue, 21 Nov 2023 14:10:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 760C3385841E for ; Tue, 21 Nov 2023 03:10:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id C50293858D35 for ; Tue, 21 Nov 2023 03:10:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C50293858D35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C50293858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700536205; cv=none; b=D6zJNEQAr0yBQ4fj+w7wlHcnBlI39HXazYZOQU6TaOn3Jati+MqiBPxTDxxkiaYTQOspkW9JB6X19vblw0kPfiDpgHy0667apz0k8cIT3N0EXVjDT9rwazf36iK9JaOjLBfzuSAs01L8ZfCLcovl/6pZihdYq4dHujlWVHoT5yQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700536205; c=relaxed/simple; bh=d3nkUVNu6EoUv9WO5y1ha7/6ZQJRopTnEmb1DNIzMnA=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=CrwmSWcnItHw4hzdELLSLzSou2mLMJCnCvYPasAi5qE8+OAPVuotNER7xekhvEKio1gp6rr2t45oIxjJ6SqnrjN3pNvrtKuofbWWeoeLq60R68zCXdFqzBqBNXwSKjaUiwqk5QhICBr2DB1iMKReam/+a3WAy9RW9bsfnfpvfeQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1700536201; bh=d3nkUVNu6EoUv9WO5y1ha7/6ZQJRopTnEmb1DNIzMnA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=F1UkRpccFVu93lkpYpmH0yLJftwaBPz2Lb5j2MqsV+7XbLoX4wDB2UNhn0nw3smHd iY9qdRdirlkaafq0VWMd1t5l6G7gC0J+D3GMpr78JgvrUAIgaU4PU/yuCtTr9vuRRF JSIxWFKBCj2FYD9vbkdZFrt7EI/ZjvnrK8f6H5fk= Received: from [127.0.0.1] (unknown [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 1977366B3A; Mon, 20 Nov 2023 22:09:59 -0500 (EST) Message-ID: Subject: Pushed: LoongArch: Fix libgcc build failure when libc is not available (was Re: genopts: Add infrastructure to generate code for new features in ISA evolution) From: Xi Ruoyao To: Joseph Myers Cc: gcc-patches@gcc.gnu.org, chenglulu , i@xen0n.name, xuchenghua@loongson.cn Date: Tue, 21 Nov 2023 11:09:58 +0800 In-Reply-To: <0d3b2d5dc3a192952d03d874d2330759b9e97033.camel@xry111.site> References: <20231117204323.453536-1-xry111@xry111.site> <20231117204323.453536-3-xry111@xry111.site> <74823bfa-1b5c-1790-9fc6-ab97adc1a515@codesourcery.com> <0d3b2d5dc3a192952d03d874d2330759b9e97033.camel@xry111.site> Autocrypt: addr=xry111@xry111.site; prefer-encrypt=mutual; keydata=mDMEYnkdPhYJKwYBBAHaRw8BAQdAsY+HvJs3EVKpwIu2gN89cQT/pnrbQtlvd6Yfq7egugi0HlhpIFJ1b3lhbyA8eHJ5MTExQHhyeTExMS5zaXRlPoiTBBMWCgA7FiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQrKrSDhnnEOPHFgD8D9vUToTd1MF5bng9uPJq5y3DfpcxDp+LD3joA3U2TmwA/jZtN9xLH7CGDHeClKZK/ZYELotWfJsqRcthOIGjsdAPuDgEYnkdPhIKKwYBBAGXVQEFAQEHQG+HnNiPZseiBkzYBHwq/nN638o0NPwgYwH70wlKMZhRAwEIB4h4BBgWCgAgFiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwwACgkQrKrSDhnnEOPjXgD/euD64cxwqDIqckUaisT3VCst11RcnO5iRHm6meNIwj0BALLmWplyi7beKrOlqKfuZtCLbiAPywGfCNg8LOTt4iMD User-Agent: Evolution 3.50.1 MIME-Version: 1.0 X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org On Tue, 2023-11-21 at 08:00 +0800, Xi Ruoyao wrote: /* snip */ > > This has broken libgcc builds when target libc isn't yet available. > > > > In file included from /scratch/jmyers/glibc-bot/src/gcc/libgcc/../gcc/config/loongarch/loongarch-def.h:49, > >                  from /scratch/jmyers/glibc-bot/src/gcc/libgcc/../gcc/config/loongarch/loongarch-opts.h:24, > >                  from ../.././gcc/options.h:8, > >                  from ../.././gcc/tm.h:49, > >                  from /scratch/jmyers/glibc-bot/src/gcc/libgcc/libgcc2.c:29: > > /scratch/jmyers/glibc-bot/build/compilers/loongarch64-linux-gnu-lp64d/gcc-first/gcc/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory > >     9 | # include_next > >       |                ^~~~~~~~~~ > > compilation terminated. > > make[3]: *** [Makefile:505: _muldi3.o] Error 1 > > > > https://sourceware.org/pipermail/libc-testresults/2023q4/012109.html > > > > My guess would be that the definitions needing are not actually > > needed in code built for the target, and so there should be more > > > > #if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS) > > > > conditions like the one already present in loongarch-opts.h, to avoid > > depending on a target header like this being present. > > Ah, makes sense.  I thought stdint.h was usable without libc but it's > not true. > > The only use for stdint.h is in struct loongarch_isa (using int64_t for > a 64-bit bitset).  This struct is not used by target code. > > I'll test building a cross compiler from x86_64 with stdint.h and struct > loongarch_isa guarded with the ifdef. Pushed the attached patch r14-5634. Tested building a cross compiler from x86_64 with cross Binutils but not target libc. Also tested bootstrapping on loongarch64-linux-gnu. From d0faa1c8bad666c3e241d99871449aa60ccb8932 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Tue, 21 Nov 2023 09:09:25 +0800 Subject: [PATCH 7/7] LoongArch: Fix libgcc build failure when libc is not available To use int64_t we included in loongarch-def.h. Unfortunately, loongarch-def.h is also used by libgcc etc., causing a build failure when building a "stage1" cross compiler at which the target libc is not built yet. As int64_t is used for a C-compatible replacement of HOST_WIDE_INT, it's not directly or indirectly referred by the target libraries. So guard everything requiring stdint.h with #if then they'll not block target libraries. gcc/ChangeLog: * config/loongarch/loongarch-def.h (stdint.h): Guard with #if to exclude it for target libraries. (loongarch_isa_base_features): Likewise. (loongarch_isa): Likewise. (loongarch_abi): Likewise. (loongarch_target): Likewise. (loongarch_cpu_default_isa): Likewise. --- gcc/config/loongarch/loongarch-def.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h index af7bd635d6e..851ff864eb2 100644 --- a/gcc/config/loongarch/loongarch-def.h +++ b/gcc/config/loongarch/loongarch-def.h @@ -46,7 +46,10 @@ along with GCC; see the file COPYING3. If not see #ifndef LOONGARCH_DEF_H #define LOONGARCH_DEF_H +#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS) #include +#endif + #include "loongarch-tune.h" #ifdef __cplusplus @@ -62,9 +65,11 @@ extern const char* loongarch_isa_base_strings[]; #define ISA_BASE_LA64V110 1 #define N_ISA_BASE_TYPES 2 +#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS) /* Unlike other arrays, this is defined in loongarch-cpu.cc. The problem is we cannot use the C++ header options.h in loongarch-def.c. */ extern int64_t loongarch_isa_base_features[]; +#endif /* enum isa_ext_* */ extern const char* loongarch_isa_ext_strings[]; @@ -121,6 +126,7 @@ extern const char* loongarch_cmodel_strings[]; #define M_OPT_ABSENT(opt_enum) ((opt_enum) == M_OPT_UNSET) +#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS) /* Internal representation of the target. */ struct loongarch_isa { @@ -150,6 +156,9 @@ struct loongarch_target int cmodel; /* CMODEL_ */ }; +extern struct loongarch_isa loongarch_cpu_default_isa[]; +#endif + /* CPU properties. */ /* index */ #define CPU_NATIVE 0 @@ -162,7 +171,6 @@ struct loongarch_target /* parallel tables. */ extern const char* loongarch_cpu_strings[]; -extern struct loongarch_isa loongarch_cpu_default_isa[]; extern int loongarch_cpu_issue_rate[]; extern int loongarch_cpu_multipass_dfa_lookahead[]; -- 2.42.1