summaryrefslogtreecommitdiff
path: root/bridges
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-11-04 23:06:45 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-11-07 08:54:58 +0100
commit9ec4c4ab052c66e9e25c9893bba33b8dee258484 (patch)
tree9b3a8fb20e5dbb47c0017454b9b5ab4b096ee1a4 /bridges
parentc01e02425e3ce7a14f06cfc505cf375a82a7c980 (diff)
Don't rely on __builtin_alloca when creating a call stack
same as 3f7c8ce1dca7eacb511def7799691be2e3d9a4a6 for gcc_linux_x86-64 (see there for a more detailed commit message; plus trivial follow-up 5e04886917abad0541eb3ef6d51cd5dc0395af21 "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
Diffstat (limited to 'bridges')
-rw-r--r--bridges/source/cpp_uno/gcc3_macosx_x86-64/callvirtualmethod.cxx45
1 files changed, 29 insertions, 16 deletions
diff --git a/bridges/source/cpp_uno/gcc3_macosx_x86-64/callvirtualmethod.cxx b/bridges/source/cpp_uno/gcc3_macosx_x86-64/callvirtualmethod.cxx
index d4d51600faad..47f383a6e885 100644
--- a/bridges/source/cpp_uno/gcc3_macosx_x86-64/callvirtualmethod.cxx
+++ b/bridges/source/cpp_uno/gcc3_macosx_x86-64/callvirtualmethod.cxx
@@ -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"