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: 167485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp368921vqb; Mon, 20 Nov 2023 19:10:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgyy9/El3O4DZQPsBaCP4rZ2DFRCKNPw2TxWueFuKdPBR/nr0n+tfIwdu+ossXfkCAlvpV X-Received: by 2002:ad4:596f:0:b0:658:23a5:e062 with SMTP id eq15-20020ad4596f000000b0065823a5e062mr10089946qvb.31.1700536229609; Mon, 20 Nov 2023 19:10:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700536229; cv=pass; d=google.com; s=arc-20160816; b=zq9WUk7SqRj6S2nKrDr7O9Kh3p2jCAqa8Xv2V3x1hgrM/EO/jIKd4OuMdFNgm57J/O Tx7PQJcuO4kbgqHT4X5InZfSU3JHvELEkHlrH1AfjvZ8xGFDGVKQTBBxFfxr4iVbApjC uOStTbvnuB4TCW4yXTHiGeqV2igLGXF4aN8K5lVeaJbFEASBIox/hDX0XEkQYGzgnAEq yJniScEHGBwW0Q45eM3Y76OXN5HohV4ThKa4i/wevTO1abGL8BVawE8RtPuPBuesgOee sjnSzyKlKKKAMMuX8rd7hPMgCiHyTGlon/cC7i9HUQeHH2HVGgqe/uBl+6urnphd75C0 fSUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=xeoQhlz4Nicuiqb1QykRISoQLp42udZnfSSH8W0wafE=; fh=r++wcGUPAF87n50Ae/Ofc86S8bwCogBYKsPxiwzULg4=; b=PXdm/b1IroqwXWp1IhO72JlQ/4UU6aAbt1AFOjcBz/NTD8gWXiv6RnNg+bXZtTM2R7 M6wy40/JzyAZ1iYQ/4dS9vxndQAHnSwBeFhFUqeD9W+BtHzgkTrTGz4hBrNwQEXDnPGO TPxiCM0peJr22ldwmlRlDToEAObY04Uk8c+egROWXOYN6t4hSAOxQU/lfTg0/6Dn/kq2 oZyy0mEoN2otVBgcjQLFjtAYzzgF8yad5iSyQpFJNIE2yV6vc6Erye9/Hkcu+mBzrMUw b1H73IVv4I981GwrdVpVM6g14h0+gcDCCeA6+q+4b5PIipNMoqOzuk9VCelcTmG066Tg YCVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=F1UkRpcc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id pe24-20020a056214495800b0064c6b7d96e1si8333510qvb.372.2023.11.20.19.10.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 19:10:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=F1UkRpcc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E356385842B for ; Tue, 21 Nov 2023 03:10:29 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783141477575904629 X-GMAIL-MSGID: 1783141477575904629 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