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: fail to overwrite symbols of generics in -linkshared modus #64801

Closed
j-licht opened this issue Dec 19, 2023 · 5 comments
Closed

cmd/link: fail to overwrite symbols of generics in -linkshared modus #64801

j-licht opened this issue Dec 19, 2023 · 5 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@j-licht
Copy link

j-licht commented Dec 19, 2023

Go version

go version go1.21.3 linux/amd64

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

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/licht/.cache/go-build'
GOENV='/home/licht/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/licht/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/licht/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='x86_64-pc-linux-gnu-gcc'
CXX='x86_64-pc-linux-gnu-g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-I/usr/include/elogind/'
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 -ffile-prefix-map=/tmp/go-build4175278028=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I'm trying to build https://github.com/j-licht/generics-linkshared/tree/main with go build -linkshared.
Which is a little Demo Code for tailscale/tailscale#6597
Basically I've a package wich provides a function with a generic and in two different places the generic is used with the same type.

What did you expect to see?

Successful build as without the -linkshared option

What did you see instead?

this error:

# github.com/j-licht/generics-linkshared
link: duplicated definition of symbol github.com/j-licht/generics-linkshared/generic.GenericDemo[go.shape.bool].Println.func1, from github.com/j-licht/generics-linkshared/generic and main
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 19, 2023
@mauri870
Copy link
Member

/cc @golang/compiler

@mauri870 mauri870 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 19, 2023
@cherrymui
Copy link
Member

Could you share the exact commands you run, and its output? Please also note that the shared build mode and linkshared are stateful, meaning that the behavior of the command varies depending on what packages have been built into shared libraries and installed into GOROOT/pkg and GOPATH/pkg. So could you share what shared libraries have been built and installed? That is, what commands you run from a fresh Go installation and empty GOPATH?

Also note that the linkshared feature predates generics and is supported mostly for legacy and compatibility reasons. There is no plan to make any improvements.

Thanks.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 19, 2023
@cherrymui cherrymui added this to the Unplanned milestone Dec 19, 2023
@j-licht
Copy link
Author

j-licht commented Dec 19, 2023

The demo already fails in a clean installation:

docker run --rm -v $(pwd):/work golang:1.21.3-alpine3.17 /bin/sh -c "cd /work && apk add build-base && go build -linkshared"
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
(1/20) Installing libgcc (12.2.1_git20220924-r4)
(2/20) Installing libstdc++ (12.2.1_git20220924-r4)
(3/20) Installing binutils (2.39-r2)
(4/20) Installing libmagic (5.43-r0)
(5/20) Installing file (5.43-r0)
(6/20) Installing libgomp (12.2.1_git20220924-r4)
(7/20) Installing libatomic (12.2.1_git20220924-r4)
(8/20) Installing gmp (6.2.1-r2)
(9/20) Installing isl25 (0.25-r1)
(10/20) Installing mpfr4 (4.1.0-r0)
(11/20) Installing mpc1 (1.2.1-r1)
(12/20) Installing gcc (12.2.1_git20220924-r4)
(13/20) Installing libstdc++-dev (12.2.1_git20220924-r4)
(14/20) Installing musl-dev (1.2.3-r5)
(15/20) Installing libc-dev (0.7.2-r3)
(16/20) Installing g++ (12.2.1_git20220924-r4)
(17/20) Installing make (4.3-r1)
(18/20) Installing fortify-headers (1.1-r1)
(19/20) Installing patch (2.7.6-r9)
(20/20) Installing build-base (0.5-r3)
Executing busybox-1.35.0-r29.trigger
OK: 245 MiB in 36 packages
go: downloading github.com/godbus/dbus/v5 v5.0.4
# github.com/j-licht/generics-linkshared
link: duplicated definition of symbol github.com/j-licht/generics-linkshared/generic.GenericDemo[go.shape.bool].Println.func1, from github.com/j-licht/generics-linkshared/generic and main

@cherrymui
Copy link
Member

cherrymui commented Dec 19, 2023

Thanks. It seems you're using module mode. Please note that the shared build mode and linkshared don't work in module mode, see e.g. #38499 and #42189. Also, -linkshared is intended to link with already installed shared libraries, i.e. with some shared libraries installed with go install -buildmode=shared command . But there is no installed shared libraries in your case. So -linkshared, even if the linking doesn't fail, will not do anything useful. Thanks.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@j-licht
Copy link
Author

j-licht commented Dec 19, 2023

I agree it doesn't make any sense without pre installing shared libraries. The use case comes from yocto linux, where they install std as shared library.
So I dropped the dbus module from the demo and added the std installation to the docker command:

docker run --rm -v $(pwd):/work golang:1.21.3-alpine3.17 /bin/sh -c "cd /work && apk add build-base && go install -linkshared -buildmode=shared std && go build -linkshared"
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
(1/20) Installing libgcc (12.2.1_git20220924-r4)
(2/20) Installing libstdc++ (12.2.1_git20220924-r4)
(3/20) Installing binutils (2.39-r2)
(4/20) Installing libmagic (5.43-r0)
(5/20) Installing file (5.43-r0)
(6/20) Installing libgomp (12.2.1_git20220924-r4)
(7/20) Installing libatomic (12.2.1_git20220924-r4)
(8/20) Installing gmp (6.2.1-r2)
(9/20) Installing isl25 (0.25-r1)
(10/20) Installing mpfr4 (4.1.0-r0)
(11/20) Installing mpc1 (1.2.1-r1)
(12/20) Installing gcc (12.2.1_git20220924-r4)
(13/20) Installing libstdc++-dev (12.2.1_git20220924-r4)
(14/20) Installing musl-dev (1.2.3-r5)
(15/20) Installing libc-dev (0.7.2-r3)
(16/20) Installing g++ (12.2.1_git20220924-r4)
(17/20) Installing make (4.3-r1)
(18/20) Installing fortify-headers (1.1-r1)
(19/20) Installing patch (2.7.6-r9)
(20/20) Installing build-base (0.5-r3)
Executing busybox-1.35.0-r29.trigger
OK: 245 MiB in 36 packages
# github.com/j-licht/generics-linkshared
link: duplicated definition of symbol github.com/j-licht/generics-linkshared/generic.GenericDemo[go.shape.bool].Println.func1, from github.com/j-licht/generics-linkshared/generic and main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants