Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I get elf type using c api #644

Closed
lemon0910 opened this issue Apr 28, 2024 · 4 comments
Closed

how can I get elf type using c api #644

lemon0910 opened this issue Apr 28, 2024 · 4 comments

Comments

@lemon0910
Copy link

lemon0910 commented Apr 28, 2024

I can get elf type like:

readelf -h profile

ELF Header:

Type: DYN (Position-Independent Executable file)

It's very important to convert address to symbol.

but I read c api document https://docs.rs/blazesym-c/latest/blazesym_c/fn.blaze_inspect_syms_elf.html, I don't find api to get the type of elf files

@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Apr 28, 2024

Can you elaborate on your workflow, what you are trying to achieve, and why the ELF type would have relevance for that?

@lemon0910
Copy link
Author

I write a progarm like profile (https://github.com/libbpf/libbpf-bootstrap/blob/master/examples/c/profile.c).

I want to profile c++ program.

The c++ program split debuginfo from binary : objcopy --only-keep-debug my_program my_program.debug

so I need:
1, call bpf_get_stack to get stack function adress.
2, convert function address to symbol using debuginfo.

In pharse 2, different elf type like ET_DYN or ET_EXEC have different way to convert.

For ET_EXEC type, I can directly convert using blaze_symbolize_elf_virt_offsets

For ET_DYN type, I need call blaze_normalize_user_addrs before blaze_symbolize_elf_virt_offsets

@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Apr 29, 2024

different elf type like ET_DYN or ET_EXEC have different way to convert.

I don't believe that is true, the mechanism is the same for all types.

For ET_EXEC type, I can directly convert using blaze_symbolize_elf_virt_offsets

bpf_get_stack should report absolute addresses, so you'd need process symbolization, which also normalizes addresses, in both cases. Yes, blaze_symbolize_elf_virt_offsets may work in some cases, but it's still not right.

Split debug info support has not yet been implemented for blazesym (#60). That being said, the objcopy way you outline above is basically just producing "regular" DWARF from what I understand -- just not inside the executable file itself. So you should be able to symbolize it once #634 lands: set a custom process dispatch function and then return an ElfResolver working on my_program my_program.debug.

@danielocfb
Copy link
Collaborator

So you should be able to symbolize it once #634 lands: set a custom process dispatch function and then return an ElfResolver working on my_program my_program.debug.

That change has landed.

Direct debug link support is out as well: #665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants