On Wednesday, March 13, 2024 at 4:37:31 PM UTC-4 Ian Lance Taylor wrote:
On Wed, Mar 13, 2024 at 8:04 AM 'Grant Seltzer Richman' via golang-nuts <golan...@googlegroups.com> wrote: > > I've been using the `Table.PCToLine` method to resolve program counters (extracted via bpf) into functions with their file names and line numbers. > > It appears that this breaks when i'm testing it on a binary that has cgo enabled. It does not fix it by compiling the binary statically. > > Another issue I have with this API is that creating the Table requires passing the `.gosymtab` which of course is empty. Cgo binaries don't even have it so I just pass an empty slice. > > Does anyone have alternatives to this package or possible explanations to why these issues exist? When using cgo the final executable is generated by the C linker. If that process uses -fpie, as is the default on some systems, PCToLine may not work. Yea that makes sense, my theory is that the C linker is adding symbols to the text section before runtime.text as theorized here: https://github.com/golang/go/issues/65232#issuecomment-1908498616 Have you tried using runtime.FuncForPC? I can't do so because i'm running the analysis from a separate process. The bpf program is attached to the traced process and that collects the program counters to send to the analysis process. The analysis process has the binary open of the traced process. I've decided to use DWARF instead which is working well and is even convenient for resolving inlined functions. Ian -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/634e80f7-cd15-45cf-9b3b-226888b9d6aan%40googlegroups.com.