Bug 1730030 - Replace some assembly with corresponding compiler builtins. r=gerald

This has the side-effect of adding the missing arm64 mac support for PHC.

Differential Revision: https://phabricator.services.mozilla.com/D125139
This commit is contained in:
Mike Hommey 2021-09-10 00:58:34 +00:00
parent 9632e084b7
commit 9c0f04e547
4 changed files with 26 additions and 52 deletions

View File

@ -651,15 +651,10 @@ static uint32_t gGCStackTraceTableWhenSizeExceeds = 4 * 1024;
// This code is cribbed from the Gecko Profiler, which also uses // This code is cribbed from the Gecko Profiler, which also uses
// FramePointerStackWalk() on Mac: Registers::SyncPopulate() for the frame // FramePointerStackWalk() on Mac: Registers::SyncPopulate() for the frame
// pointer, and GetStackTop() for the stack end. // pointer, and GetStackTop() for the stack end.
void** fp; # pragma GCC diagnostic push
# if defined(__x86_64__) # pragma GCC diagnostic ignored "-Wframe-address"
asm( void** fp = reinterpret_cast<void**>(__builtin_frame_address(1));
// Dereference %rbp to get previous %rbp # pragma GCC diagnostic pop
"movq (%%rbp), %0\n\t"
: "=r"(fp));
# else
asm("ldr %0, [x29]\n\t" : "=r"(fp));
# endif
void* stackEnd = pthread_get_stackaddr_np(pthread_self()); void* stackEnd = pthread_get_stackaddr_np(pthread_self());
FramePointerStackWalk(StackWalkCallback, MaxFrames, &tmp, fp, stackEnd); FramePointerStackWalk(StackWalkCallback, MaxFrames, &tmp, fp, stackEnd);
#else #else

View File

@ -224,11 +224,10 @@ void StackTrace::Fill() {
// This code is cribbed from the Gecko Profiler, which also uses // This code is cribbed from the Gecko Profiler, which also uses
// FramePointerStackWalk() on Mac: Registers::SyncPopulate() for the frame // FramePointerStackWalk() on Mac: Registers::SyncPopulate() for the frame
// pointer, and GetStackTop() for the stack end. // pointer, and GetStackTop() for the stack end.
void** fp; # pragma GCC diagnostic push
asm( # pragma GCC diagnostic ignored "-Wframe-address"
// Dereference %rbp to get previous %rbp void** fp = reinterpret_cast<void**>(__builtin_frame_address(1));
"movq (%%rbp), %0\n\t" # pragma GCC diagnostic pop
: "=r"(fp));
void* stackEnd = pthread_get_stackaddr_np(pthread_self()); void* stackEnd = pthread_get_stackaddr_np(pthread_self());
FramePointerStackWalk(StackWalkCallback, kMaxFrames, this, fp, stackEnd); FramePointerStackWalk(StackWalkCallback, kMaxFrames, this, fp, stackEnd);
#else #else

View File

@ -201,25 +201,15 @@ static void PlatformInit(PSLockRef aLock) {}
#if defined(HAVE_NATIVE_UNWIND) #if defined(HAVE_NATIVE_UNWIND)
void Registers::SyncPopulate() { void Registers::SyncPopulate() {
# if defined(__x86_64__) // Derive the stack pointer from the frame pointer. The 0x10 offset is
asm( // 8 bytes for the previous frame pointer and 8 bytes for the return
// Compute caller's %rsp by adding to %rbp: // address both stored on the stack after at the beginning of the current
// 8 bytes for previous %rbp, 8 bytes for return address // frame.
"leaq 0x10(%%rbp), %0\n\t" mSP = reinterpret_cast<Address>(__builtin_frame_address(0)) + 0x10;
// Dereference %rbp to get previous %rbp # pragma GCC diagnostic push
"movq (%%rbp), %1\n\t" # pragma GCC diagnostic ignored "-Wframe-address"
: "=r"(mSP), "=r"(mFP)); mFP = reinterpret_cast<Address>(__builtin_frame_address(1));
# elif defined(__aarch64__) # pragma GCC diagnostic pop
asm(
// Compute caller's sp by adding to fp:
// 8 bytes for previous fp, 8 bytes for return address
"add %0, x29, #0x10\n\t"
// Dereference fp to get previous fp
"ldr %1, [x29]\n\t"
: "=r"(mSP), "=r"(mFP));
# else
# error "unknown architecture"
# endif
mPC = reinterpret_cast<Address>( mPC = reinterpret_cast<Address>(
__builtin_extract_return_addr(__builtin_return_address(0))); __builtin_extract_return_addr(__builtin_return_address(0)));
mLR = 0; mLR = 0;

View File

@ -230,25 +230,15 @@ static void PlatformInit(PSLockRef aLock) {}
#if defined(HAVE_NATIVE_UNWIND) #if defined(HAVE_NATIVE_UNWIND)
void Registers::SyncPopulate() { void Registers::SyncPopulate() {
# if defined(__x86_64__) // Derive the stack pointer from the frame pointer. The 0x10 offset is
asm( // 8 bytes for the previous frame pointer and 8 bytes for the return
// Compute caller's %rsp by adding to %rbp: // address both stored on the stack after at the beginning of the current
// 8 bytes for previous %rbp, 8 bytes for return address // frame.
"leaq 0x10(%%rbp), %0\n\t" mSP = reinterpret_cast<Address>(__builtin_frame_address(0)) + 0x10;
// Dereference %rbp to get previous %rbp # pragma GCC diagnostic push
"movq (%%rbp), %1\n\t" # pragma GCC diagnostic ignored "-Wframe-address"
: "=r"(mSP), "=r"(mFP)); mFP = reinterpret_cast<Address>(__builtin_frame_address(1));
# elif defined(__aarch64__) # pragma GCC diagnostic pop
asm(
// Compute caller's sp by adding to fp:
// 8 bytes for previous fp, 8 bytes for return address
"add %0, x29, #0x10\n\t"
// Dereference fp to get previous fp
"ldr %1, [x29]\n\t"
: "=r"(mSP), "=r"(mFP));
# else
# error "unknown architecture"
# endif
mPC = reinterpret_cast<Address>( mPC = reinterpret_cast<Address>(
__builtin_extract_return_addr(__builtin_return_address(0))); __builtin_extract_return_addr(__builtin_return_address(0)));
mLR = 0; mLR = 0;