+2023-11-13 Bruno Haible <bruno@clisp.org>
+
+ Don't use CHERI facilities with CC="clang -march=morello".
+ Suggested by Jessica Clarke <jrtc27@jrtc27.com> in
+ <https://lists.gnu.org/archive/html/bug-gnulib/2023-11/msg00116.html>.
+ * lib/alignalloc.h (alignalloc): Test __CHERI_PURE_CAPABILITY__, not
+ __CHERI__.
+ * lib/eealloc.h (eemalloc, eerealloc): Likewise.
+ * lib/ialloc.h (irealloc, ireallocarray): Likewise.
+ * lib/malloca.h (malloca): Likewise.
+ * lib/malloca.c (small_t, mmalloca, freea): Likewise.
+ * lib/rawmemchr.c (rawmemchr): Likewise.
+ * lib/safe-alloc.h (safe_alloc_realloc_n): Likewise.
+ * lib/sigsegv.c (SIGSEGV_FAULT_STACKPOINTER): Likewise.
+ * lib/ssfmalloc.h (struct dissected_page_header, init_small_block_page,
+ init_medium_block_page, free_block_from_pool, allocate_block): Likewise.
+ * tests/test-stdint.c: Likewise.
+
2023-11-13 Bruno Haible <bruno@clisp.org>
jit/cache: Fix configure test.
rawmemchr: speed up, particularly on CHERI
* lib/rawmemchr.c (rawmemchr) [__CHERI__]: Use memchr instead of
one-byte reads. This sped up a simple benchmark (rawmemchr on
- 100,000 bytes) by 6x on a Research Morello SoC r0p0 on CheriBSD 14.
+ 100,000 bytes) by 6x on a Research Morello SoC r0p0 on CheriBSD 14.
[!__CHERI__]: Use sizeof, not alignof, as better alignment
should help performance a bit on some platforms.
* modules/rawmemchr (Depends-on): Remove alignasof.
#include <errno.h>
#include <stdlib.h>
#include "idx.h"
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
if (alignment < sizeof (void *))
alignment = sizeof (void *);
errno = posix_memalign (&ptr, alignment, size | !size);
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
if (ptr != NULL)
ptr = cheri_bounds_set (ptr, size);
# endif
#endif
#include <stdlib.h>
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
if (n == 0)
nx = 1;
void *ptr = malloc (nx);
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
if (ptr != NULL)
ptr = cheri_bounds_set (ptr, n);
# endif
if (n == 0)
nx = 1;
void *ptr = realloc (p, nx);
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
if (ptr != NULL)
ptr = cheri_bounds_set (ptr, n);
# endif
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
/* Work around GNU realloc glitch by treating a zero size as if it
were 1, so that returning NULL is equivalent to failing. */
p = realloc (p, s | !s);
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
if (p != NULL)
p = cheri_bounds_set (p, s);
#endif
if (n == 0 || s == 0)
nx = sx = 1;
p = reallocarray (p, nx, sx);
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
if (p != NULL && (n == 0 || s == 0))
p = cheri_bounds_set (p, 0);
#endif
#include "malloca.h"
#include <stdckdint.h>
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
allocation.
- NULL comes from a failed heap allocation. */
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
/* Type for holding the original malloc() result. */
typedef uintptr_t small_t;
#else
So, the memory range [p, p+n) lies in the allocated memory range
[mem, mem + nplus). */
small_t *sp = p;
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
sp[-1] = umem;
p = (char *) cheri_bounds_set ((char *) p - sizeof (small_t),
sizeof (small_t) + n)
{
char *cp = p;
small_t *sp = p;
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
void *mem = sp[-1];
# else
void *mem = cp - sp[-1];
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
memory allocated on the stack, that must be freed using freea() before
the function returns. Upon failure, it returns NULL. */
#if HAVE_ALLOCA
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
# define malloca(N) \
((N) < 4032 - (2 * sa_alignment_max - 1) \
? cheri_bounds_set ((void *) (((uintptr_t) \
void *
rawmemchr (const void *s, int c_in)
{
-# ifdef __CHERI__
+# ifdef __CHERI_PURE_CAPABILITY__
/* Most architectures let you read an aligned word,
even if the unsigned char array at S ends in the middle of the word.
However CHERI does not, so call memchr
#endif
#include <stdlib.h>
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
if (count == 0 || size == 0)
countx = sizex = 1;
ptr = reallocarray (ptr, countx, sizex);
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
if (ptr != NULL && (count == 0 || size == 0))
ptr = cheri_bounds_set (ptr, 0);
#endif
/* See sys/arm64/include/ucontext.h. */
-# if defined __CHERI__
+# if defined __CHERI_PURE_CAPABILITY__
# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.mc_capregs.cap_sp
# else
# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.mc_gpregs.gp_sp
#include "thread-optim.h"
#include "gl_oset.h"
#include "gl_rbtree_oset.h"
-#ifdef __CHERI__
+#ifdef __CHERI_PURE_CAPABILITY__
# include <cheri.h>
#endif
struct dissected_page_header
{
struct any_page_header common;
- #ifdef __CHERI__
+ #ifdef __CHERI_PURE_CAPABILITY__
/* This page, with bounds [page, page + PAGESIZE). */
uintptr_t whole_page;
#endif
{
struct small_page_header *pageptr = (struct small_page_header *) page;
pageptr->common.common.page_type = small_page_type;
- #ifdef __CHERI__
+ #ifdef __CHERI_PURE_CAPABILITY__
pageptr->common.whole_page = page;
#endif
{
struct medium_page_header *pageptr = (struct medium_page_header *) page;
pageptr->common.common.page_type = medium_page_type;
- #ifdef __CHERI__
+ #ifdef __CHERI_PURE_CAPABILITY__
pageptr->common.whole_page = page;
#endif
pageptr->num_gaps = 1;
FREE_PAGES (pool->freeable_page, PAGESIZE);
/* Don't free the page now, but later. */
- #ifdef __CHERI__
+ #ifdef __CHERI_PURE_CAPABILITY__
pool->freeable_page = pageptr->whole_page;
#else
pool->freeable_page = page;
(size <= SMALL_BLOCK_MAX_SIZE ? &small_block_pages : &medium_block_pages);
block = allocate_block_from_pool (size, pool);
if (mt) gl_lock_unlock (ssfmalloc_lock);
-#if defined __CHERI__
+#if defined __CHERI_PURE_CAPABILITY__
if (block != 0)
{
size_t offset = block & (PAGESIZE - 1);
#ifdef INTPTR_MAX
intptr_t g[3] = { 17, INTPTR_MIN, INTPTR_MAX };
verify (sizeof (void *) <= sizeof (intptr_t));
-# ifndef __CHERI__
+# ifndef __CHERI_PURE_CAPABILITY__
verify (TYPE_MINIMUM (intptr_t) == INTPTR_MIN);
verify (TYPE_MAXIMUM (intptr_t) == INTPTR_MAX);
# endif
#ifdef UINTPTR_MAX
uintptr_t h[2] = { 17, UINTPTR_MAX };
verify (sizeof (void *) <= sizeof (uintptr_t));
-# ifndef __CHERI__
+# ifndef __CHERI_PURE_CAPABILITY__
verify (TYPE_MAXIMUM (uintptr_t) == UINTPTR_MAX);
# endif
verify_same_types (UINTPTR_MAX, (uintptr_t) 0 + 0);
verify_width (UINT_FAST32_WIDTH, 0, UINT_FAST32_MAX);
verify_width (INT_FAST64_WIDTH, INT_FAST64_MIN, INT_FAST64_MAX);
verify_width (UINT_FAST64_WIDTH, 0, UINT_FAST64_MAX);
-#ifndef __CHERI__
+#ifndef __CHERI_PURE_CAPABILITY__
# ifdef INTPTR_WIDTH
verify_width (INTPTR_WIDTH, INTPTR_MIN, INTPTR_MAX);
# endif