guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Making cross-gcc work for all gcc versions


From: Carl Dong
Subject: Making cross-gcc work for all gcc versions
Date: Fri, 03 May 2019 16:31:47 +0000

Hi all,

I believe that riscv64-linux-gnu support came in gcc 7.1, which is an
architecture we plan to support for bitcoin core's releases. In my experiments
with cross-gcc, I've successfully created cross-gcc's for the default gcc (v5 I
think) for x86_64, i686, aarch64, and armhf. However, cross-gcc doesn't work for
the following configurations:

x86_64, i686 for gcc-6 and gcc-7
Any arch for gcc-8

One can replicate this experiment easily by creating a guix-work.scm like so:

```guile
(define-module (guix-work)
  #:use-module (gnu packages cross-base)
  #:use-module (gnu packages gcc))

(define (xgcc gcc-pkg triplet)
  (cross-gcc triplet
             #:xgcc gcc-pkg
             #:xbinutils (cross-binutils triplet)
             #:libc (cross-libc triplet)))

(define-public xgcc-8-x86_64  (xgcc gcc-8 "x86_64-linux-gnu"))
(define-public xgcc-8-i686    (xgcc gcc-8 "i686-linux-gnu"))
(define-public xgcc-8-aarch64 (xgcc gcc-8 "aarch64-linux-gnu"))
(define-public xgcc-8-armhf   (xgcc gcc-8 "arm-linux-gnueabihf"))

(define-public xgcc-7-x86_64  (xgcc gcc-7 "x86_64-linux-gnu"))
(define-public xgcc-7-i686    (xgcc gcc-7 "i686-linux-gnu"))
(define-public xgcc-7-aarch64 (xgcc gcc-7 "aarch64-linux-gnu"))
(define-public xgcc-7-armhf   (xgcc gcc-7 "arm-linux-gnueabihf"))

(define-public xgcc-6-x86_64  (xgcc gcc-6 "x86_64-linux-gnu"))
(define-public xgcc-6-i686    (xgcc gcc-6 "i686-linux-gnu"))
(define-public xgcc-6-aarch64 (xgcc gcc-6 "aarch64-linux-gnu"))
(define-public xgcc-6-armhf   (xgcc gcc-6 "arm-linux-gnueabihf"))

(define-public xgcc-5-x86_64  (xgcc gcc-5 "x86_64-linux-gnu"))
(define-public xgcc-5-i686    (xgcc gcc-5 "i686-linux-gnu"))
(define-public xgcc-5-aarch64 (xgcc gcc-5 "aarch64-linux-gnu"))
(define-public xgcc-5-armhf   (xgcc gcc-5 "arm-linux-gnueabihf"))
```

And invoking:

```
guix build --keep-going \
           --keep-failed \
           --no-grafts \
           --max-jobs=(nproc) \
           --load-path=. \
     gcc-cross-{{x86_64,i686,aarch64}-linux-gnu,address@hidden,6,7,8}
```

Digging thru the logs for gcc-8, it seems that we need to add a
gcc-8-cross-environment-variables.patch just like we did for gcc-6.

Here's what I came up with:

```diff
diff --git a/gcc/gcc.c b/gcc/gcc.c
index a716f708259..dc7862f413a 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4342,7 +4342,7 @@ process_command (unsigned int decoded_options_count,
     }

   temp = env.get (LIBRARY_PATH_ENV);
-  if (temp && *cross_compile == '0')
+  if (temp)
     {
       const char *startp, *endp;
       char *nstore = (char *) alloca (strlen (temp) + 3);
diff --git a/gcc/incpath.c b/gcc/incpath.c
index b11c6a57939..a66a94a04e5 100644
--- a/gcc/incpath.c
+++ b/gcc/incpath.c
@@ -472,8 +472,8 @@ register_include_chains (cpp_reader *pfile, const char 
*sysroot,
                         int stdinc, int cxx_stdinc, int verbose)
 {
   static const char *const lang_env_vars[] =
-    { "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH",
-      "OBJC_INCLUDE_PATH", "OBJCPLUS_INCLUDE_PATH" };
+    { "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH",
+      "CROSS_OBJC_INCLUDE_PATH", "CROSS_OBJCPLUS_INCLUDE_PATH" };
   cpp_options *cpp_opts = cpp_get_options (pfile);
   size_t idx = (cpp_opts->objc ? 2: 0);

@@ -484,7 +484,7 @@ register_include_chains (cpp_reader *pfile, const char 
*sysroot,

   /* CPATH and language-dependent environment variables may add to the
      include chain.  */
-  add_env_var_paths ("CPATH", INC_BRACKET);
+  add_env_var_paths ("CROSS_CPATH", INC_BRACKET);
   add_env_var_paths (lang_env_vars[idx], INC_SYSTEM);

   target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);
diff --git a/gcc/system.h b/gcc/system.h
index 4abc321c71d..d6186476024 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -1209,4 +1209,6 @@ helper_const_non_const_cast (const char *p)
 void qsort_chk (void *, size_t, size_t, int (*)(const void *, const void *));
 #endif

+#define LIBRARY_PATH_ENV "CROSS_LIBRARY_PATH"
+
 #endif /* ! GCC_SYSTEM_H */
diff --git a/gcc/tlink.c b/gcc/tlink.c
index ec20bd2fa0f..cd17bdce004 100644
--- a/gcc/tlink.c
+++ b/gcc/tlink.c
@@ -456,7 +456,7 @@ recompile_files (void)
   file *f;

   putenv (xstrdup ("COMPILER_PATH="));
-  putenv (xstrdup ("LIBRARY_PATH="));
+  putenv (xstrdup (LIBRARY_PATH_ENV "="));

   while ((f = file_pop ()) != NULL)
     {
```

However, even after adding this patch the build fails for reasons that are
beyond me. I'd appreciate any help I can get on making cross-gcc work with 
gcc-8.

Cheers,
Carl Dong
address@hidden
"I fight for the users"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]