Skip to content

Commit

Permalink
btf: Make test for ld64imm CO-RE relocations
Browse files Browse the repository at this point in the history
Added a test which makes sure we do not mess up offsets when replacing
a ld64imm with poisoned instructions.

Signed-off-by: Dylan Reimerink <[email protected]>
  • Loading branch information
dylandreimerink committed Feb 21, 2024
1 parent 933e7a3 commit e43a484
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ TARGETS := \
btf/testdata/relocs \
btf/testdata/relocs_read \
btf/testdata/relocs_read_tgt \
btf/testdata/relocs_enum \
cmd/bpf2go/testdata/minimal

.PHONY: all clean container-all container-shell generate
Expand Down
13 changes: 13 additions & 0 deletions btf/core_reloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,16 @@ func TestCORERelocationRead(t *testing.T) {
}
})
}

func TestLD64IMMReloc(t *testing.T) {
spec, err := ebpf.LoadCollectionSpec("testdata/relocs_enum-el.elf")
if err != nil {
t.Fatal(err)
}

coll, err := ebpf.NewCollection(spec)
if err != nil {
t.Fatal(err)
}
defer coll.Close()
}
Binary file added btf/testdata/relocs_enum-eb.elf
Binary file not shown.
Binary file added btf/testdata/relocs_enum-el.elf
Binary file not shown.
16 changes: 16 additions & 0 deletions btf/testdata/relocs_enum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "bpf_core_read.h"

enum cgroup_subsys_id {
cpuset_cgrp_id,
cpuset_cgrp_id_lublub,
CGROUP_SUBSYS_COUNT,
};

#define __section(NAME) __attribute__((section(NAME), used))

__section("socket/core_ld64imm") int core_ld64imm() {
if (bpf_core_enum_value_exists(enum cgroup_subsys_id, cpuset_cgrp_id_lublub)) {
__attribute__((unused)) const volatile int val = bpf_core_enum_value(enum cgroup_subsys_id, cpuset_cgrp_id_lublub);
}
return 0;
}

0 comments on commit e43a484

Please sign in to comment.