Seperate debuginfo?

480 views
Skip to first unread message

ethan....@opendoor.com

unread,
Aug 12, 2020, 11:43:51 AM8/12/20
to golang-nuts
The C ecosystem allows one to generate a separate file containing debug info so that you can initially install a stripped library or binary and then only pull in the debug info as needed. I'm interested in doing the same for go, but I have not been able to find an equivalent to the -gsplit-dwarf compiler flag. I've tried using `objcopy --only-keep-debug` to generate a .debug file, but it didn't seem to take.

Has anyone else gone down this road? I would also be glad to hear that this is just known not to be possible at this point so that I can stop digging.

For a little context as to why I want to do this, we are using go on embedded devices and we would like to keep our payload size down for OTA updates so we would rather avoid shipping debug info that will only be used rarely.

Thanks!
Ethan

Ian Lance Taylor

unread,
Aug 12, 2020, 12:26:24 PM8/12/20
to ethan....@opendoor.com, golang-nuts
I would expect the objcopy approach to work.

go build x
objcopy --only-keep-debug x x.debug
objcopy --strip-debug --add-gnu-debuglink=x.debug x x.stripped

Where does that go wrong?

Ian

Ethan Pailes

unread,
Aug 12, 2020, 3:56:13 PM8/12/20
to golang-nuts
Wow, that works perfectly! Thank you so much!

The --add-gnu-debuglink=x.debug bit was what I was missing.

Unfortunately, it doesn't seem like delve supports separate debug info yet, so I'll have to stick with gdb in these situations.

Also, it seems that upx[1] breaks the debuglink, which doesn't seem entirely unreasonable (I'm mostly including this tidbit in case someone else in a similar situation to mine finds this post)

Ethan Pailes

unread,
Aug 13, 2020, 9:35:23 AM8/13/20
to golang-nuts
I've worked on this some more now, and it turns out that while directly executing the result of `upx -9` breaks,
you can use `upx --exact -9` to compress your exe and then `upx -d` to decompress it later. The decompressed
executable works with the .debug file.
Reply all
Reply to author
Forward
0 new messages