How to confirm a function is NOT compiled into a go binary

68 views
Skip to first unread message

worths...@gmail.com

unread,
Jun 8, 2019, 2:38:21 PM6/8/19
to golang-nuts
I'm looking for some type of tool or method to examine a compiled go binary and confirm that a list of functions is NOT included in the compiled binary.

example:
package internal

func A() string {
  return "func A"
}

func B() string {
  return "func B"
}

func C() string {
  return "func C"
}

package main

import "fmt"
import "internal"

func main() {
    fmt.Println(internal.A())
}

If the above were a compiled binary, I would like to use a tool or method to confirm that B() and C() is NOT included in the compiled binary.

Thanks...

Andrew Klager

unread,
Jun 8, 2019, 2:49:10 PM6/8/19
to worths...@gmail.com, golang-nuts
--
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/20430673-7bf2-47bc-afed-cd99d88a716f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Engels

unread,
Jun 8, 2019, 4:56:47 PM6/8/19
to Andrew Klager, worths...@gmail.com, golang-nuts
Since Go effectively requires source code for compilation, I think what you’re asking for is impossible as the dev can just copy the source under a different function name, including most stdlib code. 

Wagner Riffel

unread,
Jun 8, 2019, 6:57:29 PM6/8/19
to worths...@gmail.com, golang-nuts
This is totally possible, you can either use 'go tool nm' as suggest,
or 'go tool objdump', both tools can answer this question.
go tool objdump -s 'pkgname/internal' a.out
go tool nm a.out | grep 'pkgname/internal'
Be aware that testing against the shown examples, neither A() will be
present, by default go compiler will do inlining, you might want to
use //go:noinline directive.

BR.
Reply all
Reply to author
Forward
0 new messages