[PATCH] D88942: BPF: avoid duplicated globals for CORE relocations

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 21:25:27 PDT 2020


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

This patch fixed two issues related with relocation globals.
In LLVM, if a global, e.g. with name "g", is created and 
conflict with another global with the same name, LLVM will
rename the global, e.g., with a new name "g.2". Since
relocation global name has special meaning, we do not want
llvm to change it, so internally we have logic to check
whether duplication happens or not. If happens, just reuse
the previous global.

The first bug is related to non-btf-id relocation
(BPFAbstractMemberAccess.cpp). Commit 54d9f743c8b0 <https://reviews.llvm.org/rG54d9f743c8b0f501288119123cf1828bf7ade69c>
("BPF: move AbstractMemberAccess and PreserveDIType passes
to EP_EarlyAsPossible") changed ModulePass to FunctionPass,
i.e., handling each function at a time. But still just
one BPFAbstractMemberAccess object is created so module
level de-duplication still possible. Commit 40251fee0084 <https://reviews.llvm.org/rG40251fee00840b98d927c2c138e45e812bc3468b>
("[BPF][NewPM] Make BPFTargetMachine properly adjust NPM optimizer
pipeline") made a change to create a BPFAbstractMemberAccess
object per function so module level de-duplication is not 
possible any more without going through all module globals.
This patch restored the old behavior to create just one 
BPFAbstractMemberAccess object and fixed the issue.

NPM still has the issues. But since NPM is on by default yet,
it is okay for now. Will engage with NPM maintainer to find
a proper fix.

The second bug is related to btf-id relocation
(BPFPreserveDIType.cpp). Before Commit 54d9f743c8b0 <https://reviews.llvm.org/rG54d9f743c8b0f501288119123cf1828bf7ade69c>, the pass
is a ModulePass, so we have a local variable, incremented for 
each instance, and works fine. But after Commit 54d9f743c8b0 <https://reviews.llvm.org/rG54d9f743c8b0f501288119123cf1828bf7ade69c>,
the pass becomes a FunctionPass. Local variable won't work
properly since different functions will start with the same
initial value. Fix the issue by change the local count variable
as static, so it will be truely unique across the whole module
compilation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88942

Files:
  llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
  llvm/lib/Target/BPF/BPFPreserveDIType.cpp
  llvm/test/CodeGen/BPF/CORE/btf-id-duplicate.ll
  llvm/test/CodeGen/BPF/CORE/field-reloc-duplicate.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88942.296592.patch
Type: text/x-patch
Size: 13145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201007/d96c42c6/attachment.bin>


More information about the llvm-commits mailing list