aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2025-12-03 13:07:22 -0800
committerPaul Eggert2025-12-03 13:10:35 -0800
commit335f1a11f072ee05e2ea52ea08bf7df6a42e3e50 (patch)
treef29fa3b81e7ec2e903b47b575b6ee1ba674d04df
parentc79eb45340d8c82acd148fbfab498b9579f27c6d (diff)
downloademacs-335f1a11f072ee05e2ea52ea08bf7df6a42e3e50.tar.gz
emacs-335f1a11f072ee05e2ea52ea08bf7df6a42e3e50.zip
Waste 4 fewer bytes in GNU/Linux 32-bit HPPA
Also, add more commentary about the situation. * src/systhread.h (SYSTHREAD_ALIGN_ROOM): Use alignof (double), not alignof (int), to align the room. This means we have only 8 (not 12) bytes of slop on 32-bit HPPA GNU/Linux.
-rw-r--r--src/systhread.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/systhread.h b/src/systhread.h
index 30fa5a94b45..14266ff600f 100644
--- a/src/systhread.h
+++ b/src/systhread.h
@@ -32,7 +32,16 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
32 Unfortunately POSIX allows this curious situation. 32 Unfortunately POSIX allows this curious situation.
33 Do this by allocating possibly-poorly-aligned objects a bit larger 33 Do this by allocating possibly-poorly-aligned objects a bit larger
34 than pthread_mutex_t and pthread_cond_t, and then aligning pointers 34 than pthread_mutex_t and pthread_cond_t, and then aligning pointers
35 to these objects at runtime. */ 35 to these objects at runtime.
36
37 Although since glibc 2.4 (2006) the stricter alignment has not been
38 needed by the underlying 32-bit HPPA code so the types are overaligned,
39 the overalignment is still present in glibc 2.42 (2025) to avoid
40 changing ABI offsets in structs that other libraries make visible.
41 Address the issue for all platforms that overalign the two types.
42 Do not bother to optimize for glibc 2.4+ on 32-bit HPPA even though
43 as of 2025 it is the only maintained platform known to overalign and
44 it does not need the overalignment. */
36 45
37#if (ALIGNOF_PTHREAD_COND_T <= ALIGNOF_MAX_ALIGN_T \ 46#if (ALIGNOF_PTHREAD_COND_T <= ALIGNOF_MAX_ALIGN_T \
38 && ALIGNOF_PTHREAD_MUTEX_T <= ALIGNOF_MAX_ALIGN_T) 47 && ALIGNOF_PTHREAD_MUTEX_T <= ALIGNOF_MAX_ALIGN_T)
@@ -40,17 +49,21 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
40 and is already aligned properly. */ 49 and is already aligned properly. */
41# define SYSTHREAD_ALIGN_PTR(type, ptr) (ptr) 50# define SYSTHREAD_ALIGN_PTR(type, ptr) (ptr)
42#else 51#else
43/* An unusual case, e.g., GNU/Linux 32-bit HPPA. 52/* An unusual case, e.g., GNU/Linux 32-bit HPPA with glibc 2.42.
44 Aligning SYSTHREAD_ALIGN_ROOM (TYPE) * up for TYPE * results in a 53 Aligning SYSTHREAD_ALIGN_ROOM (TYPE) * up for TYPE * results in a
45 valid pointer. TYPE's alignment must be at least that of int; 54 valid pointer. TYPE's alignment must be at least that of double;
46 in practice it is always greater than that of max_align_t. */ 55 in practice it is always greater than that of max_align_t. */
47# define SYSTHREAD_ALIGN_ROOM(type) \ 56# define SYSTHREAD_ALIGN_ROOM(type) \
48 union { int i; char room[sizeof (type) + alignof (type) - alignof (int)]; } 57 union \
58 { \
59 double i; \
60 char room[sizeof (type) + alignof (type) - alignof (double)]; \
61 }
49/* Align PTR up for TYPE *. 62/* Align PTR up for TYPE *.
50 PTR should be of type SYSTHREAD_ALIGN_ROOM (TYPE) *. */ 63 PTR should be of type SYSTHREAD_ALIGN_ROOM (TYPE) *. */
51# define SYSTHREAD_ALIGN_PTR(type, ptr) \ 64# define SYSTHREAD_ALIGN_PTR(type, ptr) \
52 ((type *) ((uintptr_t) ((ptr)->room + (alignof (type) - alignof (int))) \ 65 ((type *) ((uintptr_t) ((ptr)->room + (alignof (type) - alignof (double))) \
53 & ~(alignof (type) - alignof (int)))) 66 & ~(alignof (type) - alignof (double))))
54#endif 67#endif
55 68
56/* A system mutex is just a pthread mutex, possibly with alignment slop. 69/* A system mutex is just a pthread mutex, possibly with alignment slop.