]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix alignment of pthread_mutex_t
authorDaniel King <dmking@adacore.com>
Fri, 13 Sep 2024 15:16:52 +0000 (16:16 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 4 Nov 2024 15:57:56 +0000 (16:57 +0100)
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.

gcc/ada/libgnat/s-oslock__posix.ads

index e2c237f26981466d4c3a8ac920628a346ec4415d..cde92e5f23a39f108c4e987ff1c008b23bc5715b 100644 (file)
@@ -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;