From 19bf83a9a068f2d5293b63c9300f99172b2d278d Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Mon, 20 Dec 2021 15:19:50 +0000 Subject: Darwin: Update rules for handling alignment of globals. The current rule was too strict and has not been required since Darwin11. This relaxes the constraint to allow up to 2^28 alignment for non-common entities. Common is still restricted to a maximum aligment of 2^15. When the host is an older version of Darwin ( earlier that 11 ) then the existing constraint is still applied. Note that this is a host constraint not a target one (so that a compilation on 10.7 targeting 10.6 is allowed to use a greater alignment than the tools on 10.6 support). This matches the behaviour of clang. Signed-off-by: Iain Sandoe gcc/ChangeLog: * config.gcc: Emit L2_MAX_OFILE_ALIGNMENT with suitable values for the host. * config/darwin.c (darwin_emit_common): Error for alignment values > 32768. * config/darwin.h (MAX_OFILE_ALIGNMENT): Rework to use the configured L2_MAX_OFILE_ALIGNMENT. gcc/testsuite/ChangeLog: * gcc.dg/darwin-aligned-globals.c: New test. * gcc.dg/darwin-comm-1.c: New test. * gcc.dg/attr-aligned.c: Amend for new alignment values on Darwin. * gcc.target/i386/pr89261.c: Likewise. --- gcc/config/darwin.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'gcc/config/darwin.c') diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index e580319..5045b68 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -2558,7 +2558,6 @@ darwin_emit_common (FILE *fp, const char *name, rounded = (size + (align-1)) & ~(align-1); l2align = floor_log2 (align); - gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); in_section = comm_section; /* We mustn't allow multiple public symbols to share an address when using @@ -2709,6 +2708,10 @@ darwin_asm_output_aligned_decl_common (FILE *fp, tree decl, const char *name, #ifdef DEBUG_DARWIN_MEM_ALLOCATORS fprintf (fp, "# adcom: %s (%d,%d) decl=0x0\n", name, (int)size, (int)align); #endif + /* Common variables are limited to a maximum alignment of 2^15. */ + if (align > 32768) + error_at (UNKNOWN_LOCATION, "common variables must have an alignment" + " of 32678 or less"); darwin_emit_common (fp, name, size, align); return; } @@ -2736,7 +2739,7 @@ fprintf (fp, "# adcom: %s (%lld,%d) ro %d cst %d stat %d com %d pub %d" } /* We shouldn't be messing with this if the decl has a section name. */ - gcc_assert (DECL_SECTION_NAME (decl) == NULL); + gcc_checking_assert (DECL_SECTION_NAME (decl) == NULL); /* We would rather not have to check this here - but it seems that we might be passed a decl that should be in coalesced space. */ @@ -2765,10 +2768,16 @@ fprintf (fp, "# adcom: %s (%lld,%d) ro %d cst %d stat %d com %d pub %d" l2align = floor_log2 (align / BITS_PER_UNIT); /* Check we aren't asking for more aligment than the platform allows. */ - gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); + gcc_checking_assert (l2align <= L2_MAX_OFILE_ALIGNMENT); if (TREE_PUBLIC (decl) != 0) - darwin_emit_common (fp, name, size, align); + { + /* Common variables are limited to a maximum alignment of 2^15. */ + if (l2align > 15) + error_at (DECL_SOURCE_LOCATION (decl), "common variables must have" + " an alignment of 32678 or less"); + darwin_emit_common (fp, name, size, align); + } else darwin_emit_local_bss (fp, decl, name, size, l2align); } -- cgit v1.1