FAQ
I want to start the Go runtime from a C file. Someone previously suggesting
calling main (or possibly renaming it first?) from one of the rt0 assembly
files (for me it would be rt0_linux_amd64.s). Could I get any resources on
how to do this or examples of people doing this before? I heard it was used
on Androids to start the Go runtime. I'm just a little hazy on how to go
about this, so I would really appreciate any suggestions/resources on
pulling this together. Thanks!

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

Search Discussions

  • Rob Pike at Jan 14, 2015 at 11:23 pm
    What you're suggesting sounds like a solution to the wrong problem. What
    are you really trying to do?

    -rob

    On Thu, Jan 15, 2015 at 10:18 AM, eatonphil wrote:

    I want to start the Go runtime from a C file. Someone previously
    suggesting calling main (or possibly renaming it first?) from one of the
    rt0 assembly files (for me it would be rt0_linux_amd64.s). Could I get any
    resources on how to do this or examples of people doing this before? I
    heard it was used on Androids to start the Go runtime. I'm just a little
    hazy on how to go about this, so I would really appreciate any
    suggestions/resources on pulling this together. Thanks!

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+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-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Philneaton95 at Jan 14, 2015 at 11:28 pm
    I want to be able to call a Go function from shared object libraries like
    Apache modules or Node.js addons. I have a github repo here
    <https://github.com/eatonphil/mod_frugal> detailing my previous attempt. It
    works pretty well (compile-wise) but it obviously fails at runtime when it
    is trying to reference __go_new. I posted here before and the best solution
    I got was to start the runtime before I tried to make any calls to Go
    functions since this is not currently supported in Go otherwise. I am not
    an assembly expert so I could really use help figuring out how to call
    (which might include renaming first) main in my rt0 file so I can make a
    call to an external Go function.

    Thanks!

    On Wednesday, January 14, 2015 at 6:23:23 PM UTC-5, Rob 'Commander' Pike
    wrote:
    What you're suggesting sounds like a solution to the wrong problem. What
    are you really trying to do?

    -rob


    On Thu, Jan 15, 2015 at 10:18 AM, eatonphil <philne...@gmail.com
    <javascript:>> wrote:
    I want to start the Go runtime from a C file. Someone previously
    suggesting calling main (or possibly renaming it first?) from one of the
    rt0 assembly files (for me it would be rt0_linux_amd64.s). Could I get any
    resources on how to do this or examples of people doing this before? I
    heard it was used on Androids to start the Go runtime. I'm just a little
    hazy on how to go about this, so I would really appreciate any
    suggestions/resources on pulling this together. Thanks!

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Rob Pike at Jan 14, 2015 at 11:35 pm
    You really can't do that, at least not yet. The Go runtime needs to own the
    process, which means it needs to boot it up. You can call C from Go but not
    the other way around.

    There are plans to make this possible but no timeline for implementing
    them. It's hard.

    -rob

    On Thu, Jan 15, 2015 at 10:28 AM, wrote:

    I want to be able to call a Go function from shared object libraries like
    Apache modules or Node.js addons. I have a github repo here
    <https://github.com/eatonphil/mod_frugal> detailing my previous attempt.
    It works pretty well (compile-wise) but it obviously fails at runtime when
    it is trying to reference __go_new. I posted here before and the best
    solution I got was to start the runtime before I tried to make any calls to
    Go functions since this is not currently supported in Go otherwise. I am
    not an assembly expert so I could really use help figuring out how to call
    (which might include renaming first) main in my rt0 file so I can make a
    call to an external Go function.

    Thanks!

    On Wednesday, January 14, 2015 at 6:23:23 PM UTC-5, Rob 'Commander' Pike
    wrote:
    What you're suggesting sounds like a solution to the wrong problem. What
    are you really trying to do?

    -rob

    On Thu, Jan 15, 2015 at 10:18 AM, eatonphil wrote:

    I want to start the Go runtime from a C file. Someone previously
    suggesting calling main (or possibly renaming it first?) from one of the
    rt0 assembly files (for me it would be rt0_linux_amd64.s). Could I get any
    resources on how to do this or examples of people doing this before? I
    heard it was used on Androids to start the Go runtime. I'm just a little
    hazy on how to go about this, so I would really appreciate any
    suggestions/resources on pulling this together. Thanks!

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@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-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+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-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Philneaton95 at Jan 14, 2015 at 11:43 pm
    I see. I'm interested to learn more about the difficulties. Are there any
    blog posts or other resources discussing this limitation?

    On Wednesday, January 14, 2015 at 6:35:44 PM UTC-5, Rob 'Commander' Pike
    wrote:
    You really can't do that, at least not yet. The Go runtime needs to own
    the process, which means it needs to boot it up. You can call C from Go but
    not the other way around.

    There are plans to make this possible but no timeline for implementing
    them. It's hard.

    -rob


    On Thu, Jan 15, 2015 at 10:28 AM, <philne...@gmail.com <javascript:>>
    wrote:
    I want to be able to call a Go function from shared object libraries like
    Apache modules or Node.js addons. I have a github repo here
    <https://github.com/eatonphil/mod_frugal> detailing my previous attempt.
    It works pretty well (compile-wise) but it obviously fails at runtime when
    it is trying to reference __go_new. I posted here before and the best
    solution I got was to start the runtime before I tried to make any calls to
    Go functions since this is not currently supported in Go otherwise. I am
    not an assembly expert so I could really use help figuring out how to call
    (which might include renaming first) main in my rt0 file so I can make a
    call to an external Go function.

    Thanks!

    On Wednesday, January 14, 2015 at 6:23:23 PM UTC-5, Rob 'Commander' Pike
    wrote:
    What you're suggesting sounds like a solution to the wrong problem. What
    are you really trying to do?

    -rob

    On Thu, Jan 15, 2015 at 10:18 AM, eatonphil wrote:

    I want to start the Go runtime from a C file. Someone previously
    suggesting calling main (or possibly renaming it first?) from one of the
    rt0 assembly files (for me it would be rt0_linux_amd64.s). Could I get any
    resources on how to do this or examples of people doing this before? I
    heard it was used on Androids to start the Go runtime. I'm just a little
    hazy on how to go about this, so I would really appreciate any
    suggestions/resources on pulling this together. Thanks!

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@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-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Rob Pike at Jan 15, 2015 at 12:04 am
    https://docs.google.com/a/golang.org/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelrAP0NqSS_00RgZQ

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Phil Eaton at Jan 15, 2015 at 12:33 am
    Thanks for that! That's really helpful about the plans for the future but
    not so helpful describing why the limitations are currently the way they
    are. I.e. what design decisions led to this point. I'm also interested in
    that aspect.

    So if I wanted to start working on a substitute runtime by (e.g.) defining
    the symbols I'm missing (like __go_new). How can I go about finding out
    more information? In particular what is this __go_new function? I grepped
    for it in the goland source and didn't find anything. If I could correctly
    define these symbols and link against them in my process, couldn't I get
    this working?

    I've included the shared object file that links against a go object file
    generated from libtool and gccgo. Feel free to find the __go_new reference
    I'm referring to. I'm assuming this is a memory management function?

    Thanks!


    --
    Phil Eaton

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

    On Wed, Jan 14, 2015 at 4:33 PM, Phil Eaton wrote:
    Thanks for that! That's really helpful about the plans for the future but
    not so helpful describing why the limitations are currently the way they
    are. I.e. what design decisions led to this point. I'm also interested in
    that aspect.
    The Go runtime expects to be invoked at the start of the process. It
    reads the auxiliary vector passed in by the kernel. It sets up signal
    handlers. It allocates large chunks of contiguous memory. It
    allocates thread local storage slots.

    So if I wanted to start working on a substitute runtime by (e.g.) defining
    the symbols I'm missing (like __go_new). How can I go about finding out more
    information? In particular what is this __go_new function? I grepped for it
    in the goland source and didn't find anything. If I could correctly define
    these symbols and link against them in my process, couldn't I get this
    working?

    I've included the shared object file that links against a go object file
    generated from libtool and gccgo. Feel free to find the __go_new reference
    I'm referring to. I'm assuming this is a memory management function?
    Admittedly things are a little different with gccgo. With gccgo it is
    more feasible to start the program as a C program. Earlier you
    mentioned rt0_linux_amd64.s, but that is part of the gc toolchain, not
    gccgo.

    With gccgo, look at main in libgo/runtime/go-main.c and runtime_main
    in libgo/runtime/proc.c. If you can arrange to have all those steps
    occur up to the point of the call to main_main, then you have a
    fighting chance of having it work. I've never tried it and there may
    be serious problems.

    __go_new is defined in libgo/runtime.

    Ian

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 14, '15 at 11:18p
activeJan 15, '15 at 1:14a
posts8
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase