pkg/symbol: Position independent executable#2910
Conversation
PIE is used by default in gcc for security measures, i.e., address space layout randomization. This means that the executable segment is mapped to a random high memory address such as 0x5646e2188000 instead of the usual 0x401000 address (non PIE). See https://github.com/marselester/diy-parca-agent/tree/main/cmd/addr2func tool if you want to inspect an ELF file.
|
@kakkoyun thank you! |
kakkoyun
left a comment
There was a problem hiding this comment.
Thanks a lot for the contribution ❤️
As we talked offline. These changes need more consideration. We might evolve this into something else.
|
Thank you for taking time walking me through the related code in the Parca Agent! |
|
Here is a summary of address normalization. Please feel free to fill the gaps. Parca Agent stores CPU samples in pprof format and uploads them to Parca Server. The format itself allows to store function names, but Agent doesn't symbolize anything and delegates this responsibility to Server. Moreover, unlike pprof tools, Agent doesn't write "raw" sampled addresses into profiles, it normalizes them first. This decision was made to offload Server, so it wouldn't need to normalize an address on each Normalization allows one to look up a function name in a symbol table using an address // GetBase determines the base address to subtract from virtual
// address to get symbol table address. For an executable, the base
// is 0. Otherwise, it's a shared library, and the base is the
// address where the mapping starts. The kernel needs special handling.
base, _ := elfexec.GetBase(&ef.FileHeader, ph, f.m.kernelOffset, f.m.start, f.m.limit, f.m.offset)
normalizedAddress := addr - baseSee related Agent code:
Before uploading an object file (an executable or a shared library), it is stripped off of ELF sections that don't help Server with symbolization. For example, |
I am working on a DIY symbolizer and decided to share some of the results -- support of PIE. I've started with simple cases (see a blog post) such as resolving function names using only
.symtabsection, i.e., I haven't touched dynamic libraries yet.PIE (position independent executable) is used by default in gcc for security measures, i.e., address space layout randomization. This means that the executable segment is mapped to a random high memory address such as
0x5646e2188000instead of the usual0x401000address (non PIE).