This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] fix and simplify GetMaxVirtualAddress for ppc64*
ClosedPublic

Authored by willschm on Oct 30 2014, 3:37 PM.

Details

Summary

Use __builtin_frame_address(0) to calculate the memory layout for power. This works for both PPC64 endian-ness modes, so also eliminates the need for the BIG_ENDIAN/LITTLE_ENDIAN checks.

By trial and error, it also looks like the kPPC64_ShadowOffset64 value is (1ULL << 41) for both BE and LE, so that #if/#elif/#endif block has also been simplified.

Diff Detail

Repository
rL LLVM

Event Timeline

willschm updated this revision to Diff 15587.Oct 30 2014, 3:37 PM
willschm retitled this revision from to [compiler-rt] fix and simplify GetMaxVirtualAddress for ppc64*.
willschm updated this object.
willschm edited the test plan for this revision. (Show Details)
willschm added reviewers: kcc, samsonov, wschmidt.
willschm set the repository for this revision to rL LLVM.
willschm added subscribers: Unknown Object (MLST), willschm.
kcc edited edge metadata.Oct 31 2014, 2:23 PM

I wonder if you can add a powerpc-specific test for this.

lib/sanitizer_common/sanitizer_posix.cc
91 ↗(On Diff #15587)

I'd prefer if you don't use builtins in this file as it it is compiled by compilers that don't understand it.
Arguably, such compilers will never have powerpc64 defined, but for consistency still let's still not use builtin here.

There is GET_CURRENT_FRAME in sanitizer_common/sanitizer_internal_defs.h and
MostSignificantSetBitIndex/LeastSignificantSetBitIndex in sanitizer_common/sanitizer_common.h
You probably need MostSignificantSetBitIndex

willschm updated this revision to Diff 15729.Nov 3 2014, 1:41 PM
willschm edited edge metadata.

Reworked to use GET_CURRENT_FRAME and MostSignificantSetBitIndex helper functions per previous comments.

In D6044#5, @kcc wrote:

I wonder if you can add a powerpc-specific test for this.

Maybe. :-)
Is there an existing test that checks for something similar for other platforms? I'm not very familiar with the existing set of tests, so not sure what the options are, or what is practical.

kcc added a subscriber: samsonov.Nov 3 2014, 2:16 PM

I would add a test similar to test/asan/TestCases/debug_mapping.cc that will use ASAN_OPTIONS=verbosity=1
to check that the mapping is what's expected on the given system.

The test will need the REQUIRES: clause similar to the one below, but for powerpc
// REQUIRES: x86_64-supported-target
( I am not sure what exactly that should be. Alexey?)

lib/sanitizer_common/sanitizer_posix.cc
89 ↗(On Diff #15729)

space is missing between '-' and '1'.

foad added a subscriber: foad.Nov 3 2014, 2:43 PM

I can confirm that this works for me on big-endian PPC64 Fedora 19.

But the comments here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55975#c27 suggest that with "ulimit -s unlimited", the stack might not be right up near the 1<<44 or 1<<46 byte limit, so maybe it would be a bit safer to do something like:

if (GET_CURRENT_FRAME() < 1ULL << 44)
  return (1ULL << 44) - 1;
else
  return (1ULL << 46) - 1;

In practice, on my machine, this doesn't seem to be a problem. Even with "ulimit -s unlimited" the stack is still very close to 1<<46.

In D6044#11, @foad wrote:

I can confirm that this works for me on big-endian PPC64 Fedora 19.

But the comments here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55975#c27 suggest that with "ulimit -s unlimited", the stack might not be right up near the 1<<44 or 1<<46 byte limit, so maybe it would be a bit safer to do something like:

if (GET_CURRENT_FRAME() < 1ULL << 44)
  return (1ULL << 44) - 1;
else
  return (1ULL << 46) - 1;

In practice, on my machine, this doesn't seem to be a problem. Even with "ulimit -s unlimited" the stack is still very close to 1<<46.

Right. similar experiments here, on an assortment of systems has not shown that 'ulimit -s unlimited' affects the values coming out of the *frame_address(0) calls.

foad added a comment.Nov 5 2014, 8:56 AM

I can also confirm that the asan_mapping.h changes get things working for me on little-endian PPC64 Ubuntu 14.04.

I'm not a reviewer but it LGTM!

samsonov edited edge metadata.Nov 5 2014, 11:08 AM
In D6044#9, @kcc wrote:

I would add a test similar to test/asan/TestCases/debug_mapping.cc that will use ASAN_OPTIONS=verbosity=1
to check that the mapping is what's expected on the given system.

The test will need the REQUIRES: clause similar to the one below, but for powerpc
// REQUIRES: x86_64-supported-target
( I am not sure what exactly that should be. Alexey?)

Should be powerpc64-supported-target

willschm updated this revision to Diff 15834.Nov 5 2014, 2:56 PM
willschm edited edge metadata.

Add a testcase that covers validation of address mapping for both old and new kernels.
Also some cosmetic touch-ups per previous feedback.

kcc accepted this revision.Nov 5 2014, 3:39 PM
kcc edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 5 2014, 3:39 PM
foad added a comment.Nov 6 2014, 1:13 AM

Just one more inline comment.

lib/sanitizer_common/sanitizer_posix.cc
85–86 ↗(On Diff #15834)

comment should be tweaked or removed

willschm closed this revision.Nov 6 2014, 7:09 AM
willschm updated this revision to Diff 15869.

Closed by commit rL221457 (authored by @willschm).