This is an archive of the discontinued LLVM Phabricator instance.

[memprof] Record BuildIDs in the raw profile.
ClosedPublic

Authored by snehasish on Mar 2 2023, 2:06 PM.

Details

Summary

This patch adds support for recording BuildIds usng the sanitizer
ListOfModules API. We add another entry to the SegmentEntry struct and
change the memprof raw version.

Diff Detail

Event Timeline

snehasish created this revision.Mar 2 2023, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2023, 2:06 PM
snehasish requested review of this revision.Mar 2 2023, 2:06 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 2 2023, 2:06 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
snehasish updated this revision to Diff 501981.Mar 2 2023, 2:08 PM

Remove commented code.

tejohnson added inline comments.Mar 3 2023, 5:46 PM
compiler-rt/include/profile/MemProfData.inc
58–59

Do we need to record the size or can we just pad with zeros if less than the max? Is it ever not 32 in practice? Looks like it is defined to 32 in sanitizer_common.h.

Looking into the regenerating the profiles for the PGOProfile tests.

compiler-rt/include/profile/MemProfData.inc
58–59

I think we need it. In practice, we usually have 16 or 20 byte buildids [1] but they could be of arbitrary length if it's provided by the user rather than generated by the linker. Also the build id is a raw sequence of bytes. Padding with zeros is not enough to distinguish the length if the build id itself contains leading/trailing zero bytes.

[1] https://github.com/llvm/llvm-project/blob/8a5d4eb775c644d8683f24817d44c510d2b853b7/lld/ELF/Writer.cpp#L2938-L2975

tejohnson added inline comments.Mar 6 2023, 12:43 PM
compiler-rt/include/profile/MemProfData.inc
58–59

Ok got it. I thought sanitizer_common.h always used 32, but I now see another interface where it can be variable (but max of 32, which matches the handling here).

tejohnson accepted this revision.Mar 9 2023, 7:56 AM

lgtm - but does this depend on D145644 and require some additional test changes?

This revision is now accepted and ready to land.Mar 9 2023, 7:56 AM

lgtm - but does this depend on D145644 and require some additional test changes?

Yes, I will rebase this patch once that is submitted. I need to look at the LLVM.Transforms/PGOProfile::memprof.ll test failures.

snehasish updated this revision to Diff 503938.Mar 9 2023, 2:27 PM

Update raw profiles, add another test for buildids only.

Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 2:27 PM

lgtm - but does this depend on D145644 and require some additional test changes?

Yes, I will rebase this patch once that is submitted. I need to look at the LLVM.Transforms/PGOProfile::memprof.ll test failures.

@tejohnson I've rebased the patch and updated the raw profiles for all the tests with the new version. Also added a new test for llvm-profdata to check the buildid we serialize in the raw profile. No changes to the code from prior diffs. PTAL, thanks!

snehasish updated this revision to Diff 503945.Mar 9 2023, 3:00 PM

Update test regex.

This revision was automatically updated to reflect the committed changes.
snehasish reopened this revision.Mar 13 2023, 4:26 PM

Reopening since I missed the updates to the memprof unit tests in compiler-rt. This was caught by the buildbots. As part of the changes I modified the SerializeToRawProfile API slightly to make it easier to test. Also regenerated the raw profiles and binaries again since the runtime changed.

@tejohnson PTAL, thanks!

This revision is now accepted and ready to land.Mar 13 2023, 4:26 PM
snehasish updated this revision to Diff 504887.Mar 13 2023, 4:26 PM

Update the unittest in compiler-rt which was caught by the build bot failures.

This revision was automatically updated to reflect the committed changes.