Skip to content

Commit 405f45a

Browse files
apinski-quicpinskia
authored andcommitted
varasm: Ensure each variable in mergeable section is the entity size [PR121394]
Now there are mergeable sections which have an entity size, we can place decls (constants) that are smaller in size in these sections. An example is an `long double` which has a size of 12 bytes on i686 and is placed in the 16 bytes shareable section. For an example with the following C++ code: ``` std::initializer_list<long double> a = {0.3l}; ``` We place the constant array in the .rodata.cst16 section but we don't add a padding to 16 bytes. ``` .section .rodata.cst16,"aM",@progbits,16 .align 16 .type _ZGR1a_, @object .size _ZGR1a_, 12 _ZGR1a_: .long -1717986918 .long -1717986919 .long 16381 .text ``` GAS has a workaround added to do the padding but other assemblers don't. The gas workaround was added with https://sourceware.org/legacy-ml/binutils/2002-11/msg00615.html . Now for the constant pool, GCC does emit a `.align` to padd out the size correctly. This was done in r0-46282-gf41115930523b3. The same padding should be done when emitting a variable contents when in a mergeable section. This patch implements the padding and we now get an addition `.zero 4` which pads out the section. Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/121394 gcc/ChangeLog: * varasm.cc (assemble_variable_contents): Pad out mergeable sections if needed. (output_constant_pool_1): Change the padding to be explicit zeroing for mergeable sections. Signed-off-by: Andrew Pinski <[email protected]>
1 parent 59dbef0 commit 405f45a

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

gcc/varasm.cc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,19 @@ assemble_variable_contents (tree decl, const char *name,
24752475
else
24762476
/* Leave space for it. */
24772477
assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl)));
2478+
/* For mergeable section, make sure the section is zero filled up to
2479+
the entity size of the section. */
2480+
if (in_section
2481+
&& (in_section->common.flags & SECTION_MERGE)
2482+
&& tree_fits_uhwi_p (DECL_SIZE_UNIT (decl))
2483+
&& ((in_section->common.flags & SECTION_ENTSIZE)
2484+
> tree_to_uhwi (DECL_SIZE_UNIT (decl))))
2485+
{
2486+
unsigned HOST_WIDE_INT entsize, declsize;
2487+
entsize = (in_section->common.flags & SECTION_ENTSIZE);
2488+
declsize = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2489+
assemble_zeros (entsize - declsize);
2490+
}
24782491
targetm.asm_out.decl_end ();
24792492
}
24802493
}
@@ -4435,10 +4448,16 @@ output_constant_pool_1 (class constant_descriptor_rtx *desc,
44354448

44364449
/* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
44374450
sections have proper size. */
4438-
if (align > GET_MODE_BITSIZE (desc->mode)
4439-
&& in_section
4440-
&& (in_section->common.flags & SECTION_MERGE))
4441-
assemble_align (align);
4451+
if (in_section
4452+
&& (in_section->common.flags & SECTION_MERGE)
4453+
&& ((in_section->common.flags & SECTION_ENTSIZE)
4454+
> GET_MODE_SIZE (desc->mode)))
4455+
{
4456+
unsigned HOST_WIDE_INT entsize, constsize;
4457+
entsize = (in_section->common.flags & SECTION_ENTSIZE);
4458+
constsize = GET_MODE_SIZE (desc->mode);
4459+
assemble_zeros (entsize - constsize);
4460+
}
44424461

44434462
#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
44444463
done:

0 commit comments

Comments
 (0)