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

elf: include data sections without references in CollectionSpec #1614

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Nov 18, 2024

Before VariableSpec, this was a nice optimization since no symbol references means no ProgramSpec could ever refer to the map, effectively making it dead code. There was a clear benefit to skipping it, although in practice having a datasec without references should be quite rare.

With VariableSpec in the picture, the contents of a data section now affect things like code generation through bpf2go. If an object contains variable declarations like global volatile const and all of its references are compiled out using compile-time flags, it won't show up in CollectionSpec.Variables if its data section was skipped due to having no references.

While migrating the Cilium agent to using VariableSpec, I noticed some permutations of build flags caused all references to a particular datasec to drop, omitting it from spec.Variables. This patch removes the datasec pruning, making the contents of spec.Variables more deterministic in the face of changing build-time environments.

For users of NewCollection(), this can create and populate a .rodata map unnecessarily, but if it's not referred to by any programs and the Collection is closed, the map will be freed.

For users of LoadAndAssign(), the loading behaviour doesn't change since the map won't be pulled in for lazy-loading if there aren't any program references.

Before VariableSpec, this was a nice optimization since no symbol references
means no ProgramSpec could ever refer to the map, effectively making it dead
code. There was a clear benefit to skipping it, although in practice having
a datasec without references should be quite rare.

With VariableSpec in the picture, the contents of a data section now affect
things like code generation through bpf2go. If an object contains variable
declarations like global `volatile const` and all of its references are
compiled out using compile-time flags, it won't show up in CollectionSpec.Variables
if its data section was skipped due to having no references.

While migrating the Cilium agent to using VariableSpec, I noticed some
permutations of build flags caused all references to a particular datasec to
drop, omitting it from spec.Variables. This patch removes the datasec pruning,
making the contents of spec.Variables more deterministic in the face of changing
build-time environments.

For users of NewCollection(), this can create and populate a .rodata map
unnecessarily, but if it's not referred to by any programs and the Collection
is closed, the map will be freed.

For users of LoadAndAssign(), the loading behaviour doesn't change since the
map won't be pulled in for lazy-loading if there aren't any program references.

Signed-off-by: Timo Beckers <[email protected]>
@ti-mo ti-mo requested a review from a team as a code owner November 18, 2024 21:02
@ti-mo ti-mo merged commit 82c5aca into cilium:main Nov 18, 2024
17 checks passed
@ti-mo ti-mo deleted the tb/no-skip-datasec branch November 18, 2024 21:07
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

Successfully merging this pull request may close these issues.

1 participant