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

cmd/link: musl dynamic linker/loader not found correctly #45034

Closed
dilyn-corner opened this issue Mar 15, 2021 · 3 comments
Closed

cmd/link: musl dynamic linker/loader not found correctly #45034

dilyn-corner opened this issue Mar 15, 2021 · 3 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Milestone

Comments

@dilyn-corner
Copy link

dilyn-corner commented Mar 15, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.2 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dilyn/.cache/go-build"
GOENV="/home/dilyn/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/dilyn/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/dilyn/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build888305945=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Build go from source:

export CC="${CC:-cc}"
export GOARCH=amd64
export GO_LDFLAGS="-w -s"

[ -f "$KISS_ROOT/var/db/kiss/installed/go/manifest" ] || {
    export GOROOT=$PWD/go1.4-bootstrap
    export GOROOT_FINAL=$PWD/lib/go-bootstrap

    mkdir -p lib/go-bootstrap

    cd "$GOROOT/src"
    ./make.bash
    cd ..
    cp -a bin pkg src ../lib/go-bootstrap
    cd ..
}

export GOROOT_FINAL=/usr/lib/go

if [ -f "$KISS_ROOT/var/db/kiss/go/manifest" ]; then
    export GOROOT_BOOTSTRAP=/usr/lib/go
else
    export GOROOT_BOOTSTRAP=$PWD/lib/go-bootstrap
fi

export GOROOT=$PWD/go-current

(
    cd "$GOROOT/src"
    ./make.bash --no-clean -v
)

cd "$GOROOT"

mkdir -p "$1/usr/bin" "$1/usr/lib/go/bin"

install -m755 "bin/go"    "$1/usr/lib/go/bin/go"
install -m755 "bin/gofmt" "$1/usr/lib/go/bin/gofmt"

ln -s "/usr/lib/go/bin/go"    "$1/usr/bin"
ln -s "/usr/lib/go/bin/gofmt" "$1/usr/bin"

cp -a misc pkg src lib "$1/usr/lib/go"

Build age with -buildmode=pie:

export GOPATH="$PWD/go"
mkdir -p bin
go build \
    -trimpath \
    -modcacherw \
    -buildmode=pie \
    -o bin filippo.io/age/cmd/...

mkdir -p "$1/usr/bin"
install -Dm755 bin/age        "$1/usr/bin"
install -Dm755 bin/age-keygen "$1/usr/bin"

What did you expect to see?

I expect that ldd /usr/bin/age-keygen reports:
/lib/ld-musl-x86_64.so.1

What did you see instead?

Instead, ldd reports:
/lib64/ld-linux-x86-64.so.2
Which results in a message when executing age-keygen:
sh: age-keygen: not found

@dilyn-corner
Copy link
Author

The problem specifically is here

go/src/make.bash

Lines 133 to 140 in 846dce9

# On Alpine Linux, use the musl dynamic linker/loader
if [ -f "/etc/alpine-release" ]; then
if type readelf >/dev/null 2>&1; then
echo "int main() { return 0; }" | ${CC:-gcc} -o ./test-alpine-ldso -x c -
export GO_LDSO=$(readelf -l ./test-alpine-ldso | grep 'interpreter:' | sed -e 's/^.*interpreter: \(.*\)[]]/\1/')
rm -f ./test-alpine-ldso
fi
fi

Alpine Linux is not the only musl-based distro.

@ianlancetaylor ianlancetaylor changed the title Dynamic linker/loader not found correctly cmd/link: musl dynamic linker/loader not found correctly Mar 15, 2021
@ianlancetaylor
Copy link
Contributor

Note that ldd is not a reliable way of determining the ELF interpreter recorded in the executable. Use readelf -l instead.

Patches to improve make.bash are welcome.

@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Linux labels Mar 15, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Mar 15, 2021
@gopherbot
Copy link

Change https://golang.org/cl/301989 mentions this issue: src/make.bash: this change modifies Go to correctly select a dyamic linker

@dmitshur dmitshur modified the milestones: Backlog, Go1.17 Mar 25, 2021
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 25, 2021
@golang golang locked and limited conversation to collaborators May 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants