Re: [go-nuts] Getting a function's linked address?

2020-01-15 Thread Julio Guerra
For the record, I could do what I needed using the `//go:linkname` 
directive.

My instrumentation tool injects statements that need features from another 
package that I cannot import. So I forward declare functions using a given 
link name that is implemented in another package - similarly to what can be 
found in the stdlib.

This way, the forward declarations get resolved at link time - similarly to 
what you can do with `extern` with GCC.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e871a4f3-b9e4-4714-aec1-ca0fa95232f4%40googlegroups.com.


[go-nuts] Re: How to print an AST without formatting?

2020-01-09 Thread Julio Guerra
I saw `go tool cover` does it, but I don't see anything else but a simple 
call to printer.Fprint(w, f.fset, f.astFile) at 
https://github.com/golang/tools/blob/master/cmd/cover/cover.go#L384

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/362b2c19-8dfa-455d-bf74-04d9c1ff589a%40googlegroups.com.


[go-nuts] How to print an AST without formatting?

2020-01-09 Thread julio
Hello,

I am looking for a way to keep to original token positioning but I cannot 
find how to avoid it when using `go/printer` or `go/format`.
Basically, how to make this example print the same string that was parsed: 
https://play.golang.org/p/dI7WcevQJAZ

Thanks for your help!
Julio

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fbf8e5b6-f237-470c-9267-246132a2e0bc%40googlegroups.com.


[go-nuts] Re: Enforcing a type name rather than a variable name

2020-01-03 Thread julio
By the way, here is the function having this in package `net`: 
https://golang.org/src/net/lookup.go#L81

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3365c11e-918e-4bd7-989b-46868148b1ec%40googlegroups.com.


[go-nuts] Enforcing a type name rather than a variable name

2020-01-03 Thread julio
Hello,

Is there any way to avoid the compilation error "*error is not a type" of 
this example https://play.golang.org/p/gWNStGSCfTm ?
I understand the variable named `error` hides the type named `error` but is 
there some other syntax to specify the error type?

I am facing this issue while writing an instrumentation tool: some 
functions the tool instruments have such signatures, while the tool add Go 
code referencing the type name, not the variable name.

Thanks for your help

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8612f73c-bfb4-4bce-a5d3-3567ee2cbd9a%40googlegroups.com.


Re: [go-nuts] Assigning a value to a function pointer

2019-12-23 Thread julio


> > But I cannot find any way of assigning a value to the function pointer 
> `f` even using the `unsafe` package. 
>
> https://play.golang.org/p/qP5kuSCW6dO 
>

Thanks, unfortunately the asm shows that what gets into `f` is the stack 
address of `f0` and not the address of the function:

LEAQ"".foo·f(SB), DX
MOVQDX, "".f0(SP) // f0 = foo
MOVQ"".f0(SP), DX // f = 
MOVQ(DX), AX // *f

I'd love to find how to directly use the address without any local variable 
:-)

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3ac144bc-7d4c-4400-945a-33d2163780cd%40googlegroups.com.


[go-nuts] Assigning a value to a function pointer

2019-12-23 Thread julio
Hello,

The following Go program has a valid syntax:
https://play.golang.org/p/V7bIGnTu1fb

But I cannot find any way of assigning a value to the function pointer `f` 
even using the `unsafe` package.
My main reason for willing this is to be able to:
- atomically load a dynamic address.
- avoid using instead `*interface{}` (that I can atomically load + 
type-assert + call).

Thanks for your help,
Julio

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/175966b4-d900-4f7b-bfb4-c99fc4ed9f6b%40googlegroups.com.


Re: [go-nuts] Getting a function's linked address?

2019-10-31 Thread julio . nemesis

>
> You can create a lookup table at run time.  What would change if you 
> could do it at link time?  Can you show us the code you want to write? 
>

This is actually linked to my remark on build-time source instrumentation 
on https://github.com/golang/go/issues/35204 : I insert hooks into 
functions and then use a lookup table to find them at run time. Currently, 
they are created using a function which adds the newly created pointer into 
a global map, thus done at "Go init time". But if we say that I shouldn't 
add new dependencies when from a -toolexec tool, I need to create this same 
lookup table differently.

TBH, I just would like to know if getting a symbol address at link time is 
possible. Because I actually found today a workaround to be able to add new 
dependencies my -toolexec tool. But I may need to do this later on.

The other idea I had in mind was using the gosymtab to find function 
adresses but it looks like this section is not always present and I am not 
sure how long it will be supported.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e3c50e8b-f1d0-47a2-ae03-53b2ae4f00db%40googlegroups.com.


Re: [go-nuts] Getting a function's linked address?

2019-10-30 Thread julio . nemesis
I was meaning an equivalent to declaring an extern function using the same name 
as the symbol we want. The function address will be the linked symbol address.

I indeed use the reflect package today, but this happen at run time while I 
would like to get those values at link time. I'd like to create a lookup table 
to function addresses.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3c4465bd-aeac-4188-98d2-810e19541c5b%40googlegroups.com.


[go-nuts] Getting a function's linked address?

2019-10-29 Thread julio . nemesis
Hello,

I am wondering if it is possible to get the address of a function but at 
link-time. Kind of the equivalent to the C keyword `extern`.

Maybe using the link name directive? But it is not super clear to me.

I would like to get them instead at link time instead of using the gosymtab.

Thank you

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7649f370-2720-4630-b441-e08b7709f960%40googlegroups.com.


[go-nuts] Distributing Go bindings: Go plugin vs Go archive vs Go shared package

2019-09-10 Thread julio
Hello!

I am trying to find out the best way to distribute Go bindings to a C 
library. I would like to avoid asking my users to install their target gcc 
because of cgo. So my idea is to avoid cgo by avoiding having my user 
compiling the bindings, by therefore distributing an already compiled 
package for every target GOOS and GOARCH.

Some discussions on Go plugins I found are about this precise case but it 
is not supported on Windows so far. 
But I really don't get why isn't it possible to simply use the archive 
build mode `-buildmode archive` on the bindings, then include the resulting 
Go package archive in the repo, and simply use some go CLI option in order 
to use the correct archive for the target GOOS/GOARCH?

I couldn't find out how to pass such option to the go compiler so far, so I 
was hoping for some help.

Thanks for your help,
Julio

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/601106da-f825-47cf-b0b1-56a2e026d7e4%40googlegroups.com.


[go-nuts] How to safely convert a pointer to *unsafe.Pointer

2019-07-19 Thread julio
Hello,

I would like to make sure that the following line of Go is a defined 
behavior:

 addr := (*unsafe.Pointer)((unsafe.Pointer)())

I use it to perform atomic loads and stores to addr such as in this simple 
example: https://play.golang.org/p/DpDrRvTYMG8
It allows me not to use atomic.Value which performs two atomic operations 
and possible disable preemption (
https://golang.org/src/sync/atomic/value.go?s=1233:1269#L35).

Thanks for your help,
Julio

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3bc36e02-c821-4241-b929-c9c5abd5b4b7%40googlegroups.com.


Re: [go-nuts] [RFC] Dynamically instrumentation Go binaries

2018-11-19 Thread Julio Guerra
On Thu, Nov 15, 2018 at 9:57 PM Tristan Colgate  wrote:

> Maybe you mean something like support for linux uprobes?
> There is some discussion here:
> https://github.com/golang/go/issues/22008
> Google for "golang uprobes" picks up a couple of other links:
>
> http://www.brendangregg.com/blog/2017-01-31/golang-bcc-bpf-function-tracing.html
>
> https://kinvolk.io/blog/2017/09/an-update-on-gobpf---elf-loading-uprobes-more-program-types/
>

Ran a small benchmark using uprobes and there's no overhead for an io-bound
function, for a cpu-bound function, it is twice slower. So it may be a very
good solution for a first linux-only version, as I don't need return probes
(uretprobes seem to be a problem with Go's dynamic stack management).

-- 
Julio Guerra

-- 
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] [RFC] Dynamically instrumentation Go binaries

2018-11-19 Thread Julio Guerra
On Thu, Nov 15, 2018 at 7:55 PM Michael Jones 
wrote:

> You could study Rob Pike’s coverage/profiling tool to see how he adds and
> exploits basic block counting.  Good work as always.
>

Good idea, thanks. I had a look at the implementation of it, and at the way
it is integrated into the go toolchain. Unfortunately, it doesn't seem
possible to include extra compilation stages in the toolchain. I was hoping
for a way to insert an extra step to be able to modify the AST to insert
tracepoints.

So, for example, coverage is built inside `go test` by directly calling `go
cover`, and it doesn't use any plugin interface :(

-- 
Julio Guerra

-- 
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] Re: [RFC] Dynamically instrumentation Go binaries

2018-11-19 Thread Julio Guerra
On Fri, Nov 16, 2018 at 12:06 AM Damian Gryski  wrote:

> One approach would be to augment the compiler to instrument the binary
> with the techniques outlined in:
>
> XRay: A Function Call Tracing System
> https://ai.google/research/pubs/pub45287
>
>
Yes, this is very likely the best option for performance and to avoid code
relocation at run time... Unfortunately, the go toolchain currently doesn't
have any "plugin" interface to add extra compilation stages.

-- 
Julio Guerra

-- 
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] [RFC] Dynamically instrumentation Go binaries

2018-11-15 Thread julio
Hi,

I am working on dynamic instrumentation of Go programs at run time, 
possibly without static source-code instrumentation. As I would like a 
solution as close to Go and standard as possible, I was first thinking of 
using `go generate` to generate a file adding things `reflect` doesn't 
provide such as the list of packages, functions, global variables... That 
way, I should be able to use `reflect` to modify any dynamic calls by 
modifying the method tables of their underlying type representations.

But regarding statically linked calls, the less intrusive technique I 
found are uprobes, which is linux-specific. And at the opposite, there are 
user-space binary code instrumentation libraries such as dyninst that 
modify the code at run time...

So I am wondering if anyone here has any thoughts on this subject, that 
doesn't seem to be solved for Go programs.

Thanks!

Julio

-- 
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] Is it safe to invoke len(channel) on multi-gorountine

2017-06-17 Thread julio . nemesis
I almost got into the trap with this, trying to prioritize selected 
channel...
https://play.golang.org/p/VOrPwx7HC_

-- 
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.