Hi,

I am having issues with usage of cross-compilation toolchains withing Guix
shell. I am using toolchain created pretty much same as other cross toolchains
directly in Guix. The definition can be seen here:

  
https://gitlab.com/elektroline-predator/guix-channel/-/blob/master/gnu/packages/ellembedded.scm?ref_type=heads#L64

When I use this channel and create shell that contains both native and cross
toolchain then I get issues like this when cross-compiling:

  In file included from 
/gnu/store/1hnwdgx0irx58v97b25gl5fqfl8s5c9y-profile/include/features.h:548,
                 from 
/gnu/store/1hnwdgx0irx58v97b25gl5fqfl8s5c9y-profile/include/sys/cdefs.h:24,
                 from 
/gnu/store/1hnwdgx0irx58v97b25gl5fqfl8s5c9y-profile/arm-none-eabi/include/sys/reent.h:15,
                 from 
/gnu/store/1hnwdgx0irx58v97b25gl5fqfl8s5c9y-profile/arm-none-eabi/include/reent.h:93,
                 from ./misc/lib_impure.c:31:
  /gnu/store/1hnwdgx0irx58v97b25gl5fqfl8s5c9y-profile/include/gnu/stubs.h:7:11: 
fatal error: gnu/stubs-32.h: No such file or directory
    7 | # include <gnu/stubs-32.h>
      |           ^~~~~~~~~~~~~~~~

The compilation works once I remove gcc-toolchain from my environment. This is
clearly caused by injection of X86_64 headers to the profile with gcc-toolchain.

The issue is that my build system needs host's toolchain to compile its tools
thus I can't remove it from environment in general.

I have investigated it in more depth and discovered that I can demonstrate the
issue with the upstream gcc-cross-avr-toolchain:

  cynerd@ridcully:packages$ guix shell gcc-cross-avr-toolchain
  cynerd@ridcully:packages$ env | grep CROSS_C_INCLUDE
  
CROSS_C_INCLUDE_PATH=/gnu/store/212x0rz9cj0hgll8wida6vrg5w897by4-profile/include:/gnu/store/212x0rz9cj0hgll8wida6vrg5w897by4-profile/avr/include
  cynerd@ridcully:packages$ ls 
/gnu/store/212x0rz9cj0hgll8wida6vrg5w897by4-profile/include
  ctf-api.h  ctf.h  sframe-api.h  sframe.h
  cynerd@ridcully:packages$ exit
  cynerd@ridcully:packages$ guix shell gcc-cross-avr-toolchain gcc-toolchain
  cynerd@ridcully:packages$ env | grep CROSS_C_INCLUDE
  
CROSS_C_INCLUDE_PATH=/gnu/store/a301s9byb0gfxvdkhbda1kpn4akgkdlv-profile/include:/gnu/store/a301s9byb0gfxvdkhbda1kpn4akgkdlv-profile/avr/include
  cynerd@ridcully:packages$ ls 
/gnu/store/a301s9byb0gfxvdkhbda1kpn4akgkdlv-profile/include
  aio.h        assert.h        ctf.h          errno.h            fstab.h        
 ieee754.h        linux       net        netrose         pthread.h  scsi        
  stab.h         syscall.h    uchar.h     wctype.h
  aliases.h    bfd.h           ctype.h        error.h            fts.h          
 ifaddrs.h        locale.h    netash     nfs             pty.h      search.h    
  stdbit.h       sysexits.h   ucontext.h  wordexp.h
  alloca.h     bfdlink.h       diagnostics.h  execinfo.h         ftw.h          
 inttypes.h       malloc.h    netatalk   nl_types.h      pwd.h      semaphore.h 
  stdc-predef.h  syslog.h     ulimit.h    xen
  ansidecl.h   bits            dirent.h       fcntl.h            gconv.h        
 langinfo.h       math.h      netax25    nss.h           rdma       setjmp.h    
  stdint.h       tar.h        unistd.h
  a.out.h      byteswap.h      dis-asm.h      features.h         getopt.h       
 lastlog.h        mcheck.h    netdb.h    obstack.h       re_comp.h  
sframe-api.h  stdio_ext.h    termio.h     utime.h
  argp.h       c++             dlfcn.h        features-time64.h  glob.h         
 libcollector.h   memory.h    neteconet  paths.h         regex.h    sframe.h    
  stdio.h        termios.h    utmp.h
  argz.h       collectorAPI.h  drm            fenv.h             gnu            
 libfcollector.h  misc        netinet    plugin-api.h    regexp.h   sgtty.h     
  stdlib.h       tgmath.h     utmpx.h
  ar.h         complex.h       elf.h          finclude           gnu-versions.h 
 libgen.h         mntent.h    netipx     poll.h          regulator  shadow.h    
  string.h       thread_db.h  values.h
  arpa         config          endian.h       fmtmsg.h           grp.h          
 libintl.h        monetary.h  netiucv    printf.h        resolv.h   signal.h    
  strings.h      threads.h    video
  asm          cpio.h          envz.h         fnmatch.h          gshadow.h      
 limits.h         mqueue.h    netpacket  proc_service.h  rpc        sound       
  symcat.h       time.h       wait.h
  asm-generic  ctf-api.h       err.h          fpu_control.h      iconv.h        
 link.h           mtd         netrom     protocols       sched.h    spawn.h     
  sys            ttyent.h     wchar.h

The include paths are defined with generic ones before the platform specific
ones. All is consistent when gcc-toolchain is not included because compiler will
look into avr specific ones. But additional headers are introduced once
gcc-toolchain is introduced and they take precedence by design. But they are
configured for x86_64 and not for AVR (or ARM in my real case).

The hotfix would be to swap the order (prefer the platform specific ones), but
that is not correct fix at all. Some macros can still check if some header is
available and include it when it is. If that header is available on x86 but not
on AVR then it would be included in AVR build from x86. This feels like a bug
somewhere.

Does anyone have an idea what is the purpose of unified include directory and
how to keep the platform paths separate?

Thanks anyone for hints and help.
Karel Kočí

Attachment: signature.asc
Description: PGP signature

Reply via email to