FAQ
Hi all,

As those of you who drink the golang-codereviews firehose will have
noticed, I've started pushing up some changes for review that move in
the direction of supporting building Go packages into shared
libraries.

In particular these 7 CLs:

  * https://go-review.googlesource.com/8234 “runtime: rename ·main·f to
·mainPC to avoid duplicate symbol”
  * https://go-review.googlesource.com/7797 “cmd/internal/gc: provide
value for importpath of package being compiled”
  * https://go-review.googlesource.com/8230 “cmd/internal/ld: handle
TLS and imported symbols more regularly”
  * https://go-review.googlesource.com/8235 “cmd/internal/obj,etc:
replace -shared with -buildmode=c-shared”
  * https://go-review.googlesource.com/8236 “cmd/internal/{gc,ld}:
"support" -buildmode=shared & -linkshared”
  * https://go-review.googlesource.com/8237 “cmd/internal/obj/x86,
cmd/internal/ld, cmd/6l: support accessing global data …”
  * https://go-review.googlesource.com/8252 “cmd/internal/ld: support
for -buildmode=shared”

implement the toolchain support for -buildmode=shared from Ian's "go
execution modes" document -- but not the -linkshared part, so it's not
that useful yet. They're also not all really ready for submission.
I'd hoped to have the go tool support up for review as well but I've
run out of time.

The other CLs I've pushed today are all steps on the way to
-linkshared support. I have an implementation of both
-buildmode=shared and -linkshared on github (at
https://github.com/mwhudson/go/tree/linker-command-line) so I know it
works, although the changes in that branch are a jumbled mess.
Hopefully I'll be able to get cleaner versions of all this up as CLs
tomorrow.

Cheers,
mwh

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael Hudson-Doyle at Apr 1, 2015 at 3:57 am

    On 30 March 2015 at 22:19, Michael Hudson-Doyle wrote:
    Hi all,

    As those of you who drink the golang-codereviews firehose will have
    noticed, I've started pushing up some changes for review that move in
    the direction of supporting building Go packages into shared
    libraries.
    Hi again,

    I've just mailbombed golang-codereviews yet again, this time with a
    working prototype of -buildmode=shared & -linkshared support. A quick
    demo (after running ./make.bash):

    mwhudson@narsil:src$ go.master install -buildmode=shared std
    mwhudson@narsil:src$ go.master install -buildmode=shared -linkshared cmd
    mwhudson@narsil:src$ du -sh ../pkg/tool/linux_amd64/
    131M ../pkg/tool/linux_amd64/
    mwhudson@narsil:src$ go.master install -linkshared cmd
    mwhudson@narsil:src$ du -sh ../pkg/tool/linux_amd64/
    13M ../pkg/tool/linux_amd64/
    mwhudson@narsil:src$ ls -lh ../pkg/linux_amd64_bm-shared/*.so
    -rw-r--r-- 1 mwhudson mwhudson 16M Apr 1 16:51
    ../pkg/linux_amd64_bm-shared/libcmd.so
    -rw-r--r-- 1 mwhudson mwhudson 37M Apr 1 16:51
    ../pkg/linux_amd64_bm-shared/libstd.so

    The branch is on github at
    https://github.com/mwhudson/go/tree/linkshared-integration if you want
    to try it out.

    I'm off until after Easter now. Thanks in advance for all comments in gerrit!

    Cheers,
    mwh

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Stephen Gutekanst at Apr 2, 2015 at 9:20 pm
    Very nice progress!

    I've played around with your branch a bit -- am I correct in my
    understanding that it does not function yet for `main` packages (it seems
    to not export `main.main` or `main.init` symbols for such packages yet)?

    Super cool work!
    Stephen
    On Tuesday, March 31, 2015 at 8:57:47 PM UTC-7, Michael Hudson-Doyle wrote:

    On 30 March 2015 at 22:19, Michael Hudson-Doyle
    <michael...@canonical.com <javascript:>> wrote:
    Hi all,

    As those of you who drink the golang-codereviews firehose will have
    noticed, I've started pushing up some changes for review that move in
    the direction of supporting building Go packages into shared
    libraries.
    Hi again,

    I've just mailbombed golang-codereviews yet again, this time with a
    working prototype of -buildmode=shared & -linkshared support. A quick
    demo (after running ./make.bash):

    mwhudson@narsil:src$ go.master install -buildmode=shared std
    mwhudson@narsil:src$ go.master install -buildmode=shared -linkshared cmd
    mwhudson@narsil:src$ du -sh ../pkg/tool/linux_amd64/
    131M ../pkg/tool/linux_amd64/
    mwhudson@narsil:src$ go.master install -linkshared cmd
    mwhudson@narsil:src$ du -sh ../pkg/tool/linux_amd64/
    13M ../pkg/tool/linux_amd64/
    mwhudson@narsil:src$ ls -lh ../pkg/linux_amd64_bm-shared/*.so
    -rw-r--r-- 1 mwhudson mwhudson 16M Apr 1 16:51
    ../pkg/linux_amd64_bm-shared/libcmd.so
    -rw-r--r-- 1 mwhudson mwhudson 37M Apr 1 16:51
    ../pkg/linux_amd64_bm-shared/libstd.so

    The branch is on github at
    https://github.com/mwhudson/go/tree/linkshared-integration if you want
    to try it out.

    I'm off until after Easter now. Thanks in advance for all comments in
    gerrit!

    Cheers,
    mwh
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Hudson-Doyle at Apr 3, 2015 at 2:07 am

    On 3 April 2015 at 10:20, Stephen Gutekanst wrote:
    Very nice progress! Thanks.
    I've played around with your branch a bit -- am I correct in my
    understanding that it does not function yet for `main` packages (it seems to
    not export `main.main` or `main.init` symbols for such packages yet)?
    It doesn't let you put main packages into shared libraries, no.
    That's by design though, so there's no "yet" about it -- I'm not sure
    what that would mean, really. If I've misunderstood, please explain
    further :)

    Cheers,
    Michael
    Super cool work!
    Stephen
    On Tuesday, March 31, 2015 at 8:57:47 PM UTC-7, Michael Hudson-Doyle wrote:

    On 30 March 2015 at 22:19, Michael Hudson-Doyle
    wrote:
    Hi all,

    As those of you who drink the golang-codereviews firehose will have
    noticed, I've started pushing up some changes for review that move in
    the direction of supporting building Go packages into shared
    libraries.
    Hi again,

    I've just mailbombed golang-codereviews yet again, this time with a
    working prototype of -buildmode=shared & -linkshared support. A quick
    demo (after running ./make.bash):

    mwhudson@narsil:src$ go.master install -buildmode=shared std
    mwhudson@narsil:src$ go.master install -buildmode=shared -linkshared cmd
    mwhudson@narsil:src$ du -sh ../pkg/tool/linux_amd64/
    131M ../pkg/tool/linux_amd64/
    mwhudson@narsil:src$ go.master install -linkshared cmd
    mwhudson@narsil:src$ du -sh ../pkg/tool/linux_amd64/
    13M ../pkg/tool/linux_amd64/
    mwhudson@narsil:src$ ls -lh ../pkg/linux_amd64_bm-shared/*.so
    -rw-r--r-- 1 mwhudson mwhudson 16M Apr 1 16:51
    ../pkg/linux_amd64_bm-shared/libcmd.so
    -rw-r--r-- 1 mwhudson mwhudson 37M Apr 1 16:51
    ../pkg/linux_amd64_bm-shared/libstd.so

    The branch is on github at
    https://github.com/mwhudson/go/tree/linkshared-integration if you want
    to try it out.

    I'm off until after Easter now. Thanks in advance for all comments in
    gerrit!

    Cheers,
    mwh
    --
    You received this message because you are subscribed to the Google Groups
    "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Fventuri at Apr 5, 2015 at 12:36 am
    I am experimenting with building applications written in Go to run under
    the OSv cloud operating system (http://osv.io/) and I too was hoping that
    there could be a way (or at least a plan for the future) to be able to
    build a full "standalone" Go program into a shared library, since currently
    OSv only runs relocatable shared objects
    (https://github.com/cloudius-systems/osv/wiki/Running-compiled-code-on-OSv).

    We were able using 'gccgo' and its shared library to run a few simple Go
    programs under OSv
    (https://groups.google.com/forum/#!topic/osv-dev/eIyzdvzXwfY); I also tried
    to use your code to build a simple 'hello' program as a shared object but I
    was not able to run it in OSv.

    I think it would really nice to have Go 1.4.2 applications running in OSv,
    and reading Ian Lance Taylor's document on the new Go execution modes made
    me think this would sometime be possible.

    Since these new Go execution modes are still being implemented and there
    might still be room for change, I was wondering if you think that the
    design not to put main packages into shared libraries might be reconsidered
    (or if you know of a different Go project working on that; I might have
    missed it).

    Thanks,
    Franco Venturi

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ian Lance Taylor at Apr 5, 2015 at 1:01 am

    On Fri, Apr 3, 2015 at 7:26 PM, wrote:
    I am experimenting with building applications written in Go to run under the
    OSv cloud operating system (http://osv.io/) and I too was hoping that there
    could be a way (or at least a plan for the future) to be able to build a
    full "standalone" Go program into a shared library, since currently OSv only
    runs relocatable shared objects
    (https://github.com/cloudius-systems/osv/wiki/Running-compiled-code-on-OSv).
    I would think that you could almost do that today by using something
    like

    go build -ldflags="-linkmode=external -extldflags=-shared"

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Fventuri at Apr 5, 2015 at 2:44 am
    Ian,
    I tried that command with the current go1.4.2 and if failed:

    go build -ldflags="-linkmode=external -extldflags=-shared" hello.go

    # command-line-arguments
    /usr/bin/ld: /var/tmp/go-link-uDE4OK/go.o: relocation R_X86_64_TPOFF32
    against `runtime.tlsg' can not be used when making a shared object;
    recompile with -fPIC
    /var/tmp/go-link-uDE4OK/go.o: error adding symbols: Bad value
    collect2: error: ld returned 1 exit status
    /usr/local/go/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful
    exit status 0x100

    This seems to be issue #9652 that Michael Hudson-Doyle opened a couple of
    months ago (https://github.com/golang/go/issues/9652); in his comments on
    that issue he says he is working on fixing it, but it looks like the use
    case he has in mind (being able to use Go packages as shared libraries) is
    different from the one specific to the way OSv runs (where even 'main'
    needs to be in the shared library).

    Franco

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ian Lance Taylor at Apr 6, 2015 at 4:05 pm

    On Sat, Apr 4, 2015 at 7:44 PM, wrote:
    I tried that command with the current go1.4.2 and if failed:

    go build -ldflags="-linkmode=external -extldflags=-shared" hello.go

    # command-line-arguments
    /usr/bin/ld: /var/tmp/go-link-uDE4OK/go.o: relocation R_X86_64_TPOFF32
    against `runtime.tlsg' can not be used when making a shared object;
    recompile with -fPIC
    /var/tmp/go-link-uDE4OK/go.o: error adding symbols: Bad value
    collect2: error: ld returned 1 exit status
    /usr/local/go/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful exit
    status 0x100
    Good point, you will need to also use -gcflags=-shared.

    I don't know if that is fully working today. I expect it will be by
    the 1.5 release.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Hudson-Doyle at Apr 7, 2015 at 4:21 am

    On 1 April 2015 at 16:57, Michael Hudson-Doyle wrote:
    On 30 March 2015 at 22:19, Michael Hudson-Doyle
    wrote:
    Hi all,

    As those of you who drink the golang-codereviews firehose will have
    noticed, I've started pushing up some changes for review that move in
    the direction of supporting building Go packages into shared
    libraries.
    Hi again,

    I've just mailbombed golang-codereviews yet again, this time with a
    working prototype of -buildmode=shared & -linkshared support. A quick
    demo (after running ./make.bash):
    And again,

    I've just pushed another update, and created a topic in gerrit this
    time, so you can see all changes at
    https://go-review.googlesource.com/#/q/topic:shlibs. T

    That doesn't seem to put them in a very useful order though, so this
    is the order of commits currently (oldest to newest):

    8b0c14c cmd/internal/obj/x86, cmd/internal/ld, cmd/6l: 6g/asm -dynlink
    accesses global data via a GOT
    f9f3449 cmd/internal/ld: add -buildmode=c-shared as an alternative to -shared
    dfc6d6f cmd/internal/ld: support for -buildmode=shared
    1f0f609 cmd/go: support -buildmode=shared
    e3cb2a4 runtime, cmd/internal/ld: initialize themoduledata slices directly
    eadc912 runtime, reflect: support multiple moduledata objects
    abf9c92 runtime, cmd/internal/ld: rename themoduledata to firstmoduledata
    06f36e9 reflect, cmd/internal/gc: look for pointer types by string
    before synthesizing
    838b267 cmd/6g: call duffcopy, duffzero via got when dynamically linking go
    ba3cd96 reflect, runtime: check equality, not identity, for method names
    3b56e43 cmd/6l: call runtime.addmoduledata from .init_array
    9875304 cmd/6l: support -linkshared
    068be5f cmd/go: start support for -linkshared
    885d9c5 cmd/internal/gc, cmd/internal/ld: fixes for global vars of
    types from other modules
    54a4f78 cmd/internal/ld: set moduledatasize correctly when -linkshared, hack

    The themes are roughly 1) support creating shared libraries, 2)
    assorted fixery to not assume all code comes from a single module, 3)
    support linking against shared libraries.

    I still have a few things I know I need to fix (mostly noted in
    TODO(mwhudson)s or commit messages I hope) but I think I'm now at a
    point where serious review of these changes would be appropriate.

    Thanks for all the review comments so far!

    Cheers,
    mwh

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedMar 30, '15 at 9:19a
activeApr 7, '15 at 4:21a
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase