Subject: bug#30395: ‘gcc’ doesn't compile with LD_LIBRARY_PATH="$HOME/.guix-profile/lib"

From: Mathieu Lirzin <[email-masked]>
Date: Sat, 17 Feb 2018 20:02:22 +0100

Hello,

[email-masked] (Ludovic Courtès) writes:

> Mathieu Lirzin <[email-masked]> skribis:
>
>> After looking at the attached ‘strace’ log, as you initially guessed
>> this issue is that multiple GCC are loaded.  My ‘gcc-toolchain’ is using
>> GCC 7.3 and ‘glibc’ is referring to GCC 5.4.
>
> Normally ‘glibc’ does not contain references to ‘gcc’:
>
> $ guix size /gnu/store/3h31zsqxjjg52da5gp3qmhkh4x8klhah-glibc-2.25
> store item                                                       total    self
> /gnu/store/3h31zsqxjjg52da5gp3qmhkh4x8klhah-glibc-2.25              38.5    37.1  96.3%
> /gnu/store/zhrajv6qf2hzn9c3g2bb07559hyrz5xp-bash-static-4.4.12       1.4     1.4   3.7%
> total: 38.5 MiB

OK, My guess regarding the link between [email-masked] and [email-masked] was
solely based on the proximity in the order of ‘.so’ files opening.

--8<---------------cut here---------------start------------->8---
1382  open("/home/mthl/.guix-profile/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1382  open("/gnu/store/3v8z40rdvpbdpaccfqgvxkw1dnipc321-gmp-6.1.2/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1382  open("/gnu/store/3h31zsqxjjg52da5gp3qmhkh4x8klhah-glibc-2.25/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1382  open("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/tls/x86_64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1382  stat("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/tls/x86_64", 0x7ffec8dd5730) = -1 ENOENT (No such file or directory)
1382  open("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/tls/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1382  stat("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/tls", 0x7ffec8dd5730) = -1 ENOENT (No such file or directory)
1382  open("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/x86_64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1382  stat("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/x86_64", 0x7ffec8dd5730) = -1 ENOENT (No such file or directory)
1382  open("/gnu/store/6wyjls0q2c9gjskkplsr1ad09p3d8gzg-gcc-5.4.0-lib/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
--8<---------------cut here---------------end--------------->8---

Even if it was effective in term of solving my specific issue, it was
really not a rigorous analysis.

>> After removing ‘glibc’ and from my profile calling ‘gcc’ completes, so I
>> don't need to install ‘binutils’ in my profile anymore.
>
> I don’t get it yet.  The log shows this:
>
> 9543  execve("/gnu/store/x7i79rihhdjkps5fx0f9p2q0svh5a88n-guile-2.2.2/bin/guile", ["/gnu/store/x7i79rihhdjkps5fx0f9p"..., "-c", "(load-compiled \"/gnu/store/w27in"..., "-plugin", "/gnu/store/xjpchnxm9fgg05fqm9apy"..., "-plugin-opt=/gnu/store/xjpchnxm9"..., "-plugin-opt=-fresolution=/tmp/cc"..., "-plugin-opt=-pass-through=-lgcc", "-plugin-opt=-pass-through=-lgcc_"..., "-plugin-opt=-pass-through=-lgcc_"..., "-plugin-opt=-pass-through=-lc", "-plugin-opt=-pass-through=-lgcc", "-plugin-opt=-pass-through=-lgcc_"..., "--eh-frame-hdr", "-m", "elf_x86_64", "-dynamic-linker", "/gnu/store/3h31zsqxjjg52da5gp3qm"..., "/gnu/store/0qg64bwn2z3g91b5iw16i"..., "/gnu/store/0qg64bwn2z3g91b5iw16i"..., "/gnu/store/45rhjm5ryms10frcyrzcd"..., "-L/gnu/store/0qg64bwn2z3g91b5iw1"..., "-L/gnu/store/45rhjm5ryms10frcyrz"..., "-L/gnu/store/45rhjm5ryms10frcyrz"..., "-L/gnu/store/3h31zsqxjjg52da5gp3"..., "/tmp/cc9aj9M2.o", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "-L/gnu/store/3h31zsqxjjg52da5gp3"..., "-rpath=/gnu/store/3h31zsqxjjg52d"..., ...], 0x113a520 /* 31 vars */) = 0
>
> 9543  open("/home/mthl/.guix-profile/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
>
> 9543  write(2, "Uncaught exception:\n", 20) = 20
> 9543  futex(0x7f5d453c6930, FUTEX_WAKE_PRIVATE, 2147483647) = 0
> 9543  futex(0x7f5d43ab0190, FUTEX_WAKE_PRIVATE, 2147483647) = 0
> 9543  close(3)                          = 0
> 9543  close(4)                          = 0
> 9543  munmap(0x7f5d455e8000, 4096)      = 0
> 9543  exit(0)                           = ?
> 9539  <... wait4 resumed> 0xcddb20, 0, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> 9539  --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} ---
>
> This is the execution of ld-wrapper and it terminates with “Uncaught
> exception”, which isn’t really helpful.  Apparently this happens before
> ‘boot-9.scm’ was even search for.
>
> Can you reproduce it by running ‘ld’ directly in that environment?  Or
> better yet, by running ‘guile’?  The next thing is to try and do that
> in gdb…

Yes I can reproduce simply by running ‘guile’ (v2.2.2 and v2.2.3).  :-)

--8<---------------cut here---------------start------------->8---
LD_LIBRARY_PATH="$HOME/.guix-profile/lib" guile
Uncaught exception:
Throw to key encoding-error with args ("scm_to_stringn" "cannot convert
narrow string to output locale" 22 #f #f)
--8<---------------cut here---------------end--------------->8---

I have tried to set LC_ALL=C, but this doesn't have any impact.  Here
are the outputs of ‘LD_LIBRARY_PATH="$HOME/.guix-profile/lib" strace -f
-s 1000 -o OUTPUT guile’ for the failing environment with [email-masked] in
the profile:

and when glibc is removed from the profile:

I have tried to first debug ‘guile’ with ‘gdb’. Since it crashes, I
don't know to get any backtrace from it.  However I have noticed that
since ‘gdb’ itself is linked with libguile and suffers from the same
problem with LD_LIBRARY_PATH improperly set, but doesn't crash.  So I
have run the following:

--8<---------------cut here---------------start------------->8---
mthl@godel ~/src/guile$ gdb gdb
[...]
Reading symbols from gdb...(no debugging symbols found)...done.
(gdb) set environment LD_LIBRARY_PATH /home/mthl/.guix-profile/lib
(gdb) run
Starting program: /gnu/store/ly635xcgaqwb6brmwhf5d71fvcbz5dpc-profile/bin/gdb 
warning: the debug information found in "/home/mthl/.guix-profile/lib/debug//gnu/store/38kr8xi7nib8rx8xr4gi0w0d8knyca3k-glibc-2.25/lib/libdl-2.25.so.debug" does not match "/home/mthl/.guix-profile/lib/libdl.so.2" (CRC mismatch).

warning: File "/gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22.8.1-gdb.scm" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
	add-auto-load-safe-path /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22.8.1-gdb.scm
line to your configuration file "/home/mthl/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/home/mthl/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
warning: the debug information found in "/home/mthl/.guix-profile/lib/debug//gnu/store/38kr8xi7nib8rx8xr4gi0w0d8knyca3k-glibc-2.25/lib/libpthread-2.25.so.debug" does not match "/home/mthl/.guix-profile/lib/libpthread.so.0" (CRC mismatch).

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/gnu/store/3h31zsqxjjg52da5gp3qmhkh4x8klhah-glibc-2.25/lib/libthread_db.so.1".
warning: the debug information found in "/home/mthl/.guix-profile/lib/debug//gnu/store/38kr8xi7nib8rx8xr4gi0w0d8knyca3k-glibc-2.25/lib/libutil-2.25.so.debug" does not match "/home/mthl/.guix-profile/lib/libutil.so.1" (CRC mismatch).

warning: the debug information found in "/home/mthl/.guix-profile/lib/debug//gnu/store/38kr8xi7nib8rx8xr4gi0w0d8knyca3k-glibc-2.25/lib/libm-2.25.so.debug" does not match "/home/mthl/.guix-profile/lib/libm.so.6" (CRC mismatch).

warning: the debug information found in "/home/mthl/.guix-profile/lib/debug//gnu/store/38kr8xi7nib8rx8xr4gi0w0d8knyca3k-glibc-2.25/lib/libc-2.25.so.debug" does not match "/home/mthl/.guix-profile/lib/libc.so.6" (CRC mismatch).

warning: the debug information found in "/home/mthl/.guix-profile/lib/debug//gnu/store/38kr8xi7nib8rx8xr4gi0w0d8knyca3k-glibc-2.25/lib/libcrypt-2.25.so.debug" does not match "/home/mthl/.guix-profile/lib/libcrypt.so.1" (CRC mismatch).

[New Thread 0x7ffff4bd6700 (LWP 21942)]
[New Thread 0x7ffff4385700 (LWP 21943)]
[New Thread 0x7ffff3b34700 (LWP 21944)]
Throw without catch before boot:
Throw to key encoding-error with args ("scm_to_stringn" "cannot convert narrow string to output locale" 22 #f #f)Aborting.

Thread 1 "gdb" received signal SIGABRT, Aborted.
0x00007ffff5d052c4 in raise () from /home/mthl/.guix-profile/lib/libc.so.6
(gdb) bt
#0  0x00007ffff5d052c4 in raise () from /home/mthl/.guix-profile/lib/libc.so.6
#1  0x00007ffff5d0672a in abort () from /home/mthl/.guix-profile/lib/libc.so.6
#2  0x00007ffff76bae23 in pre_init_throw ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#3  0x00007ffff76d08b6 in vm_regular_engine ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#4  0x00007ffff76d2a38 in scm_call_with_vm ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#5  0x00007ffff76b22bd in scm_to_stringn ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#6  0x00007ffff7666e70 in search_path ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#7  0x00007ffff76685c1 in scm_init_eval_in_scheme ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#8  0x00007ffff7661448 in scm_i_init_guile ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#9  0x00007ffff76b83b0 in scm_i_init_thread_for_guile ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#10 0x00007ffff76b83e9 in with_guile_and_parent ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#11 0x00007ffff7389732 in GC_call_with_stack_base ()
   from /home/mthl/.guix-profile/lib/libgc.so.1
#12 0x00007ffff76b8808 in scm_with_guile ()
   from /gnu/store/p50qidshrjvvd7d1955navjkijr2fg32-guile-2.0.14/lib/libguile-2.0.so.22
#13 0x000000000049cad6 in _initialize_guile() ()
#14 0x00000000006de1a3 in initialize_all_files() ()
#15 0x000000000069f27d in gdb_init(char*) ()
#16 0x00000000005fa0be in gdb_main(captured_main_args*) ()
#17 0x0000000000412075 in main ()
--8<---------------cut here---------------end--------------->8---

Apparently I miss the symbol table of gdb so I don't know how to proceed
next to get more precise information.  Help welcome.

When looking at ‘scm_to_stringn’ code and crossing with the actual error
message it looks like the failing instruction is the following:

--8<---------------cut here---------------start------------->8---
      ret = mem_iconveh (scm_i_string_chars (str), ilen,
                         "ISO-8859-1", enc,
                         (enum iconv_ilseq_handler) handler, NULL,
                         &buf, &len);
--8<---------------cut here---------------end--------------->8---

I am done for today.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37