From 27169a7f66e0bf5115ab41c325679b42f80fb966 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Tue, 11 Nov 2025 17:01:38 +0800
Subject: [PATCH 02/13] target.cpp: fix unions for powerpc

Fixes: https://github.com/cryptocorrosion/cryptocorrosion/issues/87
---
 src/trans/target.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/trans/target.cpp b/src/trans/target.cpp
index 769ce96b..ff07ecca 100644
--- a/src/trans/target.cpp
+++ b/src/trans/target.cpp
@@ -2157,6 +2157,14 @@ namespace {
             if( size == SIZE_MAX ) {
                 BUG(sp, "Unsized type in union");
             }
+            // PowerPC 32-bit ABI: union members with natural alignment 4-8 use embedding alignment 4
+            if(Target_GetCurSpec().m_arch.m_name == "powerpc")
+            {
+                if( align >= 4 && align <= 8 )
+                {
+                    align = 4;
+                }
+            }
             rv.size  = ::std::max(rv.size , size );
             rv.align = ::std::max(rv.align, align);
         }
-- 
2.43.0

