Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading shared library libresolv.so.2 on Alpine in Go 1.20 #59305

Closed
bep opened this issue Mar 29, 2023 · 17 comments
Closed

Error loading shared library libresolv.so.2 on Alpine in Go 1.20 #59305

bep opened this issue Mar 29, 2023 · 17 comments

Comments

@bep
Copy link
Contributor

bep commented Mar 29, 2023

This is a reopening of #59304 -- which was closed with a not very helpful "working as intended" message.

Searching this GitHub repo for musl libc shows lots of existing relevant issues/code adaptations. People, like me, could maybe be lead to believe that Musl Libc was supported (and Alpine is a very popular Docker runtime). I'm not saying that this is a bug, but it's at least a documentation issue.

I understand that with the big number of issues in your back log, you need to somehow be very effective about this, but these short and cranky brush offs with "working as intended" is, I suspect, not having the effect you want in the long run.

@seankhliao
Copy link
Member

As of 1.20, you're responsible for linking against C libraries properly if you build with CGo enabled.
Previously, go was distributed with prebuilt archives linked against ancient c library versions. As documented, we no longer do so.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2023
@ianlancetaylor
Copy link
Contributor

@bep Can you show us how to recreate the problem? Right now I don't understand it, and I don't see any clear reproduction instructions in the earlier issues. Thanks.

@bep
Copy link
Contributor Author

bep commented Mar 30, 2023

As of 1.20, you're responsible for linking against C libraries properly if you build with CGo enabled.

@seankhliao That I understand, but this is a C library that the Go standard library (this repo) is linking, I assume to do DNS lookups.

@ianlancetaylor I will put on my list and try to reproduce this in a simpler setup, but as this involves thinkering with Docker (not my favourite), it may take a few days. But please don't close this issue prematurely.

@Nuru
Copy link

Nuru commented Apr 3, 2023

You can see that minikube v1.30.0 suffers from this problem.

@ianlancetaylor
Copy link
Contributor

@Nuru Is it possible that you are building with glibc and then running in a container that uses Alpine?

@Nuru
Copy link

Nuru commented Apr 4, 2023

@ianlancetaylor I am not building minikube at all. I am using the binary they distribute. See kubernetes/minikube#16228

@ianlancetaylor
Copy link
Contributor

@Nuru Is it possible that the binary that they distribute was built with glibc, but that you are running it in a container that uses Alpine?

@afbjorklund
Copy link

The main difference is that due to the change above (in 1.20), there is now a new libresolv.so.2 depency:

$ go version ./minikube-1.29.0 
./minikube-1.29.0: go1.19.5
$ ldd minikube-1.29.0 
	linux-vdso.so.1 (0x00007ffcdc5f7000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f312da7d000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f312da5a000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f312dc86000)
$ go version ./minikube-1.30.0 
./minikube-1.30.0: go1.20.2
$ ldd minikube-1.30.0 
	linux-vdso.so.1 (0x00007ffc583db000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f40eb1b2000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f40eb18f000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f40eb173000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f40eb3bb000)

The glibc compatibility in Alpine (gcompat) needs to be updated to handle this too - or run a musl binary....

@Julio-Guerra
Copy link

Julio-Guerra commented Apr 18, 2023

@Nuru Is it possible that the binary that they distribute was built with glibc, but that you are running it in a container that uses Alpine?

That's exactly it @ianlancetaylor. We have a "smoke test" now failing with this issue where we build a simple hello world HTTP API using the default golang docker image and copy the resulting binary to the default alpine image. (We introduced that smoke tests because a lot of our package users compile their Go programs this way and wanted to catch any issues asap.)

Something like:

FROM golang:1.20 AS build
WORKDIR /app
COPY . .
RUN go build -o program .

FROM alpine
COPY --from=build /app/program .
RUN ./program

See the output we now get when starting it:

Error loading shared library libresolv.so.2: No such file or directory (needed by /usr/local/bin/go-dvwa)
[...]
Error relocating /usr/local/bin/go-dvwa: __res_search: symbol not found

So we are basically saying that starting from go1.20, the portability we used to have between glibc-based compilations, and musl-based ones, is no longer possible out of the box, without directly compiling with a "musl-gcc".

@afbjorklund
Copy link

afbjorklund commented Apr 18, 2023

If you want a "real" alpine binary (instead of troubleshooting the glibc compatibility), you can build with CC=musl-gcc*.

* You do need to install the musl-tools package

For minikube we didn't want to ship double (or static) binaries, but maybe someone else want dynamic musl binaries ?

$ CC=musl-gcc make
$ musl-ldd out/minikube 
	/lib/ld-musl-x86_64.so.1 (0x7f6b07e40000)
	libc.so => /lib/ld-musl-x86_64.so.1 (0x7f6b07e40000)

@ianlancetaylor
Copy link
Contributor

It's likely that a binary linked against glibc and dynamically linked against Alpine does not actually need a libresolv.so.2 shared library. So a workaround might be to add a dummy shared library with that name, or to link libc.so.6 to that name.

@afbjorklund
Copy link

afbjorklund commented Apr 18, 2023

There is a libgcompat.so library, that exports the needed symbols from the real libc. So it would be possible to fix this in the Alpine distribution, so that the default glibc compatibility layer handles this new "libresolv" like it handles "libpthread"


Note that there is no libc.so.6 either, it is also replaced.

/ # ldd /usr/bin/minikube 
	/lib64/ld-linux-x86-64.so.2 (0x7f8c8161d000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f8c8161d000)
	libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f8c8161d000)
Error loading shared library libresolv.so.2: No such file or directory (needed by /usr/bin/minikube)

ln -sf ../../lib/libgcompat.so.0 /usr/lib/libresolv.so.2

/ # ldd /usr/bin/minikube 
	/lib64/ld-linux-x86-64.so.2 (0x7fbb07446000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fbb07446000)
	libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fbb07446000)
	libresolv.so.2 => /usr/lib/libresolv.so.2 (0x7fbb07433000)
	libucontext.so.1 => /lib/libucontext.so.1 (0x7fbb0742e000)
	libobstack.so.1 => /usr/lib/libobstack.so.1 (0x7fbb07429000)

@Julio-Guerra
Copy link

Julio-Guerra commented Apr 18, 2023

If you want a "real" alpine binary (instead of troubleshooting the glibc compatibility), you can build with CC=musl-gcc*.

Thanks, that's exactly what we just did and it works. We will probably provide this answer to our users raising this specific issue from now (cross-compiling is the still in the usual "bring-your-own-toolchain" case).

@afbjorklund
Copy link

Do you have a link to the Alpine issue, about this ? I guess it would be in their interest, to be able to run go1.20 binaries

@Nuru
Copy link

Nuru commented Apr 28, 2023

I opened this issue with Alpine.

@161424
Copy link

161424 commented May 10, 2023

apk add gcompat
gcompat include libresolv.so.2
https://pkgs.alpinelinux.org/contents?file=libresolv.so.2&path=&name=&branch=edge

petermetz added a commit to petermetz/cacti that referenced this issue Aug 8, 2023
The simple answer was to upgrade to go v1.20.x from v1.15.x, but
this caused a series of other problems that also needed to address
so the complete list of changes and their motivations are below:

1. The upgrade to go v1.20.6
1.1. We no longer install docker-compose via pip because since v2
it ships with the main docker package itself (they rewrote it in go)
1.2. Added a new "gcompat" apk package which is necessary because
of go v1.20.6 as well. Details on this can be found here:
golang/go#59305 (comment)
1.3. As  part of installing the OpenSSH server, we now must first wipe all
openssh* packages due to newly surfaced package version conflicts due
to the ones that are prepackaged with the alpine image.
Without the purge step it fails like this:
    => ERROR [17/64] RUN apk add --no-cache openssh augeas                   1.1s
   ------
    > [17/64] RUN apk add --no-cache openssh augeas:
   0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
   0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
   1.041 ERROR: unable to select packages:
   1.043   openssh-client-common-9.3_p1-r3:
   1.043     breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
2. Upgraded the node-ssh library to v13 because v12 was broken due to
changes introduced by the new OpenSSH server.
3. Modified the container image definition so that we have the ability
to customize the version of fabric-nodeenv images used internally by the
peers of the fabric-samples repository. This was needed so that we can
control what version of npm and NodeJS are being used when the chain code
installation process is happening (which is just the peer running the
`npm install --production` command within the fabric-nodeenv container)
4. The default Fabric version used by the testing infrastructure is now
Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2
5. Slightly rearranged the imports & constants in some of the tests
which made it easier to verify that the new image is working as intended.

Fixes hyperledger-cacti#2358

Signed-off-by: Peter Somogyvari <[email protected]>
petermetz added a commit to petermetz/cacti that referenced this issue Aug 11, 2023
The simple answer was to upgrade to go v1.20.x from v1.15.x, but
this caused a series of other problems that also needed to address
so the complete list of changes and their motivations are below:

1. The upgrade to go v1.20.6
1.1. We no longer install docker-compose via pip because since v2
it ships with the main docker package itself (they rewrote it in go)
1.2. Added a new "gcompat" apk package which is necessary because
of go v1.20.6 as well. Details on this can be found here:
golang/go#59305 (comment)
1.3. As  part of installing the OpenSSH server, we now must first wipe all
openssh* packages due to newly surfaced package version conflicts due
to the ones that are prepackaged with the alpine image.
Without the purge step it fails like this:
    => ERROR [17/64] RUN apk add --no-cache openssh augeas                   1.1s
   ------
    > [17/64] RUN apk add --no-cache openssh augeas:
   0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
   0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
   1.041 ERROR: unable to select packages:
   1.043   openssh-client-common-9.3_p1-r3:
   1.043     breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
2. Upgraded the node-ssh library to v13 because v12 was broken due to
changes introduced by the new OpenSSH server.
3. Modified the container image definition so that we have the ability
to customize the version of fabric-nodeenv images used internally by the
peers of the fabric-samples repository. This was needed so that we can
control what version of npm and NodeJS are being used when the chain code
installation process is happening (which is just the peer running the
`npm install --production` command within the fabric-nodeenv container)
4. The default Fabric version used by the testing infrastructure is now
Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2
5. Slightly rearranged the imports & constants in some of the tests
which made it easier to verify that the new image is working as intended.
6. The new image built from this dockerfile for Fabric AIO 2.x is tagged
on the registry as:
`ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358`

Fixes hyperledger-cacti#2358

Signed-off-by: Peter Somogyvari <[email protected]>
petermetz added a commit to petermetz/cacti that referenced this issue Aug 11, 2023
The simple answer was to upgrade to go v1.20.x from v1.15.x, but
this caused a series of other problems that also needed to address
so the complete list of changes and their motivations are below:

1. The upgrade to go v1.20.6
1.1. We no longer install docker-compose via pip because since v2
it ships with the main docker package itself (they rewrote it in go)
1.2. Added a new "gcompat" apk package which is necessary because
of go v1.20.6 as well. Details on this can be found here:
golang/go#59305 (comment)
1.3. As  part of installing the OpenSSH server, we now must first wipe all
openssh* packages due to newly surfaced package version conflicts due
to the ones that are prepackaged with the alpine image.
Without the purge step it fails like this:
    => ERROR [17/64] RUN apk add --no-cache openssh augeas                   1.1s
   ------
    > [17/64] RUN apk add --no-cache openssh augeas:
   0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
   0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
   1.041 ERROR: unable to select packages:
   1.043   openssh-client-common-9.3_p1-r3:
   1.043     breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
2. Upgraded the node-ssh library to v13 because v12 was broken due to
changes introduced by the new OpenSSH server.
3. Modified the container image definition so that we have the ability
to customize the version of fabric-nodeenv images used internally by the
peers of the fabric-samples repository. This was needed so that we can
control what version of npm and NodeJS are being used when the chain code
installation process is happening (which is just the peer running the
`npm install --production` command within the fabric-nodeenv container)
4. The default Fabric version used by the testing infrastructure is now
Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2
5. Slightly rearranged the imports & constants in some of the tests
which made it easier to verify that the new image is working as intended.
6. The new image built from this dockerfile for Fabric AIO 2.x is tagged
on the registry as:
`ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358`
7. increased the tap timeout from 900 seconds (15 minutes) to 3600 (an hour)

Fixes hyperledger-cacti#2358

Signed-off-by: Peter Somogyvari <[email protected]>
petermetz added a commit to hyperledger-cacti/cacti that referenced this issue Aug 11, 2023
The simple answer was to upgrade to go v1.20.x from v1.15.x, but
this caused a series of other problems that also needed to address
so the complete list of changes and their motivations are below:

1. The upgrade to go v1.20.6
1.1. We no longer install docker-compose via pip because since v2
it ships with the main docker package itself (they rewrote it in go)
1.2. Added a new "gcompat" apk package which is necessary because
of go v1.20.6 as well. Details on this can be found here:
golang/go#59305 (comment)
1.3. As  part of installing the OpenSSH server, we now must first wipe all
openssh* packages due to newly surfaced package version conflicts due
to the ones that are prepackaged with the alpine image.
Without the purge step it fails like this:
    => ERROR [17/64] RUN apk add --no-cache openssh augeas                   1.1s
   ------
    > [17/64] RUN apk add --no-cache openssh augeas:
   0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
   0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
   1.041 ERROR: unable to select packages:
   1.043   openssh-client-common-9.3_p1-r3:
   1.043     breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
2. Upgraded the node-ssh library to v13 because v12 was broken due to
changes introduced by the new OpenSSH server.
3. Modified the container image definition so that we have the ability
to customize the version of fabric-nodeenv images used internally by the
peers of the fabric-samples repository. This was needed so that we can
control what version of npm and NodeJS are being used when the chain code
installation process is happening (which is just the peer running the
`npm install --production` command within the fabric-nodeenv container)
4. The default Fabric version used by the testing infrastructure is now
Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2
5. Slightly rearranged the imports & constants in some of the tests
which made it easier to verify that the new image is working as intended.
6. The new image built from this dockerfile for Fabric AIO 2.x is tagged
on the registry as:
`ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358`
7. increased the tap timeout from 900 seconds (15 minutes) to 3600 (an hour)

Fixes #2358

Signed-off-by: Peter Somogyvari <[email protected]>
andykps added a commit to andykps/stripe-mirakl-connector that referenced this issue Nov 17, 2023
There were errors "Error loading shared library libresolv.so.2: No such
file or directory (needed by /usr/share/filebeat/filebeat" which
apparently is due to Alpine not including libs needed by newer Go apps.
golang/go#59305
https://gitlab.alpinelinux.org/alpine/aports/-/issues/14846
@cyw3
Copy link

cyw3 commented Dec 21, 2023

apk add gcompat gcompat include libresolv.so.2 https://pkgs.alpinelinux.org/contents?file=libresolv.so.2&path=&name=&branch=edge

I also meet this problem. After following your repair steps, it was not successful and another error message appeared:

Segmentation fault (core dumped)

But I compiled the program using go1.19 and then executed it successfully under alpine.

sandeepnRES pushed a commit to sandeepnRES/cacti that referenced this issue Dec 21, 2023
The simple answer was to upgrade to go v1.20.x from v1.15.x, but
this caused a series of other problems that also needed to address
so the complete list of changes and their motivations are below:

1. The upgrade to go v1.20.6
1.1. We no longer install docker-compose via pip because since v2
it ships with the main docker package itself (they rewrote it in go)
1.2. Added a new "gcompat" apk package which is necessary because
of go v1.20.6 as well. Details on this can be found here:
golang/go#59305 (comment)
1.3. As  part of installing the OpenSSH server, we now must first wipe all
openssh* packages due to newly surfaced package version conflicts due
to the ones that are prepackaged with the alpine image.
Without the purge step it fails like this:
    => ERROR [17/64] RUN apk add --no-cache openssh augeas                   1.1s
   ------
    > [17/64] RUN apk add --no-cache openssh augeas:
   0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
   0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
   1.041 ERROR: unable to select packages:
   1.043   openssh-client-common-9.3_p1-r3:
   1.043     breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
2. Upgraded the node-ssh library to v13 because v12 was broken due to
changes introduced by the new OpenSSH server.
3. Modified the container image definition so that we have the ability
to customize the version of fabric-nodeenv images used internally by the
peers of the fabric-samples repository. This was needed so that we can
control what version of npm and NodeJS are being used when the chain code
installation process is happening (which is just the peer running the
`npm install --production` command within the fabric-nodeenv container)
4. The default Fabric version used by the testing infrastructure is now
Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2
5. Slightly rearranged the imports & constants in some of the tests
which made it easier to verify that the new image is working as intended.
6. The new image built from this dockerfile for Fabric AIO 2.x is tagged
on the registry as:
`ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358`
7. increased the tap timeout from 900 seconds (15 minutes) to 3600 (an hour)

Fixes hyperledger-cacti#2358

Signed-off-by: Peter Somogyvari <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants