diff mbox series

[bug#69396,core-updates] gnu: ld-wrapper: Also unset GUILE_LOAD_PATH.

Message ID e64c696e314f39865f782e7320241631a7e68a77.1708895869.git.maxim.cournoyer@gmail.com
State New
Headers show
Series [bug#69396,core-updates] gnu: ld-wrapper: Also unset GUILE_LOAD_PATH. | expand

Commit Message

Maxim Cournoyer Feb. 25, 2024, 9:17 p.m. UTC
The following problem was discovered while attempting to configure Guix to use
a locally built Guile tree, via its meta/uninstalled-env script, which would
attempt to use the newer Guile source files and fail with:

  Pre-boot error; key: unbound-variable, args: (#f "Unbound variable:
  ~S" (error) #f)collect2: fatal error: ld terminated with signal 6 [Aborted]

With the following change, a Guix user may now configure their build to use a
locally built Guile with e.g.:

  ~/src/guile/meta/uninstalled-env ./configure --localstatedir=/var \
  --sysconfdir=/etc

* gnu/packages/ld-wrapper.in: Unset GUILE_LOAD_PATH.  Also unset
GUILE_SYSTEM_PATH, for symmetry.  Streamline exec call, using the now fixed
'-l' option.
(ld-wrapper): Fix args being a nested list, and strip its arg0.

Change-Id: Iaaa721019f3646d851202bb018214ec9fcc04fd4
---

 gnu/packages/ld-wrapper.in | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)


base-commit: f205179ed2cedf55aa0e046af2d80282f6a74075

Comments

Ludovic Courtès Feb. 25, 2024, 9:49 p.m. UTC | #1
Hi,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> The following problem was discovered while attempting to configure Guix to use
> a locally built Guile tree, via its meta/uninstalled-env script, which would
> attempt to use the newer Guile source files and fail with:
>
>   Pre-boot error; key: unbound-variable, args: (#f "Unbound variable:
>   ~S" (error) #f)collect2: fatal error: ld terminated with signal 6 [Aborted]
>
> With the following change, a Guix user may now configure their build to use a
> locally built Guile with e.g.:
>
>   ~/src/guile/meta/uninstalled-env ./configure --localstatedir=/var \
>   --sysconfdir=/etc
>
> * gnu/packages/ld-wrapper.in: Unset GUILE_LOAD_PATH.  Also unset
> GUILE_SYSTEM_PATH, for symmetry.  Streamline exec call, using the now fixed
> '-l' option.
> (ld-wrapper): Fix args being a nested list, and strip its arg0.

[...]

> -# XXX: We have to go through Bash because there's no command-line switch to
> -# augment %load-compiled-path, and because of the silly 127-byte limit for
> -# the shebang line in Linux.
> -# Use `load-compiled' because `load' (and `-l') doesn't otherwise load our
> -# .go file (see <http://bugs.gnu.org/12519>).
> -# Unset 'GUILE_LOAD_COMPILED_PATH' to make sure we do not stumble upon
> -# incompatible .go files.  See
> -# <https://lists.gnu.org/archive/html/guile-devel/2016-03/msg00000.html>.
> +# XXX: We have to go through Bash because there's no Guile command-line switch to
> +# ignore the various Guile load path related environment variables.
>  
> +# Unset 'GUILE_LOAD_PATH' to make sure we do not stumble upon
> +# incompatible Guile files (see
> +# <https://lists.gnu.org/archive/html/guile-devel/2016-03/msg00000.html>).
> +
> +unset GUILE_LOAD_PATH
>  unset GUILE_LOAD_COMPILED_PATH
> +unset GUILE_SYSTEM_PATH
>  unset GUILE_SYSTEM_COMPILED_PATH

OK for this part (I guess nobody tried that before!).

> -main="(@ (gnu build-support ld-wrapper) ld-wrapper)"
> -exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line)))" "$@"
> +
> +exec  @GUILE@ \
> +-l @SELF@ \
> +-e '(@ (gnu build-support ld-wrapper) ld-wrapper)' -s "$0" "$@"

@SELF@ might need to be enclosed in double quotes for good measure.

Can you check through ‘strace’ how loading with ‘-l’ compares to
(load-compiled …)?

Otherwise LGTM, thanks!

Ludo’.
Maxim Cournoyer Feb. 26, 2024, 4:06 a.m. UTC | #2
Hi Ludo,

Thanks for the prompt review!

Ludovic Courtès <ludo@gnu.org> writes:

[...]

>> +unset GUILE_LOAD_PATH
>>  unset GUILE_LOAD_COMPILED_PATH
>> +unset GUILE_SYSTEM_PATH
>>  unset GUILE_SYSTEM_COMPILED_PATH
>
> OK for this part (I guess nobody tried that before!).

Ack.

>> -main="(@ (gnu build-support ld-wrapper) ld-wrapper)"
>> -exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line)))" "$@"
>> +
>> +exec  @GUILE@ \
>> +-l @SELF@ \
>> +-e '(@ (gnu build-support ld-wrapper) ld-wrapper)' -s "$0" "$@"
>
> @SELF@ might need to be enclosed in double quotes for good measure.
>
> Can you check through ‘strace’ how loading with ‘-l’ compares to
> (load-compiled …)?

Good suggestion; it turns out the .go file was not loaded until I also
would provide the -C / arguments to Guile, as load-in-vicinity with an
absolute file does the module loading from site-path thing as well as
compiled-path-dir + absolute-file-name-of.go, which meant it was
attempting to load the .go file at some odd place like
'/gnu/store/hx74v20cwcra7jq8lnagfi76i73018ai-ld-wrapper2-0/bin//gnu/store/hx74v20cwcra7jq8lnagfi76i73018ai-ld-wrapper2-0/bin/ld.go',
hm.

For completeness, the added system calls as seen with strace when using -C / -l
/gnu/store/hx74v20cwcra7jq8lnagfi76i73018ai-ld-wrapper2-0/bin/ld
compared to the previous approach were:

--8<---------------cut here---------------start------------->8---
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/3.0/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/3.0/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/3.0/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/3.0/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/lib/guile/3.0/ccache/gnu/build-support/ld-wrapper.go", 0x7ffd4c4c36a0, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/lib/guile/3.0/site-ccache/gnu/build-support/ld-wrapper.go", 0x7ffd4c4c36a0, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/3.0/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/3.0/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/3.0/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/3.0/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/site/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/gnu/build-support/ld-wrapper.scm", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/gnu/build-support/ld-wrapper", 0x7ffd4c4c3920, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/lib/guile/3.0/ccache/gnu/build-support/ld-wrapper.go", 0x7ffd4c4c36a0, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/lib/guile/3.0/site-ccache/gnu/build-support/ld-wrapper.go", 0x7ffd4c4c36a0, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
getcwd("/home/maxim/src/guix-core-updates", 100) = 34
newfstatat(AT_FDCWD, "/gnu/store/mn9fi6hvs5nr8n3c4651vbirkgigfy7n-ld-wrapper2-0/bin/ld", {st_dev=makedev(0, 0x18), st_ino=370740560, st_mode=S_IFREG|0555, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=32, st_size=12553, st_atime=1708917046 /* 2024-02-25T22:10:46-0500 */, st_atime_nsec=0, st_mtime=1 /* 1969-12-31T19:00:01-0500 */, st_mtime_nsec=0, st_ctime=1708917047 /* 2024-02-25T22:10:47.398473362-0500 */, st_ctime_nsec=398473362}, 0) = 0
newfstatat(AT_FDCWD, "//gnu/store/mn9fi6hvs5nr8n3c4651vbirkgigfy7n-ld-wrapper2-0/bin/ld.go", {st_dev=makedev(0, 0x18), st_ino=370740561, st_mode=S_IFREG|0444, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=160, st_size=81429, st_atime=1708917046 /* 2024-02-25T22:10:46-0500 */, st_atime_nsec=0, st_mtime=1 /* 1969-12-31T19:00:01-0500 */, st_mtime_nsec=0, st_ctime=1708917047 /* 2024-02-25T22:10:47.402473236-0500 */, st_ctime_nsec=402473236}, 0) = 0
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/share/guile/3.0/system/vm/loader.scm", {st_dev=makedev(0, 0x18), st_ino=357681850, st_mode=S_IFREG|0444, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=1120, st_atime=1 /* 1969-12-31T19:00:01-0500 */, st_atime_nsec=0, st_mtime=1 /* 1969-12-31T19:00:01-0500 */, st_mtime_nsec=0, st_ctime=1706016118 /* 2024-01-23T08:21:58.171697725-0500 */, st_ctime_nsec=171697725}, 0) = 0
newfstatat(AT_FDCWD, "/system/vm/loader.go", 0x7ffd4c4c36a0, 0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
newfstatat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/lib/guile/3.0/ccache/system/vm/loader.go", {st_dev=makedev(0, 0x18), st_ino=256911472, st_mode=S_IFREG|0444, st_nlink=39, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=136, st_size=68581, st_atime=1707491218 /* 2024-02-09T10:06:58.868984106-0500 */, st_atime_nsec=868984106, st_mtime=1 /* 1969-12-31T19:00:01-0500 */, st_mtime_nsec=0, st_ctime=1707727292 /* 2024-02-12T03:41:32.717219251-0500 */, st_ctime_nsec=717219251}, 0) = 0
openat(AT_FDCWD, "/gnu/store/7jdlzpvy01y7szg7phm2l2x9szjrwlgw-guile-3.0.9/lib/guile/3.0/ccache/system/vm/loader.go", O_RDONLY|O_CLOEXEC) = 5
lseek(5, 0, SEEK_END)                   = 68581
mmap(NULL, 68581, PROT_READ, MAP_PRIVATE, 5, 0) = 0x7fa8f76cc000
close(5)                                = 0
mprotect(0x7fa8f76dc000, 936, PROT_READ|PROT_WRITE) = 0
openat(AT_FDCWD, "//gnu/store/mn9fi6hvs5nr8n3c4651vbirkgigfy7n-ld-wrapper2-0/bin/ld.go", O_RDONLY|O_CLOEXEC) = 5
lseek(5, 0, SEEK_END)                   = 81429
mmap(NULL, 81429, PROT_READ, MAP_PRIVATE, 5, 0) = 0x7fa8f76b8000
close(5)                                = 0
mprotect(0x7fa8f76c8000, 5832, PROT_READ|PROT_WRITE) = 0
getcwd("/home/maxim/src/guix-core-updates", 100) = 34
newfstatat(AT_FDCWD, "/gnu/store/mn9fi6hvs5nr8n3c4651vbirkgigfy7n-ld-wrapper2-0/bin/ld", {st_dev=makedev(0, 0x18), st_ino=370740560, st_mode=S_IFREG|0555, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=32, st_size=12553, st_atime=1708917046 /* 2024-02-25T22:10:46-0500 */, st_atime_nsec=0, st_mtime=1 /* 1969-12-31T19:00:01-0500 */, st_mtime_nsec=0, st_ctime=1708917047 /* 2024-02-25T22:10:47.398473362-0500 */, st_ctime_nsec=398473362}, 0) = 0
newfstatat(AT_FDCWD, "//gnu/store/mn9fi6hvs5nr8n3c4651vbirkgigfy7n-ld-wrapper2-0/bin/ld.go", {st_dev=makedev(0, 0x18), st_ino=370740561, st_mode=S_IFREG|0444, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=160, st_size=81429, st_atime=1708917046 /* 2024-02-25T22:10:46-0500 */, st_atime_nsec=0, st_mtime=1 /* 1969-12-31T19:00:01-0500 */, st_mtime_nsec=0, st_ctime=1708917047 /* 2024-02-25T22:10:47.402473236-0500 */, st_ctime_nsec=402473236}, 0) = 0
openat(AT_FDCWD, "//gnu/store/mn9fi6hvs5nr8n3c4651vbirkgigfy7n-ld-wrapper2-0/bin/ld.go", O_RDONLY|O_CLOEXEC) = 5
--8<---------------cut here---------------end--------------->8---

So, I've reverted to the old style of using load-compiled, and left a
note.  You'll find the result in v2.

I'll synchronize with jpoiret for the right timing to merge this to
core-updates with other world rebuilding changes, to minimize disruption
to other core-updates hackers.
diff mbox series

Patch

diff --git a/gnu/packages/ld-wrapper.in b/gnu/packages/ld-wrapper.in
index 0d53e746af..0a2135ff5e 100644
--- a/gnu/packages/ld-wrapper.in
+++ b/gnu/packages/ld-wrapper.in
@@ -1,23 +1,26 @@ 
 #!@BASH@
 # -*- mode: scheme; coding: utf-8; -*-
 
-# XXX: We have to go through Bash because there's no command-line switch to
-# augment %load-compiled-path, and because of the silly 127-byte limit for
-# the shebang line in Linux.
-# Use `load-compiled' because `load' (and `-l') doesn't otherwise load our
-# .go file (see <http://bugs.gnu.org/12519>).
-# Unset 'GUILE_LOAD_COMPILED_PATH' to make sure we do not stumble upon
-# incompatible .go files.  See
-# <https://lists.gnu.org/archive/html/guile-devel/2016-03/msg00000.html>.
+# XXX: We have to go through Bash because there's no Guile command-line switch to
+# ignore the various Guile load path related environment variables.
 
+# Unset 'GUILE_LOAD_PATH' to make sure we do not stumble upon
+# incompatible Guile files (see
+# <https://lists.gnu.org/archive/html/guile-devel/2016-03/msg00000.html>).
+
+unset GUILE_LOAD_PATH
 unset GUILE_LOAD_COMPILED_PATH
+unset GUILE_SYSTEM_PATH
 unset GUILE_SYSTEM_COMPILED_PATH
-main="(@ (gnu build-support ld-wrapper) ld-wrapper)"
-exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line)))" "$@"
+
+exec  @GUILE@ \
+-l @SELF@ \
+-e '(@ (gnu build-support ld-wrapper) ld-wrapper)' -s "$0" "$@"
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -285,9 +288,9 @@  library outside of ~a: ~s~%"
       result
       (expand-arguments result)))
 
-(define (ld-wrapper . args)
+(define (ld-wrapper args)
   ;; Invoke the real `ld' with ARGS, augmented with `-rpath' switches.
-  (let* ((args (expand-arguments args))
+  (let* ((args (expand-arguments (cdr args))) ;strip arg0
          (path (library-search-path args))
          (libs (library-files-linked args path))
          (args (append args (rpath-arguments libs))))