elf: include data sections without references in CollectionSpec #1614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.