This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Enabling MIPS support for Scudo
ClosedPublic

Authored by slthakur on Apr 7 2017, 1:28 AM.

Details

Summary

Adding MIPS 32-bit and 64-bit support for Scudo.

Diff Detail

Repository
rL LLVM

Event Timeline

slthakur created this revision.Apr 7 2017, 1:28 AM
cryptoad edited edge metadata.Apr 7 2017, 7:37 PM

Thank you for this. I am curious, what did you test this on?
I have no experience on MIPS, would you be able to provide some help in case of any breakage?

Hi,

Thank you for this. I am curious, what did you test this on?
I have no experience on MIPS, would you be able to provide some help in case of any breakage?

I have tested this on a mips64 little endian machine. All tests are passing.
Yes, I will be happy to help if there is any breakage.

Regards,
Sagar

This revision is now accepted and ready to land.Apr 14 2017, 8:17 AM
slthakur closed this revision.Apr 23 2017, 9:43 PM

Committed in revision 301158.

sdardis edited edge metadata.Apr 24 2017, 2:18 AM

Sagar, rL301158 broke the buildbot clang-cmake-mips starting with http://lab.llvm.org:8011/builders/clang-cmake-mips/builds/3179 . Can you investigate?

slthakur reopened this revision.Apr 24 2017, 3:53 AM

Hi Simon,

I am investigating the failure. Meanwhile I'll revert the commit.

Regards,
Sagar

This revision is now accepted and ready to land.Apr 24 2017, 3:53 AM
slthakur updated this revision to Diff 100603.May 29 2017, 3:03 AM

Added 64-bit atomic functions for mips32 which are required in sanitizer common.

We needed to add these function because we were getting undefined references to sync_fetch_and_add_8, sync_val_compare_and_swap_8 functions.

Still LGTM for the Scudo side of things, but not being familiar with MIPS and the platform in general, I don't think I can provide appropriate feedback on the atomic modifications done in sanitizer_common.
If someone else could have a look at it, that would be great.

sdardis requested changes to this revision.May 31 2017, 5:23 AM

This appears functionally correct, but really requires documentation explaining the implementation.

My other concern is that having a single global lock for all atomic functions may be something of a bottleneck in terms of performance. The lock could be duplicated on a per template basis to avoid unnecessary contention but I'd really prefer if we could simply use template specialisation to handle 64bit types.

lib/sanitizer_common/sanitizer_atomic_clang_other.h
20

This preprocessor define check I believe to too broad.

Instead it should be:

#if defined(_MIPS_SIM) && _MIPS_SIM == _ABIO32

As it's O32 that cannot use 64 bit atomics.

29–32

This structure definition is strange.

I am guessing that you're allocating a typical MIPS sized cache into the data section, with a lock and padding, the purpose of the padding to avoid spurious ll/sc failures due to writes near the lock.

I understand that you're using a single global lock for __mips_sync_* , so that you can update types larger than a word on MIPS32 platforms, as they do not have larger than word sized atomic updates.

This hunk really needs a (long) comment to explain the reasoning and implementation.

This revision now requires changes to proceed.May 31 2017, 5:23 AM
slthakur updated this revision to Diff 102170.Jun 12 2017, 3:41 AM
slthakur edited edge metadata.

Addressed review comments

slthakur updated this revision to Diff 102180.Jun 12 2017, 7:08 AM

Using preprocessor macro _MIPS_SIM in sanitizer_atomic_clang.h as well.

sdardis accepted this revision.Jun 16 2017, 4:53 AM

LGTM with inline comments addressed.

Please add comments for the bug addition to lib/sanitizer_common/sanitizer_atomic_clang_other.h, other maintainers will not necessarily know why MIPS requires an internal spinlock for 8 byte atomics.

lib/sanitizer_common/sanitizer_atomic_clang.h
84

The casts of (u64) for cmpv and xchg should be reinterpret_cast<u64> rather than C-style casts. C style casts trigger conversions whereas we want to reinterpret the bit pattern.

lib/sanitizer_common/sanitizer_atomic_clang_other.h
20

Prefix this hunk with a comment saying that MIPS32 or code compiled for the O32 ABI on MIPS does not support atomics > 4 bytes. To address this lack of functionality, the sanitizer library provides helper methods which use an internal spin lock mechanism to emulate atomic operations when the size is 8 bytes.

148

reinterpret_cast<u64> rather than (u64).

This revision is now accepted and ready to land.Jun 16 2017, 4:53 AM
slthakur updated this revision to Diff 103011.Jun 19 2017, 4:24 AM
slthakur marked 3 inline comments as done.

Addressed review comments.

slthakur closed this revision.Jun 22 2017, 4:54 AM

Committed in revision 305682.
Thanks to Simon for the review and for fixing the build breakage.