Skip to content

Reading constants from an ELF #1567

Answered by ti-mo
thediveo asked this question in Q&A
Sep 11, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Reading constants is now possible with #1564 and will ship in 0.17. Manual is here: https://ebpf-go.dev/concepts/global-variables.

However, this strikes me as rather roundabout, esp. since we cull unreferenced symbols as you've mentioned. This cannot be worked around (aside from creating a reference..) and is still the case with the new CollectionSpec.Variables implementation.

For carrying e.g. some version info or other build-time info in an ELF, consider putting them in enums. Your MAX_ symbol in particular looks like it could be an enum in your actual code base. An ELF's enums are preserved in BTF, quick example in the repo's testdata:

λ  ebpf main ✓ bpftool btf dump file testdata/erro…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thediveo
Comment options

Answer selected by thediveo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1562 on September 24, 2024 12:49.