Golang binary dwarf

Manoj Kumar manoj.gurukul@yahoo.com
Sun Feb 7 14:54:18 GMT 2021


 Hi,
Apologies for replying late.  The issue can be reproduced on Ubuntu.
Please get the attached files & copy to some folder. If golang and Dyninst 10.2.1 version are installed on system then please follow the below steps:
1. export PATH_TO_DYNINST_LIB= <path to lib folder where dyninst libraries are installed, if not under /usr/local/lib>makeThis will create c++ binary testfile
2. compile golang program usinggo build wrapecho.goThis will create wrapechoRun wrapecho (./wrapecho) from terminal 1 and run testfile (./testfile wrapecho) from terminal 2.
testfile will print the number of arguments and each argument name for each function of wrapecho (like Hellocat,hello)
3. compile golang program using linkshared option
go build -linkshared wrapecho.goThis will create wrapecho
if above command does not work then use below two commands:go install -buildmode=shared stdgo build -linkshared wrapecho.go

Run wrapecho (./wrapecho) from terminal 1 and run testfile (./testfile wrapecho)testfile will print 0 number of arguments for each function.

Please let me know if anything is required to reproduce the issue.
Thanks
    On Sunday, 7 February, 2021, 4:40:44 pm IST, Florian Weimer <fweimer@redhat.com> wrote:  
 
 * Mark Wielaard:

> Hi Manoj,
>
> On Sat, 2021-02-06 at 07:03 +0000, Manoj Kumar via Elfutils-devel
> wrote:
>> Hi,Using dyninst, I am trying to access local variables and arguments
>> of a function which is part of a go binary.To get local variables,
>> dyninst uses libdw to find all the modules. It uses dwarf_nextcu
>> function of libdw to find all the modules of binary.When I compile a
>> go binary using "go build filename.go" then dwarf_nextcu finds all
>> the modules (almost 118) and dyninst is able to access local
>> variables and arguments of any function.But when I compile a go
>> binary with linkshared option  "go build -linkshared filename.go"
>> then dwarf_nextcu finds only 5 modules. Due to that, dyninst is not
>> able to access any variable of a function.
>> Does go binary with linkshared option has different version of dwarf?
>> Could you please suggest how to use libdw for go binary with
>> linkshared option.
>
> Could you explain what the linkshared option is and what it does?

$ go tool link -help
[…]
  -linkshared
        link against installed Go shared libraries
[…]

The Fedora version is broken, unfortunately:

$ cat t.go
package main
func main() { }
$ go build -linkshared t.go 
go build runtime/internal/sys: copying /home/fweimer/.cache/go-build/ef/ef8092ebd194e7ec34c864584fc2216541454e9626c98ffe9d5210d2784da429-d: open /usr/lib/golang/pkg/linux_amd64_dynlink/runtime/internal/sys.a: permission denied
go build internal/cpu: copying /home/fweimer/.cache/go-build/ca/ca0a2dbbc130aa21613ca27f378b8c9fda02c4082687d92b40a0d6c660bc86d1-d: open /usr/lib/golang/pkg/linux_amd64_dynlink/internal/cpu.a: permission denied
[…]
$ rpm -qf /usr/bin/go
golang-bin-1.15.7-1.fc33.x86_64

Filed here: <https://bugzilla.redhat.com/show_bug.cgi?id=1688261>

So I'm not sure how we can reproduce the elfutils issue. 8-/

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill

  
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 353 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/elfutils-devel/attachments/20210207/c4cec33b/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testfile.cpp
Type: text/x-c++src
Size: 2923 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/elfutils-devel/attachments/20210207/c4cec33b/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrapecho.go
Type: text/x-go
Size: 535 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/elfutils-devel/attachments/20210207/c4cec33b/attachment-0001.bin>


More information about the Elfutils-devel mailing list