This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Eliminate the runtime dependency on libc++abi
ClosedPublic

Authored by phosek on Jan 15 2017, 6:16 PM.

Details

Summary

Making the CPU features variable non-static avoids the need for locking to ensure that the initialization is thread-safe which in turns eliminates the runtime dependency on libc++abi library (for cxa_guard_acquire and cxa_guard_release) which makes it possible to link scudo against pure C programs.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek updated this revision to Diff 84515.Jan 15 2017, 6:16 PM
phosek retitled this revision from to [scudo] Eliminate the runtime dependency on libc++abi.
phosek updated this object.
phosek added reviewers: cryptoad, kcc.
phosek set the repository for this revision to rL LLVM.
phosek added a subscriber: llvm-commits.
EricWF edited edge metadata.Jan 17 2017, 2:07 AM

Herald added me as a reviewer because libc++ was in the title, but this looks OK to me.

If you want to continue stashing the results of getCPUFeatures() without requiring runtime guards I imagine something like this would work (At least in optimized builds):

bool testCPUFeatures(CPUFeature Feat) {
  static CPUIDRegs FeaturesRegs = {}; // shouldn't generate a guard.
  static bool RegsInit = false; // also shouldn't generate a guard.
  if (!RegsInit) {
    FeatureRegs = getCPUFeatures();; // Not thread safe but initialization doesn't depend on libc++abi.
  }
  // ...
}
cryptoad accepted this revision.Jan 17 2017, 8:37 AM

Since testCPUFeature is only used once, I'm be OK with the initial way.
Initially it was used multiple times hence it being stored statically, but it's no longer the case.
@phosek you probably want to check D28574 as well.

This revision is now accepted and ready to land.Jan 17 2017, 8:37 AM
This revision was automatically updated to reflect the committed changes.