This is an archive of the discontinued LLVM Phabricator instance.

[profile][test] Fix Profile-* :: instrprof-merge.c etc. on SPARC
ClosedPublic

Authored by ro on Jul 10 2019, 7:45 AM.

Details

Reviewers
void
vsk
Summary

While working on https://reviews.llvm.org/D40900 (which effectively is about enabling compiler-rt on sparc these days), I came across two failing profile testcases:

Profile-sparc :: instrprof-merge-match.test
Profile-sparc :: instrprof-merge.c
Profile-sparcv9 :: instrprof-merge-match.test
Profile-sparcv9 :: instrprof-merge.c

All of them crashed with a SIGBUS in __llvm_profile_merge_from_buffer:

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1 (LWP 1)]
0x00012368 in __llvm_profile_merge_from_buffer (
    ProfileData=0x2384c <main.Buffer> "\377lprofR\201", ProfileSize=360)
    at /vol/llvm/src/llvm/local/projects/compiler-rt/lib/profile/InstrProfilingMerge.c:95
95        SrcDataEnd = SrcDataStart + Header->DataSize;

where Header is insufficiently aligned for a strict-alignment target like SPARC.

Fixed by forcing the alignment to uint64_t, the members of struct __llvm_profile_header,
in the callers.

Tested on sparcv9-sun-solaris2.11. Ok for trunk?

Diff Detail

Event Timeline

ro created this revision.Jul 10 2019, 7:45 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 10 2019, 7:45 AM
Herald added subscribers: Restricted Project, fedor.sergeev, jyknight. · View Herald Transcript
vsk added a subscriber: vsk.Jul 10 2019, 9:28 AM

This might need to be '__declspec(align(x))' for msvc. See sanitizer_internal_defs.h. Imho ideally the profile library would just share that file, or just use llvm/{ADT,Support}.

ro updated this revision to Diff 209138.Jul 11 2019, 12:51 AM
  • Introduce new profile_test.h header to share the ALIGNED definition, now handling MSVC, too.
  • Use it in affected tests.

Tested on sparcv9-sun-solaris2.11 and x86_64-pc-solaris2.11. I've no way of testing
on Windows, though.

vsk accepted this revision.Jul 11 2019, 11:03 AM

Thanks, lgtm.

This revision is now accepted and ready to land.Jul 11 2019, 11:03 AM
ro closed this revision.Jul 11 2019, 11:32 AM

Forgot to add Differential Revision: tag before URL, so closing manually.