diff options
author | Alex Coplan <alex.coplan@arm.com> | 2022-11-03 12:11:45 +0000 |
---|---|---|
committer | Alex Coplan <alex.coplan@arm.com> | 2022-11-03 12:11:45 +0000 |
commit | fb1ff58603dd0ebc184b0e07c0628c6eb746c491 (patch) | |
tree | 613238295d48f807de335a88095ee290d9566ee6 | |
parent | 74dda148e9eac68f0dde2904485539a3497a2331 (diff) | |
download | binutils-gdb-fb1ff58603dd0ebc184b0e07c0628c6eb746c491.tar.gz |
libiberty: Account for CHERI alignment requirement in objalloc
The calculation of OBJALLOC_ALIGN in include/objalloc.h ensures that
allocations are sufficiently aligned for doubles, but on CHERI
architectures it is possible that void * has a greater alignment
requirement than double.
Instead of deriving the alignment requirement from double alone, this
patch uses a union to compute the maximum alignment between double and
void *.
This fixes alignment faults seen when compiling the binutils for
pure-capability Morello. With this patch applied, the majority of
binutils tests pass when the binutils themselves are compiled for
purecap.
This patch is a backport of commit
a8af417a8a1559a3ebceb0c761cf26ebce5eab7f, initially upstreamed to
Morello GCC.
-rw-r--r-- | include/objalloc.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/objalloc.h b/include/objalloc.h index 3d86dcca69c..23fb3f25ba3 100644 --- a/include/objalloc.h +++ b/include/objalloc.h @@ -50,7 +50,13 @@ struct objalloc /* Work out the required alignment. */ -struct objalloc_align { char x; double d; }; +struct objalloc_align { + char x; + union { + double d; + void *p; + } u; +}; #if defined (__STDC__) && __STDC__ #ifndef offsetof @@ -60,7 +66,7 @@ struct objalloc_align { char x; double d; }; #ifndef offsetof #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER) #endif -#define OBJALLOC_ALIGN offsetof (struct objalloc_align, d) +#define OBJALLOC_ALIGN offsetof (struct objalloc_align, u) /* Create an objalloc structure. Returns NULL if malloc fails. */ |