public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Alex Coplan <acoplan@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] libiberty: Account for CHERI alignment requirement in objalloc Date: Tue, 1 Nov 2022 12:57:41 +0000 (GMT) [thread overview] Message-ID: <20221101125741.7C2443858403@sourceware.org> (raw) https://gcc.gnu.org/g:a8af417a8a1559a3ebceb0c761cf26ebce5eab7f commit a8af417a8a1559a3ebceb0c761cf26ebce5eab7f Author: Alex Coplan <alex.coplan@arm.com> Date: Tue Nov 1 12:54:03 2022 +0000 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. We are upstreaming this patch to GCC first since GCC is the canonical upstream for libiberty, but the patch is currently motivated mainly by binutils. Diff: --- include/objalloc.h | 10 ++++++++-- 1 file 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. */
reply other threads:[~2022-11-01 12:57 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221101125741.7C2443858403@sourceware.org \ --to=acoplan@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).