From: Daniel King <dmk...@adacore.com>

On most targets the alignment of unsigned long is the same as pointer
alignment, but on CHERI targets pointers have larger alignment (16 bytes
compared to 8 bytes). pthread_mutex_t needs the same alignment as
System.Address to account for CHERI targets.

gcc/ada/ChangeLog:

        * libgnat/s-oslock__posix.ads: Fix alignment of pthread_mutex_t
        for CHERI targets.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-oslock__posix.ads | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/s-oslock__posix.ads 
b/gcc/ada/libgnat/s-oslock__posix.ads
index e2c237f2698..cde92e5f23a 100644
--- a/gcc/ada/libgnat/s-oslock__posix.ads
+++ b/gcc/ada/libgnat/s-oslock__posix.ads
@@ -52,6 +52,11 @@ private
       Data : char_array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE);
    end record;
    pragma Convention (C, pthread_mutex_t);
-   for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment;
+   for pthread_mutex_t'Alignment use
+     Integer'Max (Interfaces.C.unsigned_long'Alignment,
+                  System.Address'Alignment);
+   --  On some targets (e.g. CHERI), pointers have larger alignment than
+   --  unsigned_long. On other targets (e.g. some 16-bit targets) long is
+   --  larger than a pointer. Choose the largest to err on the side of caution.
 
 end System.OS_Locks;
-- 
2.43.0

Reply via email to