Issue 234720
Summary [BPF] CO-RE matches a derived field to a same-named base field
Labels new issue
Assignees
Reporter maxskokov
    With #233715, a non-virtual base becomes an anonymous member in BTF, as pahole does for DWARF. libbpf matches CO-RE fields by name and searches anonymous members in order (`bpf_core_match_member()`), so a derived field that hides a base field of the same name resolves to the base field, silently:

```cpp
struct Base { int x; };
struct Derived : Base { int x; };
extern "C" __attribute__((section("socket")))
int f(Derived *p) {
  return __builtin_preserve_field_info(p->x, 0);
}
```

```
$ clang -target bpf -O2 -g -c t.cpp -o t.o
$ bpftool -d gen min_core_btf t.o min.btf t.o
relo #0: <byte_off> [2] struct Derived.x (0:1 @ offset 4)
relo #0: matching candidate #0 <byte_off> [2] struct Derived.x (0:0:0 @ offset 0)
```

This happens even against the program's own BTF (bpftool v7.9.0, libbpf v1.9). C doesn't allow such duplicate names, so libbpf doesn't check for them. Clang could diagnose CO-RE accesses to a field whose name also appears in a base.

Found in review of #233715.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to