This is an archive of the discontinued LLVM Phabricator instance.

[InstrProf][compiler-rt] Fix counter section alignment issue
ClosedPublic

Authored by ellis on Jun 8 2023, 3:35 PM.

Details

Summary

I recently discovered that .profraw headers are expected to be 8 byte
aligned.
https://github.com/llvm/llvm-project/blob/643ba926c1f618401c86dc37e659df795db2e1a0/llvm/lib/ProfileData/InstrProfReader.cpp#L503-L506

When function entry coverage mode is used, function counters are single
bytes, so it is likely that the size of the counters section is not 8
byte aligned. We can add padding after the counters section to guarantee
this.

Diff Detail

Event Timeline

ellis created this revision.Jun 8 2023, 3:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 3:35 PM
Herald added subscribers: Enna1, dberris. · View Herald Transcript
ellis published this revision for review.Jun 8 2023, 3:37 PM
ellis added reviewers: kyulee, wenlei, gulfem.
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 3:37 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
kyulee added a comment.Jun 8 2023, 3:45 PM

LGTM

compiler-rt/test/profile/instrprof-entry-coverage.c
6 ↗(On Diff #529752)

Can you add a quick comment on what you're testing here?

kyulee accepted this revision.Jun 8 2023, 3:46 PM
This revision is now accepted and ready to land.Jun 8 2023, 3:46 PM
gulfem accepted this revision.Jun 8 2023, 4:32 PM
gulfem added inline comments.
compiler-rt/test/profile/instrprof-entry-coverage.c
6 ↗(On Diff #529752)

I literally ran into this padding issue yesterday while I was experimenting with single byte counters for coverage. Thanks for fixing this! Instead of concatenating two raw profiles in a test to test counter section alignment, I would suggest writing a shared library test similar to https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/profile/Posix/instrprof-shared.test, where profiles are concatenated under the hood. Other than that, it looks good to me.

ellis updated this revision to Diff 529786.Jun 8 2023, 5:05 PM

Add shared library test

ellis added inline comments.Jun 8 2023, 5:07 PM
compiler-rt/test/profile/instrprof-entry-coverage.c
6 ↗(On Diff #529752)

Thanks for the suggestion! I like this new test much better. Feel free to reach out if you find any other issues with single byte counters :)

gulfem added inline comments.Jun 8 2023, 5:21 PM
compiler-rt/test/profile/instrprof-entry-coverage.c
6 ↗(On Diff #529752)

Sounds good!

This revision was automatically updated to reflect the committed changes.