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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions elf_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,12 +1125,6 @@ func (ec *elfCode) loadDataSections() error {
continue
}

if sec.references == 0 {
// Prune data sections which are not referenced by any
// instructions.
continue
}

if sec.Size > math.MaxUint32 {
return fmt.Errorf("data section %s: contents exceed maximum size", sec.Name)
}
Expand Down
Binary file modified testdata/variables-eb.elf
Binary file not shown.
Binary file modified testdata/variables-el.elf
Binary file not shown.
5 changes: 0 additions & 5 deletions testdata/variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
// Should not appear in CollectionSpec.Variables.
__hidden volatile uint32_t hidden;

// Should also not appear in CollectionSpec.Variables. Put into its own section
// to avoid this ending up in .bss where references to other symbols in .bss
// would overlap, incorrectly preventing it from being culled by the loader.
volatile uint32_t unreferenced __section(".data.unref");

// Weak variables can be overridden by non-weak symbols when linking BPF
// programs using bpftool. Make sure they appear in CollectionSpec.Variables.
__weak volatile uint32_t weak __section(".data.weak");
Expand Down
1 change: 0 additions & 1 deletion variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestVariableSpec(t *testing.T) {
qt.Assert(t, qt.IsNil(err))

qt.Assert(t, qt.IsNil(spec.Variables["hidden"]))
qt.Assert(t, qt.IsNil(spec.Variables["unreferenced"]))
qt.Assert(t, qt.IsNotNil(spec.Variables["weak"]))

const want uint32 = 12345
Expand Down