Kaydet (Commit) 9ec4c4ab authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Don't rely on __builtin_alloca when creating a call stack

same as 3f7c8ce1 for gcc_linux_x86-64 (see there
for a more detailed commit message; plus trivial follow-up
5e048869 "Remove spurious vertical whitespace").
Except use labels 'Lpush', 'Lpushed' not starting with a dot ('.Lpush',
'.Lpushed'), as otherwise at least macOS 10.12.1 linker (ld64-274.1), when
building libgcc3_uno.dylib's __TEXT,__unwind_info section, would use
callvirtualmethod.o's __LD,__compact_unwind entry---covering the complete
callVirtualMethod function---only for the first part of the function up to the
.Lpush label, and would mark the remainder as having no unwind information (a
compact_unwind_encoding_t value of 0; see the inline comments in the
libunwind-35.3 source code,
<http://opensource.apple.com/source/libunwind/libunwind-35.3/>).  So if an
exception shall pass through that latter part it would lead to std::terminate.

Change-Id: Ib1e8a5e4534b11ebe96c3ce774f8e5e8d45476cf
üst c01e0242
......@@ -54,6 +54,8 @@ void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
// than available" error:
struct Data {
sal_uInt64 pMethod;
sal_uInt64 * pStack;
sal_uInt32 nStack;
sal_uInt64 * pGPR;
double * pFPR;
// Return values:
......@@ -62,6 +64,8 @@ void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
double xmm0;
double xmm1;
} data;
data.pStack = pStack;
data.nStack = nStack;
data.pGPR = pGPR;
data.pFPR = pFPR;
......@@ -70,19 +74,25 @@ void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
pMethod += 8 * nVtableIndex;
data.pMethod = *reinterpret_cast<sal_uInt64 *>(pMethod);
// Load parameters to stack, if necessary
if ( nStack )
{
// 16-bytes aligned
sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 16;
sal_uInt64 *pCallStack = static_cast<sal_uInt64 *>(__builtin_alloca( nStackBytes ));
std::memcpy( pCallStack, pStack, nStackBytes );
}
asm volatile (
// Push arguments to stack
"movq %%rsp, %%r12\n\t"
"movl 16%0, %%ecx\n\t"
"jrcxz Lpushed\n\t"
"xor %%rax, %%rax\n\t"
"leaq (%%rax, %%rcx, 8), %%rax\n\t"
"subq %%rax, %%rsp\n\t"
"andq $-9, %%rsp\n\t" // 16-bytes aligned
"movq 8%0, %%rsi\n\t"
"\nLpush:\n\t"
"decq %%rcx\n\t"
"movq (%%rsi, %%rcx, 8), %%rax\n\t"
"movq %%rax, (%%rsp, %%rcx, 8)\n\t"
"jnz Lpush\n\t"
"\nLpushed:\n\t"
// Fill the xmm registers
"movq 16%0, %%rax\n\t"
"movq 32%0, %%rax\n\t"
"movsd (%%rax), %%xmm0\n\t"
"movsd 8(%%rax), %%xmm1\n\t"
......@@ -94,7 +104,7 @@ void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
"movsd 56(%%rax), %%xmm7\n\t"
// Fill the general purpose registers
"movq 8%0, %%rax\n\t"
"movq 24%0, %%rax\n\t"
"movq (%%rax), %%rdi\n\t"
"movq 8(%%rax), %%rsi\n\t"
......@@ -108,12 +118,15 @@ void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
"call *%%r11\n\t"
// Fill the return values
"movq %%rax, 24%0\n\t"
"movq %%rdx, 32%0\n\t"
"movsd %%xmm0, 40%0\n\t"
"movsd %%xmm1, 48%0\n\t"
"movq %%rax, 40%0\n\t"
"movq %%rdx, 48%0\n\t"
"movsd %%xmm0, 56%0\n\t"
"movsd %%xmm1, 64%0\n\t"
// Reset %rsp
"movq %%r12, %%rsp\n\t"
:: "o" (data)
: "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r10", "r11",
: "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r10", "r11", "r12",
"xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
"memory"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment