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/compile: builmode pie with linkshared when std library is also shared fails #17076

Closed
kiap opened this issue Sep 12, 2016 · 2 comments
Closed

Comments

@kiap
Copy link

kiap commented Sep 12, 2016

When compiling standard library as shared library and use buildmode pie to compile position indedependent executable from our code it fails, but if we do not compile standard library as shared library but use our own libraries as shared library it compiles successfully

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

tested with both Master and 1.7.1
go version go1.7.1 linux/amd64
&
go version devel +d817c4e Fri Sep 9 20:07:43 2016 +0000 linux/amd64

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


GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/src/dev"
GORACE=""
GOROOT="/src/dev"
GOTOOLDIR="/src/dev/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build475536354=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

and for Go 1.7.1:
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build856345781=/tmp/go-build -gno-record-gcc-switches"

What did you do?

piet.go


package main

import (
        "fmt"
        "pack1"
        "pack2"
)
func main() {
       fmt.Println("Inside Main")
        pack1.Checkit()
        pack2.Checkit()
}


pack1 package:
pack1.go


package pack1

import "fmt"

func Checkit() {

        fmt.Println("Inside pack1")

        return

}


pack2 package:
pack2.go


package pack2

import "fmt"

func Checkit() {

        fmt.Println("Inside pack2")

        return

}


What did you expect to see?

go install -v -buildmode=shared -linkshared -pkgdir '/mnt/lib/' std
go install -v -buildmode=shared -linkshared -pkgdir '/mnt/lib/' pack1
go install -v -buildmode=shared -linkshared -pkgdir '/mnt/lib/' pack2

the above all built successfully
the following should succeed now:

go install -v -buildmode=pie -linkshared -pkgdir '/mnt/lib' piet

What did you see instead?

but it fails with:
go install -v -buildmode=pie -linkshared -pkgdir '/mnt/lib' piet

piet
# piet
/src/dev/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/mnt/lib//libstd.so: undefined reference to `main.init'
/mnt/lib//libstd.so: undefined reference to `main.main'
collect2: error: ld returned 1 exit status

What ELSE?

If you do not build the std library and skip that part
rm -rf /mnt/lib
mkdir -p /mnt/lib
go install -v -buildmode=shared -linkshared -pkgdir '/mnt/lib/' pack1
go install -v -buildmode=shared -linkshared -pkgdir '/mnt/lib/' pack2
go install -v -buildmode=pie -linkshared -pkgdir '/mnt/lib' piet

It successfully builds pie binary and uses pack1 and pack2 shared libraries , you can check that with ldd

@quentinmit quentinmit changed the title builmode pie with linkshared when std library is also shared fails cmd/compile: builmode pie with linkshared when std library is also shared fails Sep 12, 2016
@quentinmit
Copy link
Contributor

/cc @mwhudson @crawshaw

@quentinmit quentinmit added this to the Go1.8Maybe milestone Sep 12, 2016
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 13, 2017
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

3 participants