Closed amoghumesh closed 4 months ago
The root cause here is the Go special ELF runtime
For example, the following code
package main
import (
"fmt"
"time"
)
func printCurrentTime() {
currentTime := time.Now()
fmt.Println("Current Time: ", currentTime)
}
func main() {
for {
printCurrentTime()
time.Sleep(1 * time.Second)
}
}
Compile it and we can use the readelf
to get the entrypoint
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x4644c0
And we can the code on 0x4644c0
00000000004644c0 <_rt0_amd64_linux>:
4644c0: e9 fb c8 ff ff jmp 460dc0 <_rt0_amd64>
The bootup chain is _rt0_amd64_linux->_rt0_amd64->runtime.rt0_go.abi0->runtime.mstart.abi0->main.main
.
In the agent, the __libc_start_main
method we hooked has not existed. So the probe is not working here https://github.com/eunomia-bpf/bpftime/blob/master/runtime/agent/agent.cpp#L61
We only support dynamically linked go programs, please use cgo. We don't support statically linked go programs
Bug Description I'm not able to use bpftime to load uprobes onto a go binary. Here is my go program. I'm trying to attach to the time.now function in the go runtime. main.go:
Here is my
example/minimal/uprobe.bpf.c
that I modified for this purpose:bptime start
does not print the info logs sayingAttach successfully
Expected behavior
bptime start
prints the info logs sayingAttach successfully
andtime.now called
is printed on each iteration in main.goScreenshots
Using Kernel uprobes
![2024-02-21_11-45_1](https://github.com/eunomia-bpf/bpftime/assets/73810056/ca5dcbc5-d856-4ae5-80ae-13b7a58f89b8)
Using bpftime
![2024-02-21_11-44_1](https://github.com/eunomia-bpf/bpftime/assets/73810056/7a1a4b14-b19f-44eb-96d8-0bad193b5680)
OS information