Re: [go-nuts] plugin questions....

2017-03-01 Thread Ian Lance Taylor
On Tue, Feb 28, 2017 at 10:55 PM, Basile Starynkevitch
 wrote:
>
> On Wednesday, March 1, 2017 at 7:17:42 AM UTC+1, Ian Lance Taylor wrote:
>>
>> On Tue, Feb 28, 2017 at 12:44 PM, Basile Starynkevitch
>>  wrote:
>> > Can the packages defined in one plugin be visible from plugins loaded
>> > afterwards? I'm thinking of a dlopen with  RTLD_GLOBAL flag in C
>> > parlance.
>>
>> I'm not sure this really makes sense in a Go context.  I'm not sure
>> how you would refer to those symbols.
>
>
> The scenario would be the following:
>
> a plugin P1 defines the P1_foo () function. P1 is loaded (and I would like
> the name to be visible afterwards, see below). We can assume that the
> loading program & process does not have any P1_foo in it.
>
> later, another plugin P2 defines the P2_bar() function which calls P1_foo(),
> and I would like that to mean the P1_foo() function inside P1. It seems that
> this is not possible currently. (of course loading P2 before loading P1
> should fail). I don't understand why would that not make any sense.

Go, unlike C, does not have the notion of an external symbol that is
defined somewhere else to be discovered at link time.  In Go all
symbols come from imported packages.  So if P2 does not import P1,
then P2 can not refer to P1_foo.

That said, you could probably get something like this to work by using
the //go:linkname compiler directive, which is available if you import
the unsafe package.  See https://golang.org/cmd/compile.

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] plugin questions....

2017-02-28 Thread Basile Starynkevitch


On Wednesday, March 1, 2017 at 7:17:42 AM UTC+1, Ian Lance Taylor wrote:
>
> On Tue, Feb 28, 2017 at 12:44 PM, Basile Starynkevitch 
>  wrote: 
> > Can the packages defined in one plugin be visible from plugins loaded 
> > afterwards? I'm thinking of a dlopen with  RTLD_GLOBAL flag in C 
> parlance. 
>
> I'm not sure this really makes sense in a Go context.  I'm not sure 
> how you would refer to those symbols. 
>

The scenario would be the following:

a plugin *P1* defines the P1_foo () function. *P1* is loaded (and I would 
like the name to be visible afterwards, see below). We can assume that the 
loading program & process does not have any P1_foo in it.

later, *another* plugin *P2* defines the P2_bar() function which calls 
P1_foo(), and I would like that to mean the P1_foo() function inside *P1*. 
It seems that this is not possible currently. (of course loading *P2* 
before loading *P1* should fail). I don't understand why would that not 
make any sense.

Of course, once could play dirty tricks (somehow equivalent to what the 
plugin ELF machinery does internally) like using function variables (that 
is closures) systematically, for example having the main program define a 
map from string to functions and register inside that map at init time of 
the plugin.

Cheers.

-- 
Basile Starynkevitch

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] plugin questions....

2017-02-28 Thread Ian Lance Taylor
On Tue, Feb 28, 2017 at 12:44 PM, Basile Starynkevitch
 wrote:
>
> Can a plugin be made of several source files in Go?

Yes.

> How should then I
> compile a single plugin myfoo.so from several Go source files ? Can a
> plugin define several packages?

A plugin is a main package.  It can be built from as many source files
as you like.  I think a plugin can only define a single main package.


> Can a plugin contain several packages? How can I refer to symbols inside
> packages of plugins? As the usual "packagename.PublicSymbol" passed as
> argument to plugin.Lookup ? If yes, that should IMHO be documented.

As far as I know you can only refer to symbols defined in the main
package.  I could be wrong about that.


> Can one get a plugin handle for the entire program & process (like dlopen(3)
> does with a NULL filename argument on Linux)  From my understanding of
> plugin/plugin_dlopen.go this is not the case. I wish it would be the case.

You can not.


> Can the packages defined in one plugin be visible from plugins loaded
> afterwards? I'm thinking of a dlopen with  RTLD_GLOBAL flag in C parlance.

I'm not sure this really makes sense in a Go context.  I'm not sure
how you would refer to those symbols.


> I'm interested in having my Go program (monimelt on github, currently
> Feb2017 in pre-alpha stage, so nothing is working) generate at runtime some
> Go source files, compiling them as a plugin (by forking some compilation
> command at runtime), and loading them. BTW, I'm really interested in Go only
> since its plugin abilities so they matter a lot to me.

As far as I know that would work.  Note that the plugin support is
very new, is experimental, and several bugs have been reported against
it already (search for plugin at https://golang.org/issue).


> Is dladdr(3) available in Go? I would like, given a pointer, to get the name
> of the function at the same address (but I guess there could be issues with
> closures).

See runtime.FuncForPC.


> Is there any name mangling issues the user of Go plugins should be aware of?

I don't think so.  I mean, names are mangled slightly, but you
shouldn't need to know about it.

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] plugin questions....

2017-02-28 Thread Basile Starynkevitch


On Tuesday, February 28, 2017 at 10:16:27 PM UTC+1, Ian Lance Taylor wrote:
>
> On Tue, Feb 28, 2017 at 12:44 PM, Basile Starynkevitch 
>  wrote: 
> > 
> > A few questions and wishes about plugins (Go1.8 Linux/amd64) 
>
> Sorry, but you need to indicate whether you are talking about 
> -buildmode=plugin (an experimental option to build plugins that may be 
> opened by Go programs) or -buildmode=c-shared (a supported option to 
> build plugins that may be opened by non-Go programs). 
>

I'm talking about plugins written in Go for a Go program, so 
-buildmode=plugin
(I'm coding in Go because I don't want to code my multi-thread friendly GC 
in C++ or C)
 

>
> 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] plugin questions....

2017-02-28 Thread Ian Lance Taylor
On Tue, Feb 28, 2017 at 12:44 PM, Basile Starynkevitch
 wrote:
>
> A few questions and wishes about plugins (Go1.8 Linux/amd64)

Sorry, but you need to indicate whether you are talking about
-buildmode=plugin (an experimental option to build plugins that may be
opened by Go programs) or -buildmode=c-shared (a supported option to
build plugins that may be opened by non-Go programs).

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] plugin questions....

2017-02-28 Thread Basile Starynkevitch
Hello All,

A few questions and wishes about plugins (Go1.8 Linux/amd64)

Can a plugin be made of several source files in Go? How should then I 
compile a single plugin myfoo.so from several Go source files ? Can a  
plugin define several packages? 

Can a plugin contain several packages? How can I refer to symbols inside 
packages of plugins? As the usual "packagename.PublicSymbol" passed as 
argument to plugin.Lookup  ? If yes, that 
should IMHO be documented.

Can one get a plugin handle for the entire program & process (like dlopen(3) 
 does with a NULL 
*filename* argument on Linux)  From my understanding of 
plugin/plugin_dlopen.go  
this is not the case. I wish it would be the case.

Can the packages defined in one plugin be visible from plugins loaded 
afterwards? I'm thinking of a dlopen with  *RTLD_GLOBAL *flag in C parlance.

I'm interested in having my Go program (monimelt 
 on github, currently Feb2017 in 
pre-alpha stage, so nothing is working) generate at runtime some Go source 
files, compiling them as a plugin (by forking some compilation command at 
runtime), and loading them. BTW, I'm really interested in Go only since its 
plugin abilities so they matter a lot to me.

Is dladdr(3)  available 
in Go? I would like, given a pointer, to get the name of the function at 
the same address (but I guess there could be issues with closures).

Is there any name mangling  
issues the user of Go plugins should be aware of?

Regards.


-- 
Basile Starynkevitch (France)   -   http://starynkevitch.net/Basile/ 



-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.