Page MenuHomePhabricator

BPF: avoid duplicated globals for CORE relocations
ClosedPublic

Authored by yonghong-song on Oct 6 2020, 9:25 PM.

Details

Summary

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
("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
("[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 simply changed the map which holds reloc globals
as class static, so it will be available to all
BPFAbstractMemberAccess objects for different functions.

The second bug is related to btf-id relocation
(BPFPreserveDIType.cpp). Before Commit 54d9f743c8b0, the pass
is a ModulePass, so we have a local variable, incremented for
each instance, and works fine. But after Commit 54d9f743c8b0,
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.

Diff Detail

Event Timeline

yonghong-song created this revision.Oct 6 2020, 9:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2020, 9:25 PM
yonghong-song requested review of this revision.Oct 6 2020, 9:25 PM
ast accepted this revision.Oct 6 2020, 10:17 PM
This revision is now accepted and ready to land.Oct 6 2020, 10:17 PM
yonghong-song edited the summary of this revision. (Show Details)
  • got an even simpler fix. Just change the map to hold reloc globals GEPGlobals to be class static, so it will be available for all instances of BPFAbstractMemberAccess. this also resolved the issue for NPM nicely.
ast accepted this revision.Oct 6 2020, 10:33 PM
This revision was landed with ongoing or failed builds.Oct 6 2020, 10:42 PM
This revision was automatically updated to reflect the committed changes.