diff mbox series

[bug#50174,core-updates-frozen,1/2] gnu: make-bootstrap: Fix build of static gawk.

Message ID 20210823205127.27102-1-bauermann@kolabnow.com
State Accepted
Headers show
Series [bug#50174,core-updates-frozen,1/2] gnu: make-bootstrap: Fix build of static gawk. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Thiago Jung Bauermann Aug. 23, 2021, 8:51 p.m. UTC
* gnu/packages/make-bootstrap.scm (%static-inputs)[finalize-with-ld-flags]:
New function.
[map]<match-lambda>: Add new clause to match three elements.
[map]<gawk>: Add linker option.
* guix/build-system/gnu.scm (static-package): Add ‘#:ld-flags’ keyword
argument.
---

Hello,

gawk for ‘static-binaries-tarball’ is failing to build natively, at least for
x86_64-linux¹ and powerpc64le-linux. On both of them, the problem is the same:

--8<---------------cut here---------------start------------->8---
ld: ext.o: in function `load_ext':
/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/ext.c:59: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o): in function `_getopt_internal_r':
(.text+0x6e0): multiple definition of `_getopt_internal_r'; support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/support/getopt.c:404: first defined here
ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o): in function `_getopt_internal':
(.text+0xcc0): multiple definition of `_getopt_internal'; support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/support/getopt.c:1187: first defined here
ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o):(.data+0x8): multiple definition of `optind'; support/libsupport.a(getopt.o):/gnu/store/zy7zwhxxbphqqmigp17j54dpbpz6wr38-glibc-2.33/include/bits/getopt_core.h:50: first defined here
ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o):(.data+0x4): multiple definition of `opterr'; support/libsupport.a(getopt.o):/gnu/store/zy7zwhxxbphqqmigp17j54dpbpz6wr38-glibc-2.33/include/bits/getopt_core.h:55: first defined here
ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o):(.data+0x0): multiple definition of `optopt'; support/libsupport.a(getopt.o):/gnu/store/zy7zwhxxbphqqmigp17j54dpbpz6wr38-glibc-2.33/include/bits/getopt_core.h:59: first defined here
ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o): in function `getopt':
(.text+0xd20): multiple definition of `getopt'; support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/support/getopt.c:1206: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:663: gawk] Error 1
make[2]: Leaving directory '/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0'
--8<---------------cut here---------------end--------------->8---

This patch fixes it by passing “--allow-multiple-definition” to the linker.

Judging by the CI results, cross-builds seems to be working. I haven’t looked
into what’s different about them.

NB: I wasn’t sure how to write a changelog for ‘%static-inputs’ so I got a bit
creative.

¹ https://ci.guix.gnu.org/build/502639/details

 gnu/packages/make-bootstrap.scm | 14 +++++++++++---
 guix/build-system/gnu.scm       |  8 ++++++--
 2 files changed, 17 insertions(+), 5 deletions(-)

Comments

Ludovic Courtès Sept. 27, 2021, 9:38 p.m. UTC | #1
Hi Thiago,

Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:

> gawk for ‘static-binaries-tarball’ is failing to build natively, at least for
> x86_64-linux¹ and powerpc64le-linux. On both of them, the problem is the same:
>
> ld: ext.o: in function `load_ext':
> /tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/ext.c:59: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
> ld: /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc.a(getopt.o): in function `_getopt_internal_r':
> (.text+0x6e0): multiple definition of `_getopt_internal_r'; support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/support/getopt.c:404: first defined here

I don’t see that on x86_64/i686:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env  guix weather bootstrap-tarballs -s x86_64-linux -s i686-linux -s aarch64-linux -s armhf-linux --substitute-urls=https://ci.guix.gnu.org --display-missing
computing 1 package derivations for armhf-linux...
computing 1 package derivations for aarch64-linux...
computing 1 package derivations for i686-linux...
computing 1 package derivations for x86_64-linux...
looking for 4 store items on https://ci.guix.gnu.org...
https://ci.guix.gnu.org
  50.0% substitutes available (2 out of 4)
  at least 0.0 MiB of nars (compressed)
  0.0 MiB on disk (uncompressed)

  0.0% (0 out of 2) of the missing items are queued
  at least 1,000 queued builds
      i586-gnu: 386 (38.6%)
      powerpc64le-linux: 83 (8.3%)
      x86_64-linux: 527 (52.7%)
      aarch64-linux: 3 (.3%)
      i686-linux: 1 (.1%)
  build rate: .00 builds per hour
      x86_64-linux: 0.00 builds per hour
      i686-linux: 0.00 builds per hour
      aarch64-linux: 0.00 builds per hour
      powerpc64le-linux: 0.00 builds per hour

Substitutes are missing for the following items:
  /gnu/store/3c8gbn2gljj48wihs9h3nxmfwix55wrn-bootstrap-tarballs-0               armhf-linux
  /gnu/store/8b6rznm54l6drbs6qfca5bi8yjqbx51f-bootstrap-tarballs-0               aarch64-linux
$ git log |head -1
commit 7c5f01d55634254bea8bad4c9dcc31496efd4fce
--8<---------------cut here---------------end--------------->8---

Could it be that something changed in the meantime?

Thanks,
Ludo’.
Thiago Jung Bauermann Sept. 28, 2021, 3:39 a.m. UTC | #2
Hello Ludo,

Em segunda-feira, 27 de setembro de 2021, às 18:38:45 -03, Ludovic Courtès 
escreveu:
> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
> > gawk for ‘static-binaries-tarball’ is failing to build natively, at
> > least for x86_64-linux¹ and powerpc64le-linux. On both of them, the
> > problem is the same:
> > 
> > ld: ext.o: in function `load_ext':
> > /tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/ext.c:59: warning: Using
> > 'dlopen' in statically linked applications requires at runtime the
> > shared libraries from the glibc version used for linking ld:
> > /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc
> > .a(getopt.o): in function `_getopt_internal_r': (.text+0x6e0): multiple
> > definition of `_getopt_internal_r';
> > support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5
> > .1.0/support/getopt.c:404: first defined here
> 
> I don’t see that on x86_64/i686:
> 
> --8<---------------cut here---------------start------------->8---
> $ ./pre-inst-env  guix weather bootstrap-tarballs -s x86_64-linux -s i686-linux

I’m using the package ‘static-binaries-tarball’ to expose the issue. IIUC,
the static binaries (of which ‘gawk-static’ is one) aren’t used for
bootstrapping on i686-linux and x86_64-linux so you won’t see this problem
with ‘bootstrap-tarballs’ on those platforms.

> -s aarch64-linux -s armhf-linux

OTOH, these platforms do use the static binaries. For some reason which TBH
I didn’t try to investigate, ‘gawk-static’ cross-builds correctly so you’ll only see
this problem on native builds of ‘bootstrap-tarballs’ or ‘static-binaries-tarball’.

> Substitutes are missing for the following items:
>   /gnu/store/3c8gbn2gljj48wihs9h3nxmfwix55wrn-bootstrap-tarballs-0       
>        armhf-linux
> /gnu/store/8b6rznm54l6drbs6qfca5bi8yjqbx51f-bootstrap-tarballs-0        
>       aarch64-linux

Doesn’t this mean that there is indeed a problem with ‘bootstrap-tarballs’
on these platforms?

> Could it be that something changed in the meantime?

It doesn’t look like it. The latest CI result for an x86_64-linux native
build of ‘static-binaries-tarball’ on ‘core-updates-frozen’ failed:

https://ci.guix.gnu.org/build/709458/details

Ditto for the ‘core-updates’ branch:

https://ci.guix.gnu.org/build/825383/details

Also, I can still reproduce the problem on my laptop with current
‘core-updates-frozen’ commit 81a34a90d72d (“doc: Update postgresql defaut
socket directory.”) using:

$ ./pre-inst-env guix build static-binaries-tarball
Ludovic Courtès Sept. 28, 2021, 10:19 p.m. UTC | #3
Hi Thiago,

Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:

> Em segunda-feira, 27 de setembro de 2021, às 18:38:45 -03, Ludovic Courtès 
> escreveu:
>> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
>> > gawk for ‘static-binaries-tarball’ is failing to build natively, at
>> > least for x86_64-linux¹ and powerpc64le-linux. On both of them, the
>> > problem is the same:
>> > 
>> > ld: ext.o: in function `load_ext':
>> > /tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/ext.c:59: warning: Using
>> > 'dlopen' in statically linked applications requires at runtime the
>> > shared libraries from the glibc version used for linking ld:
>> > /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/libc
>> > .a(getopt.o): in function `_getopt_internal_r': (.text+0x6e0): multiple
>> > definition of `_getopt_internal_r';
>> > support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk-5
>> > .1.0/support/getopt.c:404: first defined here
>> 
>> I don’t see that on x86_64/i686:
>> 
>> --8<---------------cut here---------------start------------->8---
>> $ ./pre-inst-env  guix weather bootstrap-tarballs -s x86_64-linux -s i686-linux
>
> I’m using the package ‘static-binaries-tarball’ to expose the issue. IIUC,
> the static binaries (of which ‘gawk-static’ is one) aren’t used for
> bootstrapping on i686-linux and x86_64-linux so you won’t see this problem
> with ‘bootstrap-tarballs’ on those platforms.
>
>> -s aarch64-linux -s armhf-linux
>
> OTOH, these platforms do use the static binaries. For some reason which TBH
> I didn’t try to investigate, ‘gawk-static’ cross-builds correctly so you’ll only see
> this problem on native builds of ‘bootstrap-tarballs’ or ‘static-binaries-tarball’.

Oooh, my bad, sorry for the confusion.

>> Substitutes are missing for the following items:
>>   /gnu/store/3c8gbn2gljj48wihs9h3nxmfwix55wrn-bootstrap-tarballs-0       
>>        armhf-linux
>> /gnu/store/8b6rznm54l6drbs6qfca5bi8yjqbx51f-bootstrap-tarballs-0        
>>       aarch64-linux
>
> Doesn’t this mean that there is indeed a problem with ‘bootstrap-tarballs’
> on these platforms?

Yes, it does!  But I thought it might be “something else”.

I fixed it slightly differently in
7d30e6e5c21f5e0b79f73428414fef2dbf75e7a6, followed by the second patch
you had here.  Let’s see how far that brings us towards
’static-binaries-tarball’.

Thank you & sorry for the delay!

Ludo’.
Thiago Jung Bauermann Sept. 29, 2021, 1:59 a.m. UTC | #4
Hello Ludo,

Em terça-feira, 28 de setembro de 2021, às 19:19:04 -03, Ludovic Courtès 
escreveu:
> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
> > Em segunda-feira, 27 de setembro de 2021, às 18:38:45 -03, Ludovic
> > Courtès> 
> > escreveu:
> >> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
> >> > gawk for ‘static-binaries-tarball’ is failing to build natively, at
> >> > least for x86_64-linux¹ and powerpc64le-linux. On both of them, the
> >> > problem is the same:
> >> > 
> >> > ld: ext.o: in function `load_ext':
> >> > /tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/ext.c:59: warning: Using
> >> > 'dlopen' in statically linked applications requires at runtime the
> >> > shared libraries from the glibc version used for linking ld:
> >> > /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/li
> >> > bc
> >> > .a(getopt.o): in function `_getopt_internal_r': (.text+0x6e0):
> >> > multiple
> >> > definition of `_getopt_internal_r';
> >> > support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk
> >> > -5
> >> > .1.0/support/getopt.c:404: first defined here
> >> 
> >> I don’t see that on x86_64/i686:
> >> 
> >> --8<---------------cut here---------------start------------->8---
> >> $ ./pre-inst-env  guix weather bootstrap-tarballs -s x86_64-linux -s
> >> i686-linux> 
> > I’m using the package ‘static-binaries-tarball’ to expose the issue.
> > IIUC, the static binaries (of which ‘gawk-static’ is one) aren’t used
> > for bootstrapping on i686-linux and x86_64-linux so you won’t see this
> > problem with ‘bootstrap-tarballs’ on those platforms.
> > 
> >> -s aarch64-linux -s armhf-linux
> > 
> > OTOH, these platforms do use the static binaries. For some reason which
> > TBH I didn’t try to investigate, ‘gawk-static’ cross-builds correctly
> > so you’ll only see this problem on native builds of
> > ‘bootstrap-tarballs’ or ‘static-binaries-tarball’.
> Oooh, my bad, sorry for the confusion.

No problem!
 
> >> Substitutes are missing for the following items:
> >>   /gnu/store/3c8gbn2gljj48wihs9h3nxmfwix55wrn-bootstrap-tarballs-0
> >>   
> >>        armhf-linux
> >> 
> >> /gnu/store/8b6rznm54l6drbs6qfca5bi8yjqbx51f-bootstrap-tarballs-0
> >> 
> >>       aarch64-linux
> > 
> > Doesn’t this mean that there is indeed a problem with
> > ‘bootstrap-tarballs’ on these platforms?
> 
> Yes, it does!  But I thought it might be “something else”.
> 
> I fixed it slightly differently in
> 7d30e6e5c21f5e0b79f73428414fef2dbf75e7a6, followed by the second patch
> you had here. 

Your solution is better indeed. Thanks!

> Let’s see how far that brings us towards ’static-binaries-tarball’.

According to the CI, x86_64-linux and i686-linux are fixed now. aarch64-
linux failed but that’s because of a bug in QEMU. powerpc64-linux is 
scheduled to build but there’s a backlog in the CI for some reason.

> Thank you & sorry for the delay!

No problem at all. Thank you for fixing this problem!
Maxim Cournoyer Oct. 12, 2021, 5:45 p.m. UTC | #5
Hello,

Thiago Jung Bauermann <bauermann@kolabnow.com> writes:

> Hello Ludo,
>
> Em terça-feira, 28 de setembro de 2021, às 19:19:04 -03, Ludovic Courtès 
> escreveu:
>> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
>> > Em segunda-feira, 27 de setembro de 2021, às 18:38:45 -03, Ludovic
>> > Courtès> 
>> > escreveu:
>> >> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
>> >> > gawk for ‘static-binaries-tarball’ is failing to build natively, at
>> >> > least for x86_64-linux¹ and powerpc64le-linux. On both of them, the
>> >> > problem is the same:
>> >> > 
>> >> > ld: ext.o: in function `load_ext':
>> >> > /tmp/guix-build-gawk-5.1.0.drv-0/gawk-5.1.0/ext.c:59: warning: Using
>> >> > 'dlopen' in statically linked applications requires at runtime the
>> >> > shared libraries from the glibc version used for linking ld:
>> >> > /gnu/store/qmgsfxm3ad5n7bi947n7xw0wq86blqr9-glibc-2.33-static/lib/li
>> >> > bc
>> >> > .a(getopt.o): in function `_getopt_internal_r': (.text+0x6e0):
>> >> > multiple
>> >> > definition of `_getopt_internal_r';
>> >> > support/libsupport.a(getopt.o):/tmp/guix-build-gawk-5.1.0.drv-0/gawk
>> >> > -5
>> >> > .1.0/support/getopt.c:404: first defined here
>> >> 
>> >> I don’t see that on x86_64/i686:
>> >> 
>> >> --8<---------------cut here---------------start------------->8---
>> >> $ ./pre-inst-env  guix weather bootstrap-tarballs -s x86_64-linux -s
>> >> i686-linux> 
>> > I’m using the package ‘static-binaries-tarball’ to expose the issue.
>> > IIUC, the static binaries (of which ‘gawk-static’ is one) aren’t used
>> > for bootstrapping on i686-linux and x86_64-linux so you won’t see this
>> > problem with ‘bootstrap-tarballs’ on those platforms.
>> > 
>> >> -s aarch64-linux -s armhf-linux
>> > 
>> > OTOH, these platforms do use the static binaries. For some reason which
>> > TBH I didn’t try to investigate, ‘gawk-static’ cross-builds correctly
>> > so you’ll only see this problem on native builds of
>> > ‘bootstrap-tarballs’ or ‘static-binaries-tarball’.
>> Oooh, my bad, sorry for the confusion.
>
> No problem!
>  
>> >> Substitutes are missing for the following items:
>> >>   /gnu/store/3c8gbn2gljj48wihs9h3nxmfwix55wrn-bootstrap-tarballs-0
>> >>   
>> >>        armhf-linux
>> >> 
>> >> /gnu/store/8b6rznm54l6drbs6qfca5bi8yjqbx51f-bootstrap-tarballs-0
>> >> 
>> >>       aarch64-linux
>> > 
>> > Doesn’t this mean that there is indeed a problem with
>> > ‘bootstrap-tarballs’ on these platforms?
>> 
>> Yes, it does!  But I thought it might be “something else”.
>> 
>> I fixed it slightly differently in
>> 7d30e6e5c21f5e0b79f73428414fef2dbf75e7a6, followed by the second patch
>> you had here. 
>
> Your solution is better indeed. Thanks!
>
>> Let’s see how far that brings us towards ’static-binaries-tarball’.
>
> According to the CI, x86_64-linux and i686-linux are fixed now. aarch64-
> linux failed but that’s because of a bug in QEMU. powerpc64-linux is 
> scheduled to build but there’s a backlog in the CI for some reason.
>
>> Thank you & sorry for the delay!
>
> No problem at all. Thank you for fixing this problem!

Seems Ludovic pushed a derived fix.  Thank you both!

Closing.

Maxim
Thiago Jung Bauermann Oct. 12, 2021, 9:53 p.m. UTC | #6
Hello Maxim,

Em terça-feira, 12 de outubro de 2021, às 14:45:42 -03, Maxim Cournoyer 
escreveu:
> >> Thiago Jung Bauermann <bauermann@kolabnow.com> skribis:
> >> > Em segunda-feira, 27 de setembro de 2021, às 18:38:45 -03, Ludovic
> >> > Courtès escreveu:
> >> Thank you & sorry for the delay!
> > 
> > No problem at all. Thank you for fixing this problem!
> 
> Seems Ludovic pushed a derived fix.  Thank you both!
> 
> Closing.

I hadn’t noticed that the issue wasn’t closed. Thank you for following up 
on it!
diff mbox series

Patch

diff --git a/gnu/packages/make-bootstrap.scm b/gnu/packages/make-bootstrap.scm
index 12e59e9f8383..79eb9d60026f 100644
--- a/gnu/packages/make-bootstrap.scm
+++ b/gnu/packages/make-bootstrap.scm
@@ -260,10 +260,15 @@  for `sh' in $PATH, and without nscd, and with static NSS modules."
                     `(modify-phases ,phases
                        (delete 'fix-egrep-and-fgrep)))))))
         (finalize (compose static-package
-                           package-with-relocatable-glibc)))
+                           package-with-relocatable-glibc))
+        (finalize-with-ld-flags (lambda (pkg ld-flags)
+                                  (package-with-relocatable-glibc
+                                   (static-package pkg #:ld-flags ld-flags)))))
     `(,@(map (match-lambda
               ((name package)
-               (list name (finalize package))))
+               (list name (finalize package)))
+               ((name package ld-flags)
+                (list name (finalize-with-ld-flags package ld-flags))))
              `(("tar" ,tar)
                ("gzip" ,gzip)
                ("bzip2" ,bzip2)
@@ -272,7 +277,10 @@  for `sh' in $PATH, and without nscd, and with static NSS modules."
                ("coreutils" ,coreutils)
                ("sed" ,sed)
                ("grep" ,grep)
-               ("gawk" ,gawk)))
+               ("gawk" ,gawk
+                ;; gawk's gnulib defines some getopt symbols which are also in
+                ;; libc.a so this linker option is needed for a static build.
+                "-Wl,--allow-multiple-definition")))
       ("bash" ,static-bash))))
 
 (define %static-binaries
diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index ea91be5bcd0c..acbd5b3a0de4 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -210,7 +210,7 @@  flags for VARIABLE, the associated value is augmented."
   "A version of P linked with `-static-gcc'."
   (package-with-extra-configure-variable p "LDFLAGS" "-static-libgcc"))
 
-(define* (static-package p #:key (strip-all? #t))
+(define* (static-package p #:key (strip-all? #t) (ld-flags #f))
   "Return a statically-linked version of package P.  If STRIP-ALL? is true,
 use `--strip-all' as the arguments to `strip'."
   (package (inherit p)
@@ -220,7 +220,11 @@  use `--strip-all' as the arguments to `strip'."
                   #:strip-flags '("--strip-unneeded")))))
        (substitute-keyword-arguments a
          ((#:configure-flags flags)
-          `(cons* "--disable-shared" "LDFLAGS=-static" ,flags))
+          `(cons* "--disable-shared" (string-append "LDFLAGS=-static"
+                                                    (if ,ld-flags
+                                                        (string-append " " ,ld-flags)
+                                                        ""))
+                  ,flags))
          ((#:strip-flags flags)
           (if strip-all?
               ''("--strip-all")