This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch AOO50X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit e80ff03fbc551a374aa57f235984dcd1aedaed3a
Author: Pedro Giffuni <[email protected]>
AuthorDate: Wed Oct 21 12:18:11 2026 -0500

    freebsd_aarch64: Fix stack alignment and return handling
    
    Fix two issues in the FreeBSD aarch64 C++-UNO bridge:
    
    1. abi.cxx: align_stack_offset and stack_size now use the type's
       natural alignment (nAlignment) and raw size (nSize) instead of
       hardcoded 8/alignment and 8-byte slot rounding. This matches the
       AAPCS64/System V ABI requirement that stack arguments use their
       natural alignment and size, matching the macOS reference.
    
    2. uno2cpp.cxx: Restructure the return-value switch to use 'default'
       with a bSimpleReturn check (matching the macOS reference), so
       fill_struct is only called for register-returned aggregates, not
       for types that use the x8 hidden-result buffer.
    
    (cherry picked from commit a95bc48985b3fb1f81ca307ce89000d4dd6aa715)
---
 .../source/cpp_uno/gcc3_freebsd_aarch64/abi.cxx        | 18 ++++++++----------
 .../source/cpp_uno/gcc3_freebsd_aarch64/uno2cpp.cxx    | 13 ++++++++-----
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/abi.cxx 
b/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/abi.cxx
index c119e4580b..0106fd44dc 100644
--- a/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/abi.cxx
+++ b/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/abi.cxx
@@ -333,10 +333,13 @@ void fill_struct( typelib_TypeDescriptionReference 
*pTypeRef, const sal_uInt64*
 
 sal_uInt32 align_stack_offset( sal_uInt32 offset, 
typelib_TypeDescriptionReference *pTypeRef )
 {
-       // On aarch64 System V ABI, the smallest stack slot is 8 bytes.
-       // Align to 8 bytes regardless of the type's natural alignment.
-       const sal_uInt32 align = 8;
-       return ( offset + align - 1 ) & ~( align - 1 );
+       typelib_TypeDescription * pTypeDescr = 0;
+       TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
+       sal_uInt32 alignment = pTypeDescr->nAlignment;
+       TYPELIB_DANGER_RELEASE( pTypeDescr );
+       if ( alignment == 0 )
+               alignment = 1;
+       return ( offset + alignment - 1 ) & ~( alignment - 1 );
 }
 
 sal_uInt32 stack_size( typelib_TypeDescriptionReference *pTypeRef )
@@ -345,12 +348,7 @@ sal_uInt32 stack_size( typelib_TypeDescriptionReference 
*pTypeRef )
        TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
        sal_uInt32 size = pTypeDescr->nSize;
        TYPELIB_DANGER_RELEASE( pTypeDescr );
-       // In the System V AMD64 / AAPCS64 stack layout, the smallest slot that
-       // can be passed is 8 bytes (the natural stack slot size).  Round up
-       // so that small types like BOOLEAN (1B), SHORT (2B), LONG (4B) each
-       // occupy a full 8-byte slot on the overflow stack, matching what the
-       // callee's ABI expects.
-       return ( size + 7 ) & ~7u;
+       return size;
 }
 
 } // namespace aarch64
diff --git a/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/uno2cpp.cxx 
b/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/uno2cpp.cxx
index 8cb8c0d517..fc754843e9 100644
--- a/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/uno2cpp.cxx
+++ b/main/bridges/source/cpp_uno/gcc3_freebsd_aarch64/uno2cpp.cxx
@@ -164,12 +164,15 @@ static void callVirtualMethod(void * pThis, sal_uInt32 
nVtableIndex,
        case typelib_TypeClass_DOUBLE:
                *reinterpret_cast<double *>( pRegisterReturn ) = fpReturn[0];
                break;
-       case typelib_TypeClass_STRUCT:
-       case typelib_TypeClass_EXCEPTION:
-               aarch64::fill_struct( pReturnTypeRef, &gpReturn[0], 
&fpReturn[0], pRegisterReturn );
-               break;
        default:
-               break;
+               {
+                       sal_Int32 const nRetSize = pReturnTypeRef->pType->nSize;
+                       if (bSimpleReturn && nRetSize > 0)
+                       {
+                               aarch64::fill_struct( pReturnTypeRef, 
&gpReturn[0], &fpReturn[0], pRegisterReturn );
+                       }
+                       break;
+               }
        }
 }
 

Reply via email to