public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, chenglulu <chenglulu@loongson.cn>,
	i@xen0n.name,  xuchenghua@loongson.cn
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)
Date: Tue, 21 Nov 2023 11:09:58 +0800	[thread overview]
Message-ID: <a1fe7bb89af19e0cb17386057431ffa4e908b8ff.camel@xry111.site> (raw)
In-Reply-To: <0d3b2d5dc3a192952d03d874d2330759b9e97033.camel@xry111.site>

[-- Attachment #1: Type: text/plain, Size: 2061 bytes --]

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 <stdint.h>
> >       |                ^~~~~~~~~~
> > 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 <stdint.h> 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.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

[-- Attachment #2: 0007-LoongArch-Fix-libgcc-build-failure-when-libc-is-not-.patch --]
[-- Type: text/x-patch, Size: 2820 bytes --]

From d0faa1c8bad666c3e241d99871449aa60ccb8932 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
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 <stdint.h> 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 <stdint.h>
+#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


  reply	other threads:[~2023-11-21  3:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 20:43 [PATCH v2 0/6] Add LoongArch v1.1 div32 and ld-seq-sa support Xi Ruoyao
2023-11-17 20:43 ` [PATCH v2 1/6] LoongArch: Fix internal error running "gcc -march=native" on LA664 Xi Ruoyao
2023-11-17 20:43 ` [PATCH v2 2/6] LoongArch: genopts: Add infrastructure to generate code for new features in ISA evolution Xi Ruoyao
2023-11-20 23:15   ` Joseph Myers
2023-11-21  0:00     ` Xi Ruoyao
2023-11-21  3:09       ` Xi Ruoyao [this message]
2023-11-21 14:16         ` 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) Jeff Law
2023-11-17 20:43 ` [PATCH v2 3/6] LoongArch: Add evolution features of base ISA revisions Xi Ruoyao
2023-11-17 20:43 ` [PATCH v2 4/6] LoongArch: Take the advantage of -mdiv32 if it's enabled Xi Ruoyao
2023-11-17 20:43 ` [PATCH v2 5/6] LoongArch: Don't emit dbar 0x700 if -mld-seq-sa Xi Ruoyao
2023-11-17 20:43 ` [PATCH v2 6/6] LoongArch: Add fine-grained control for LAM_BH and LAMCAS Xi Ruoyao
2023-11-18  8:13 ` [PATCH v2 0/6] Add LoongArch v1.1 div32 and ld-seq-sa support chenglulu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1fe7bb89af19e0cb17386057431ffa4e908b8ff.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=chenglulu@loongson.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=i@xen0n.name \
    --cc=joseph@codesourcery.com \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).