yunabe/lgo

Can't install external packages

Closed this issue · 2 comments

pebbe commented

I can't install external packages that work fine with regular Go.

~ go version
go version go1.9.5 linux/amd64
~ jupyter --version
4.4.0
~ export LGOPATH=$HOME/lgo
~ mkdir $LGOPATH
~ go get github.com/yunabe/lgo/cmd/lgo && go get -d github.com/yunabe/lgo/cmd/lgo-internal
~ lgo install
2018/04/24 12:10:14 Install lgo to /home/peter/lgo
2018/04/24 12:10:14 Building libstd.so
2018/04/24 12:10:21 Building lgo core package
2018/04/24 12:10:22 Building third-party packages in $GOPATH
2018/04/24 12:10:22 Installing lgo-internal
2018/04/24 12:10:24 lgo was installed in /home/peter/lgo successfully
~ go get github.com/pebbe/util
~ lgo installpkg github.com/pebbe/util
# /tmp/go-build211418391/libgithub.com-pebbe-util.so
github.com/pebbe/util.Open: missing section for relocation target github.com/pebbe/util.(*ReadCloser).Close·f
github.com/pebbe/util.Open: missing section for relocation target github.com/pebbe/util.(*ReadCloser).Close·f
github.com/pebbe/util.Open: missing section for relocation target github.com/pebbe/util.(*ReadCloser).Close·f
github.com/pebbe/util.Open: reloc 26 to non-elf symbol github.com/pebbe/util.(*ReadCloser).Close·f (outer=github.com/pebbe/util.(*ReadCloser).Close·f) 0
github.com/pebbe/util.Open: reloc 26 to non-elf symbol github.com/pebbe/util.(*ReadCloser).Close·f (outer=github.com/pebbe/util.(*ReadCloser).Close·f) 0
github.com/pebbe/util.Open: reloc 26 to non-elf symbol github.com/pebbe/util.(*ReadCloser).Close·f (outer=github.com/pebbe/util.(*ReadCloser).Close·f) 0
github.com/pebbe/util.Open: undefined: "github.com/pebbe/util.(*ReadCloser).Close·f"
github.com/pebbe/util.Open: undefined: "github.com/pebbe/util.(*ReadCloser).Close·f"
github.com/pebbe/util.Open: undefined: "github.com/pebbe/util.(*ReadCloser).Close·f"
(1/1) failed to install "github.com/pebbe/util": exit status 2
2018/04/24 12:12:19 failed to install .so files
~ python $(go env GOPATH)/src/github.com/yunabe/lgo/bin/install_kernel
Installing Jupyter kernel spec
~ jupyter console --kernel lgo
Jupyter console 5.2.0

lgo


In [1]: import "github.com/pebbe/util"
found packages not installed in LGOPATH: [github.com/pebbe/util]
# /tmp/go-build777551001/libgithub.com-pebbe-util.so
github.com/pebbe/util.Open: missing section for relocation target github.com/pebbe/util.(*ReadCloser).Close·f
github.com/pebbe/util.Open: missing section for relocation target github.com/pebbe/util.(*ReadCloser).Close·f
github.com/pebbe/util.Open: missing section for relocation target github.com/pebbe/util.(*ReadCloser).Close·f
github.com/pebbe/util.Open: reloc 26 to non-elf symbol github.com/pebbe/util.(*ReadCloser).Close·f (outer=github.com/pebbe/util.(*ReadCloser).Close·f) 0
github.com/pebbe/util.Open: reloc 26 to non-elf symbol github.com/pebbe/util.(*ReadCloser).Close·f (outer=github.com/pebbe/util.(*ReadCloser).Close·f) 0
github.com/pebbe/util.Open: reloc 26 to non-elf symbol github.com/pebbe/util.(*ReadCloser).Close·f (outer=github.com/pebbe/util.(*ReadCloser).Close·f) 0
github.com/pebbe/util.Open: undefined: "github.com/pebbe/util.(*ReadCloser).Close·f"
github.com/pebbe/util.Open: undefined: "github.com/pebbe/util.(*ReadCloser).Close·f"
github.com/pebbe/util.Open: undefined: "github.com/pebbe/util.(*ReadCloser).Close·f"
(1/1) failed to install "github.com/pebbe/util": exit status 2
failed to install .so files

~ ls -l $LGOPATH/pkg/github.com/pebbe
totaal 76
-rw-r--r-- 1 peter peter 74992 apr 24 12:11 util.a
~ ls -l $GOPATH/pkg/linux_amd64/github.com/pebbe
totaal 72
-rw-r--r-- 1 peter peter 73020 apr 24 12:11 util.a

Wow. This is very interesting. You hit a bug of -buildmode=shared of go build.

I tried to create a minimal example to reproduce this issue and it turned out lgo can not execute the code below.

type mystruct struct {}

func (m mystruct) A() {}
func (p *mystruct) B() {}

{
    p := &mystruct{}
    (*mystruct).A(p)  // OK
    fmt.Println((*mystruct).A)  // NG
    (*mystruct).B(p)  // OK
    fmt.Println((*mystruct).B)  // OK
}

I think it's not easy to fix this issue in lgo side.
Until the bug is fixed in go, you need to modify your code to workaround this issue.

I think you can fix this issue by

  1. Change the receiver of ReadCloser.Read and Close to *ReadCloser.
    I'm not sure if there is a strong reason to use a value receiver here.
  2. Pass a wrapper function to SetFinalizer instead
    (e.g. runtime.SetFinalizer(r, func(rc *ReadCloser) {rc.Close()}))
pebbe commented

I tried this with Go 1.10 and I get the same problem.

I reported this issue: golang/go#25065