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/go: go install -buildmode=shared with no directory name generates bad shared library name #12236

Closed
avdva opened this issue Aug 20, 2015 · 7 comments

Comments

@avdva
Copy link
Contributor

avdva commented Aug 20, 2015

Go v 1.5. Fedora 22 x86_64

  1. Compile and install the package named "worker":
    go install -buildmode=shared -linkshared
  2. Try to compile another package, which imports "worker":
    go build -linkshared
    go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 gcc: error: missing argument to ‘-l’
    Output with the '-x' option:
    /home/user/dev/go/pkg/tool/linux_amd64/link -o $WORK/godev/proj/_obj/exe/a.out -L $WORK -L /home/user/dev/godev/pkg/linux_amd64_dynlink -installsuffix dynlink -extld=gcc -buildmode=exe -buildid=98b4ec39a65525d2ee4614652117b2ad4dfdeb26 -linkshared -w $WORK/godev/proj.a /home/user/dev/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 gcc: error: missing argument to ‘-l
    The same command with '-x --compiler=gccgo' option produces the following:
    /usr/bin/gccgo -o $WORK/godev/testgo/_obj/exe/a.out $WORK/godev/testgo/_obj/_go_.o -Wl,-( -m64 -Wl,-) -L/home/user/dev/godev/pkg/gccgo_linux_amd64_fPIC/shlibs -Wl, -rpath=/home/user/dev/godev/pkg/gccgo_linux_amd64_fPIC/shlibs -l -Wl,-E -fPIC
    The output is:
    /usr/bin/ld: cannot find -l-Wl,-E collect2: error: ld returned 1 exit status
    It compiles well without -linkshared. Is there an error, or I just misuse these options?
@ianlancetaylor ianlancetaylor added this to the Go1.5.1 milestone Aug 21, 2015
@ianlancetaylor ianlancetaylor changed the title Go v 1.5 with -linkshared option produces linking error cmd/ld: Go v 1.5 with -linkshared option produces linking error Aug 21, 2015
@ianlancetaylor
Copy link
Contributor

It would be very helpful if you could provide complete reproduction instructions, by which I mean the contents of the files you are compiling, the names of the directories they are in, etc. Your current description is sort of vague; when I do the exact same steps it works fine. There is something different about what you are doing, and the more details you can provide the more likely it is that we can figure out what it is. Thanks.

@mikioh mikioh changed the title cmd/ld: Go v 1.5 with -linkshared option produces linking error cmd/link: Go 1.5 with -linkshared option produces linking error Aug 21, 2015
@avdva
Copy link
Contributor Author

avdva commented Aug 21, 2015

  1. Clean go 1.5 installation from golang.org
  2. Let ~/dev/gopath will be GOPATH, and into /src/ I put 2 folders: lib with lib.go and exe with exe.go
  3. cat lib.go
package lib
 func init() {
        print("package lib")
 }
  1. GOROOT=~/Apps/go-1.5-linux_amd64-vanilla/ GOPATH=~/dev/gopath/ ~/Apps/go-1.5-linux_amd64-vanilla/bin/go install -linkshared -buildmode=shared produces
    multiple roots /home/avd/dev/gopath/pkg/linux_amd64_dynlink & /home/avd/Apps/go-1.5-linux_amd64-vanilla/pkg/linux_amd64_dynlink
    So, according to that, I run GOROOT=~/Apps/go-1.5-linux_amd64-vanilla/ GOPATH=~/dev/gopath/ ~/Apps/go-1.5-linux_amd64-vanilla/bin/go install -linkshared -buildmode=shared std
    After it installation goes fine.
  2. cd ../exe/, cat exe.go
package main
import (
    _ "lib"
)
func main() {

}

GOROOT=~/Apps/go-1.5-linux_amd64-vanilla/ GOPATH=~/dev/gopath/ ~/Apps/go-1.5-linux_amd64-vanilla/bin/go install -linkshared

/home/avd/Apps/go-1.5-linux_amd64-vanilla/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 gcc: error: missing argument to ‘-l’
Probably, I do something wrong with go install -buildmode=shared -linkshared std?
If i run it without -linkshared, I get this when installing exe:
# /tmp/go-build059541814/lib.so sync/atomic.StorePointer: sync/atomic.StoreUintptr: not defined sync/atomic.SwapPointer: sync/atomic.SwapUintptr: not defined sync/atomic.CompareAndSwapPointer: sync/atomic.CompareAndSwapUintptr: not defined runtime.sync_atomic_CompareAndSwapUintptr·f: sync/atomic.CompareAndSwapUintptr: not defined runtime.sync_atomic_StoreUintptr·f: sync/atomic.StoreUintptr: not defined runtime.sync_atomic_SwapUintptr·f: sync/atomic.SwapUintptr: not defined sync/atomic.StorePointer: undefined: sync/atomic.StoreUintptr sync/atomic.SwapPointer: undefined: sync/atomic.SwapUintptr sync/atomic.CompareAndSwapPointer: undefined: sync/atomic.CompareAndSwapUintptr runtime.sync_atomic_CompareAndSwapUintptr·f: undefined: sync/atomic.CompareAndSwapUintptr runtime.sync_atomic_StoreUintptr·f: undefined: sync/atomic.StoreUintptr runtime.sync_atomic_SwapUintptr·f: undefined: sync/atomic.SwapUintptr

@ianlancetaylor
Copy link
Contributor

Thanks. I can recreate the problem. It's a bug in how the go tool generates the library name.

The workaround is: don't cd DIR and run "go install -buildmode=shared -linkshared". Instead, run "go install -buildmode=shared -linkshared DIR". The go tool is using the explicit argument to construct the library name. When you don't give it any argument, the go tool generates "lib.so". That then confuses the linker.

CC @mwhudson

@ianlancetaylor ianlancetaylor changed the title cmd/link: Go 1.5 with -linkshared option produces linking error cmd/go: go install -buildmode=shared with no directory name generates bad shared library name Aug 21, 2015
@avdva
Copy link
Contributor Author

avdva commented Aug 21, 2015

Thank you for your assistance. I am really glad to be helpful for this project)

@mwhudson
Copy link
Contributor

Oh right, this is sort of the same problem as #10473 then.

@rsc
Copy link
Contributor

rsc commented Aug 25, 2015

There's a clear workaround here. Better to use that for the 1.5 cycle. Thanks.

@rsc rsc modified the milestones: Go1.6Early, Go1.5.1 Aug 25, 2015
@gopherbot
Copy link

CL https://golang.org/cl/13921 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants