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

fix: support bpf_core_type_exists() #655

Merged
merged 1 commit into from May 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/btf/core.go
Expand Up @@ -313,10 +313,16 @@ func coreCalculateFixups(byteOrder binary.ByteOrder, local Type, targets []Type,

if bestFixups == nil {
// Nothing at all matched, probably because there are no suitable
// targets at all. Poison everything!
// targets at all.
//
// Poison everything except checksForExistence.
bestFixups = make([]COREFixup, len(relos))
for i, relo := range relos {
bestFixups[i] = COREFixup{kind: relo.kind, poison: true}
if relo.kind.checksForExistence() {
bestFixups[i] = COREFixup{kind: relo.kind, local: 1, target: 0}
} else {
bestFixups[i] = COREFixup{kind: relo.kind, poison: true}
}
}
}

Expand Down
Binary file modified internal/btf/testdata/relocs_read-eb.elf
Binary file not shown.
Binary file modified internal/btf/testdata/relocs_read-el.elf
Binary file not shown.
15 changes: 15 additions & 0 deletions internal/btf/testdata/relocs_read.c
Expand Up @@ -26,6 +26,12 @@ struct bits {
u64 f : 16, g : 30;
};

struct nonexist {
int non_exist;
};

enum nonexist_enum { NON_EXIST = 1 };

// Perform a read from a subprog to ensure CO-RE relocations
// occurring there are tracked and executed in the final linked program.
__attribute__((noinline)) int read_subprog() {
Expand Down Expand Up @@ -89,6 +95,15 @@ __attribute__((noinline)) int read_subprog() {
if (BPF_CORE_READ_BITFIELD(&bar, g) != 0x15443322)
return __LINE__;

if (bpf_core_type_exists(struct nonexist) != 0)
return __LINE__;

if (bpf_core_field_exists(((struct nonexist *)0)->non_exist) != 0)
return __LINE__;

if (bpf_core_enum_value_exists(enum nonexist_enum, NON_EXIST) != 0)
return __LINE__;

return 0;
}

Expand Down