[PATCH] D102036: BPF: fix FIELD_EXISTS relocation with array subscripts

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 6 17:06:01 PDT 2021


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added a subscriber: hiraditya.
yonghong-song requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Lorenz Bauer reported an issue in bpf mailing list ([1]) where
for FIELD_EXISTS relocation, if the object is an array subscript,
the patched immediate is the object offset from the base address,
instead of 1.

Currently in BPF AbstractMemberAccess pass, the final offset
from the base address is the patched offset except FIELD_EXISTS
which is 1 unconditionally. In this particular case, the last
data structure access is not a field (struct/union offset)
so it didn't hit the place to set patched immediate to be 1.

This patch fixed the issue by checking the relocation type.
If the type is FIELD_EXISTS, just set to 1.
Tested by modifying some bpf selftests, libbpf is okay with
such types with FIELD_EXISTS relocation.

[1] https://lore.kernel.org/bpf/CACAyw99n-cMEtVst7aK-3BfHb99GMEChmRLCvhrjsRpHhPrtvA@mail.gmail.com/


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102036

Files:
  llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
  llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-existence-4.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102036.343538.patch
Type: text/x-patch
Size: 6287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210507/ef8b233d/attachment.bin>


More information about the llvm-commits mailing list