猿问

“去构建”后二进制中没有符号

我正在阅读本文以了解eBPF跟踪的工作原理,第一步是识别函数的符号,示例代码从这里获取:https://github.com/pixie-labs/pixie-demos/blob/main/simple-gotracing/app/app.go


但是,在完成构建后,我无法找到该符号。为什么会这样呢?


$ 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 go1.16.5 linux/amd64


牧羊人nacy
浏览 108回答 1
1回答

慕容3067478

您的函数将被内联,因此函数名称不会在可执行二进制文件中留下任何“标记”。您可以使用 来查看生成过程中有哪些函数。computeE()go build -gcflags=-minlined$ 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&nbsp; &nbsp; &nbsp; <-- NOTE THIS如果禁用内联://go:noinlinefunc computeE(iterations int64) float64 {&nbsp; &nbsp; // ...}然后构建并再次检查:$ 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然后输出将如下所示:000000000062a940 g&nbsp; &nbsp; &nbsp;F .text&nbsp; 000000000000004c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; main.computeE0000000000840a40 g&nbsp; &nbsp; &nbsp;O .bss&nbsp; &nbsp;0000000000000008&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crypto/elliptic.p256Precomputed00000000008704c0 g&nbsp; &nbsp; &nbsp;O .noptrbss&nbsp; &nbsp; &nbsp; 000000000000000c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crypto/elliptic.precomputeOnce
随时随地看视频慕课网APP

相关分类

Go
我要回答