What happens if Golang calls a shared .so library via cgo but this library is built from Golang?

264 views
Skip to first unread message

rmfr

unread,
Aug 19, 2021, 9:33:39 AM8/19/21
to golang-nuts
Hi,

As the title describes, does this is allowed by the Golang's design? If it is allowed, I think there would be at least two Golang runtime running in the same process space, am I correct?

rmfr

unread,
Aug 19, 2021, 9:36:43 AM8/19/21
to golang-nuts
Please also consider what happens if this two Golang has two different version :-D
Message has been deleted

rmfr

unread,
Aug 19, 2021, 10:15:50 AM8/19/21
to golang-nuts
I just test go1.17 call go1.16.6's application shared library, it works (one binary dumps two different golang's runtime version):

```
Go version: go1.16.6
Go version: go1.17
```

Ian Lance Taylor

unread,
Aug 19, 2021, 3:19:22 PM8/19/21
to rmfr, golang-nuts
On Thu, Aug 19, 2021 at 6:34 AM rmfr <remus.cl...@gmail.com> wrote:
>
> As the title describes, does this is allowed by the Golang's design? If it is allowed, I think there would be at least two Golang runtime running in the same process space, am I correct?

Assuming you are running on an ELF system and control symbol
visibility, this can work. As you say, you would have two different
Go runtimes in the same process, competing for access to the CPU and
virtual memory. To be clear, this is not supported by the Go project.

Ian

rmfr

unread,
Aug 19, 2021, 10:30:06 PM8/19/21
to golang-nuts
Thanks a lot, Ian :-)


> Assuming you are running on an ELF system and control symbol
visibility, this can work.
> To be clear, this is not supported by the Go project.

Do you mean that this usage is not recommended in a production environment? 
And this usage maybe no longer supported by Golang runtime in future updates?

Brian Candler

unread,
Aug 20, 2021, 4:10:24 AM8/20/21
to golang-nuts

rmfr

unread,
Aug 20, 2021, 8:14:24 AM8/20/21
to golang-nuts
> Perhaps what you're trying to achieve can be done using Go Plugins instead, although beware of significant restrictions:

Thanks Brian, I have looked at it, but I am afraid its usage conditions are too strict.

Ian Lance Taylor

unread,
Aug 20, 2021, 3:00:35 PM8/20/21
to rmfr, golang-nuts
On Thu, Aug 19, 2021 at 7:30 PM rmfr <remus.cl...@gmail.com> wrote:
>
> Thanks a lot, Ian :-)
>
> > Assuming you are running on an ELF system and control symbol
> visibility, this can work.
> > To be clear, this is not supported by the Go project.
>
> Do you mean that this usage is not recommended in a production environment?
> And this usage maybe no longer supported by Golang runtime in future updates?

I mean that while it may accidentally happen to work today, it may
break in future releases. If it does break, we will not fix it to
work again. You should not assume that this will continue to behave
in the future as it behaves today.

Ian



> On Friday, August 20, 2021 at 3:19:22 AM UTC+8 Ian Lance Taylor wrote:
>>
>> On Thu, Aug 19, 2021 at 6:34 AM rmfr <remus.cl...@gmail.com> wrote:
>> >
>> > As the title describes, does this is allowed by the Golang's design? If it is allowed, I think there would be at least two Golang runtime running in the same process space, am I correct?
>>
>> Assuming you are running on an ELF system and control symbol
>> visibility, this can work. As you say, you would have two different
>> Go runtimes in the same process, competing for access to the CPU and
>> virtual memory. To be clear, this is not supported by the Go project.
>>
>> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d787ab62-b1b7-4dd1-a2c9-cf8d3d7a4cb4n%40googlegroups.com.

rmfr

unread,
Aug 20, 2021, 7:59:19 PM8/20/21
to golang-nuts
> I mean that while it may accidentally happen to work today, it may
> break in future releases. If it does break, we will not fix it to
> work again. You should not assume that this will continue to behave
> in the future as it behaves today.

I get it. Thanks a lot, Ian :-D
Reply all
Reply to author
Forward
0 new messages