1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

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.
This commit is contained in:
Paul Eggert 2025-12-03 13:07:22 -08:00
parent c79eb45340
commit 335f1a11f0

View file

@ -32,7 +32,16 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
Unfortunately POSIX allows this curious situation. Unfortunately POSIX allows this curious situation.
Do this by allocating possibly-poorly-aligned objects a bit larger Do this by allocating possibly-poorly-aligned objects a bit larger
than pthread_mutex_t and pthread_cond_t, and then aligning pointers than pthread_mutex_t and pthread_cond_t, and then aligning pointers
to these objects at runtime. */ to these objects at runtime.
Although since glibc 2.4 (2006) the stricter alignment has not been
needed by the underlying 32-bit HPPA code so the types are overaligned,
the overalignment is still present in glibc 2.42 (2025) to avoid
changing ABI offsets in structs that other libraries make visible.
Address the issue for all platforms that overalign the two types.
Do not bother to optimize for glibc 2.4+ on 32-bit HPPA even though
as of 2025 it is the only maintained platform known to overalign and
it does not need the overalignment. */
#if (ALIGNOF_PTHREAD_COND_T <= ALIGNOF_MAX_ALIGN_T \ #if (ALIGNOF_PTHREAD_COND_T <= ALIGNOF_MAX_ALIGN_T \
&& ALIGNOF_PTHREAD_MUTEX_T <= ALIGNOF_MAX_ALIGN_T) && ALIGNOF_PTHREAD_MUTEX_T <= ALIGNOF_MAX_ALIGN_T)
@ -40,17 +49,21 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
and is already aligned properly. */ and is already aligned properly. */
# define SYSTHREAD_ALIGN_PTR(type, ptr) (ptr) # define SYSTHREAD_ALIGN_PTR(type, ptr) (ptr)
#else #else
/* An unusual case, e.g., GNU/Linux 32-bit HPPA. /* An unusual case, e.g., GNU/Linux 32-bit HPPA with glibc 2.42.
Aligning SYSTHREAD_ALIGN_ROOM (TYPE) * up for TYPE * results in a Aligning SYSTHREAD_ALIGN_ROOM (TYPE) * up for TYPE * results in a
valid pointer. TYPE's alignment must be at least that of int; valid pointer. TYPE's alignment must be at least that of double;
in practice it is always greater than that of max_align_t. */ in practice it is always greater than that of max_align_t. */
# define SYSTHREAD_ALIGN_ROOM(type) \ # define SYSTHREAD_ALIGN_ROOM(type) \
union { int i; char room[sizeof (type) + alignof (type) - alignof (int)]; } union \
{ \
double i; \
char room[sizeof (type) + alignof (type) - alignof (double)]; \
}
/* Align PTR up for TYPE *. /* Align PTR up for TYPE *.
PTR should be of type SYSTHREAD_ALIGN_ROOM (TYPE) *. */ PTR should be of type SYSTHREAD_ALIGN_ROOM (TYPE) *. */
# define SYSTHREAD_ALIGN_PTR(type, ptr) \ # define SYSTHREAD_ALIGN_PTR(type, ptr) \
((type *) ((uintptr_t) ((ptr)->room + (alignof (type) - alignof (int))) \ ((type *) ((uintptr_t) ((ptr)->room + (alignof (type) - alignof (double))) \
& ~(alignof (type) - alignof (int)))) & ~(alignof (type) - alignof (double))))
#endif #endif
/* A system mutex is just a pthread mutex, possibly with alignment slop. /* A system mutex is just a pthread mutex, possibly with alignment slop.