Skip to content

cmd/compile: crypto/elliptic build error under -linkshared mode #58966

Closed

Description

@quaresmajose

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

$ go version
go version go1.20.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

This issue can be reproduced inside the official golang:1.20-alpine docker container and it works fine on the previous golang:1.19-alpine

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/build/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3925415831=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This error has been discovered in Yocto/OpenEmbedded that builds the go shared std library and this issue also affect
other go projects [1], the workaround to build successfully since go 1.20 is not using the -linkshared

[1] https://lists.yoctoproject.org/g/meta-virtualization/topic/97182310

Steps to reproduce:

# fetch some affected source
git clone https://github.com/foundriesio/fioconfig && cd fioconfig

# go-1.19 is good
cat > Dockerfile.shared << EOF
FROM golang:1.19-alpine
RUN mkdir /build
WORKDIR /build
RUN apk add --update --no-cache g++
COPY . .
RUN go mod download
RUN go install -buildmode=shared -linkshared std
RUN go build -linkshared -tags vpn -o ./fioconfig main.go
EOF
docker build . -f Dockerfile.shared

# go-1.20 is broken
cat > Dockerfile.shared << EOF
FROM golang:1.20-alpine
RUN mkdir /build
WORKDIR /build
RUN apk add --update --no-cache g++
COPY . .
RUN go env
RUN go mod download
RUN go install -buildmode=shared -linkshared std
RUN go build -linkshared -tags vpn -o ./fioconfig main.go
EOF
docker build . -f Dockerfile.shared

What did you expect to see?

Build my go linkshared application without any errors like on previous version 1.19.

What did you see instead?

Linking errors

# command-line-arguments
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Add
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Add
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).CombinedMult
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).CombinedMult
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Double
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Double
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).IsOnCurve
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).IsOnCurve
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Params
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Params
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).ScalarBaseMult
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).ScalarBaseMult
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).ScalarMult
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).ScalarMult
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Unmarshal
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Unmarshal
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).UnmarshalCompressed
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).UnmarshalCompressed
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).normalizeScalar
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).normalizeScalar
type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).pointFromAffine
/usr/local/go/pkg/tool/linux_amd64/link: too many errors
The command '/bin/sh -c go build -linkshared -tags vpn -o ./fioconfig main.go' returned a non-zero code: 1

Activity

  1. quaresmajose commented on Mar 10, 2023

    @quaresmajose
    Author

    It looks like the crypto/elliptic is now no more than a compatibility wrapper and the new crypto/ecdh don't implement the P-224 curves [2].

    [2] https://words.filippo.io/dispatches/go-1-20-cryptography

    @FiloSottile is the author of the blog post so he maybe know better what going on.

  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Mar 10, 2023
  3. added this to the Backlog milestone on Mar 10, 2023
  4. cagedmantis commented on Mar 10, 2023

    @cagedmantis
    Contributor

    cc @rolandshoemaker @golang/security

  5. mdempsky commented on Mar 14, 2023

    @mdempsky
    Contributor

    Standalone repro:

    $ cat x.go
    package main
    
    import "crypto/elliptic"
    
    var curve elliptic.Curve
    
    func main() {
    	switch curve {
    	case elliptic.P224():
    	}
    }
    $ go install -linkshared -buildmode=shared std
    $ go build -linkshared x.go
    # command-line-arguments
    type:*crypto/elliptic.nistCurve[*crypto/internal/nistec.P224Point]: unreachable sym in relocation: crypto/elliptic.(*nistCurve[*crypto/internal/nistec.P224Point]).Add
    ...
    

    I think this is a compiler or linker issue, not an issue with crypto/elliptic itself.

    I expect the issue has to do with instantiating generic types across DSO boundaries (due to inlining).

    /cc @golang/compiler

  6. mdempsky commented on Mar 14, 2023

    @mdempsky
    Contributor

    @cherrymui gave this explanation:

    Okay, I think I understand it a little bit. We just don't support a type symbol referencing a method symbol across DSO boundary. That reference, R_METHODOFF, is relative to the section start. But we cannot do it across the DSO boundary, because we can't reference the section in a different DSO. Also, the runtime code resolves the section-relative offset to the same runtime module that contains the type symbol.

    So, either the type symbol and the method symbol are both in the shared object, or both in the main executable. But not cross.

  7. changed the title [-]crypto/elliptic: linkshared regression in crypto/internal/nistec.P224Point since version 1.20[/-] [+]cmd/compile: crypto/elliptic build error under -linkshared mode[/+] on Mar 14, 2023
  8. cuonglm commented on Mar 15, 2023

    @cuonglm
    Member

    FYI, this is started failing since https://go-review.googlesource.com/c/go/+/443535 (with 18baca6 and de6abd7 applied for fixing go install -linkshared -buildmode=shared std)

  9. quaresmajose commented on Mar 15, 2023

    @quaresmajose
    Author

    The described steps to reproduce this issue uses GOARCH="amd64" but please note that it can be reproduced on other architectures too. At last I can reproduce the issue on arm and arm64 so maybe this is architecture independent.

  10. gopherbot commented on Mar 15, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/476735 mentions this issue: cmd/link: improve error message and debugging

  11. 8 remaining items

  12. cuonglm commented on Mar 25, 2023

    @cuonglm
    Member

    @gopherbot please backport this issue to go1.20

  13. gopherbot commented on Mar 25, 2023

    @gopherbot
    Contributor

    Backport issue(s) opened: #59236 (for 1.20).

    Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

  14. modified the milestones: Backlog, Go1.21 on Mar 29, 2023
  15. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Mar 29, 2023
  16. locked and limited conversation to collaborators on Mar 28, 2024
  17. added a commit that references this issue on Sep 29, 2026
    bcd8212
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions