Reputation: 17234
I'm following this article to understand how eBPF tracing works, one of the first steps is to identify the symbol for the function, example code is picked up from here: https://github.com/pixie-labs/pixie-demos/blob/main/simple-gotracing/app/app.go
However, after doing the build, I'm unable to find the symbol. Why is that the case?
$ ls
go.mod main.go
$ grep func main.go
func computeE(iterations int64) float64 {
func main() {
http.HandleFunc("/e", func(w http.ResponseWriter, r *http.Request) {
$ go build
$ objdump --syms ./demowebservice | grep compute
0000000000840a40 g O .bss 0000000000000008 crypto/elliptic.p256Precomputed
00000000008704c0 g O .noptrbss 000000000000000c crypto/elliptic.precomputeOnce
$
Go version:-
$ go version
go version go1.16.5 linux/amd64
Upvotes: 2
Views: 454
Reputation: 417592
Your computeE()
function will be inlined and thus the function name will leave no "marks" in the executable binary. You can use go build -gcflags=-m
to see what functions are being inlined
in the build process.
$ go build -gcflags=-m |& grep inlining
./main.go:24:17: inlining call to http.HandleFunc
./main.go:24:17: inlining call to http.(*ServeMux).HandleFunc
./main.go:43:12: inlining call to fmt.Printf
./main.go:44:28: inlining call to http.ListenAndServe
./main.go:46:13: inlining call to fmt.Printf
./main.go:40:53: inlining call to computeE <-- NOTE THIS
If you disable inlining:
//go:noinline
func computeE(iterations int64) float64 {
// ...
}
And then build and check again:
$ go build -gcflags=-m |& grep inlining
./main.go:24:17: inlining call to http.HandleFunc
./main.go:24:17: inlining call to http.(*ServeMux).HandleFunc
./main.go:43:12: inlining call to fmt.Printf
./main.go:44:28: inlining call to http.ListenAndServe
./main.go:46:13: inlining call to fmt.Printf
$ objdump --syms ./demowebservice | grep compute
Then output will be something like this:
000000000062a940 g F .text 000000000000004c main.computeE
0000000000840a40 g O .bss 0000000000000008 crypto/elliptic.p256Precomputed
00000000008704c0 g O .noptrbss 000000000000000c crypto/elliptic.precomputeOnce
See related: forbid inlining in golang
Upvotes: 6