This is an archive of the discontinued LLVM Phabricator instance.

[InstrProfiling] Emit the runtime hook when no counters are lowered
ClosedPublic

Authored by vsk on Feb 26 2018, 4:10 PM.

Details

Summary

The API verification tool tapi has difficulty processing frameworks
which enable code coverage, but which have no code. The profile lowering
pass does not emit its usual set of symbols in this case because no
counters are lowered.

While the symbols are not needed for program correctness, they are
needed to allow tapi to validate the exported symbol set of instrumented
binaries.

It was not possible to add a workaround in tapi for empty binaries due
to an architectural issue: tapi generates its expected symbol set before
it inspects a binary. Changing that model has a higher cost than simply
forcing llvm to emit the usual set of profiling-related symbols even
when there no counters are present.

rdar://36076904

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.Feb 26 2018, 4:10 PM

Can this be done under an option?

More fundamentally, do you just need to create a reference to the runtime hook variable? Is it possible to just unconditionally emit that while keep others unchanged? Or even better, is it possible to do the same linker trick as on linux -- to force undef of the variable on the command line?

vsk added a comment.Feb 27 2018, 11:35 AM

Can this be done under an option?

The change doesn't affect many programs, so istm that it's simpler to make it unconditional.

More fundamentally, do you just need to create a reference to the runtime hook variable? Is it possible to just unconditionally emit that while keep others unchanged?

Currently all we need is a reference to the runtime hook. I can reduce the scope of this patch down to just this part, and then add a test that the exported symbol set for an empty program looks good.

Or even better, is it possible to do the same linker trick as on linux -- to force undef of the variable on the command line?

It's possible with an option like -force_load, but this is guaranteed to break Darwin programs which intentionally circumvent the RegisterRuntime static initializer.

vsk updated this revision to Diff 136196.Feb 27 2018, 4:54 PM
  • Simplify the patch per David's feedback.
  • Add an end-to-end test: D43844
davidxl accepted this revision.Feb 28 2018, 8:32 AM

lgtm

This revision is now accepted and ready to land.Feb 28 2018, 8:32 AM
This revision was automatically updated to reflect the committed changes.