This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Section Anchors and named sections


	This patch fixes a problem that I have encountered with the
current section anchors implementation when trying to enable it by default
for PowerPC, specifically AIX.

	get_block_for_decl() tests the DECL for specific characteristics
that could preclude it being placed in a section anchor block.  It skips
DECLs marked DECL_ONE_ONLY because the DECL is suppose to be isolated.  It
also skips DECLs in sections marked SECTION_NOSWITCH because that requires
a standalone definition.  A similar situation exists for DECLs placed in
unique sections.  Such DECLs currently are not excluded, although the
named section mechanism will override the block section choice.

	This omission could be solved by testing if SECTION_STYLE is
non-zero: either SECTION_NOSWITCH or SECTION_NAMED, instead of only
SECTION_NOSWITCH.  However, get_block_for_decl() tests the flags for the
section by calling get_variable_section() and that is the cause of the
failure symptom observed on AIX.

	get_variable_section() eventually calls get_section(), which both
stores the flags calculated from the DECL in the section and adds the
section to a hash table.  The problem is that some characeristics of the
DECL may change because an isolated DECL is processed in a slightly
different order before associating it with a section.

	An isolated DECL is emitted by assemble_variable(), which applies
target hooks like DATA_ALIGNMENT before invoking get_variable_section().
In the case of a variable assigned to a unique section with section
anchors enabled, this is a section invocation of get_section with a DECL
that may have been modified.  The section already is in the hash table,
but the flags may fail the get_section() self-check when compared with the
originally created section.  This does happen and causes failures on AIX.

	The appended patch addresses the direct problem.  The same logic
used by resolve_unique_section() to decide whether to apply a unique
section is used to avoid placing the DECL in a block, so the entire
section anchor machinery is bypassed.  Because this decision is based on
persistent information about the state of the compiler when compiling the
translation unit and not on a characteristic of the DECL that could change
during the compilation, the patch modifies use_blocks_for_decl_p() and not
get_block_for_decl().

	As a follow-on, the section anchor infrastructure probably should
be modified to apply DATA_ALIGNMENT and CONSTANT_ALIGNMENT to the DECL
before invoking get_variable_section, matching the rhythm of the compiler
when assembling a variable without section anchors.  That would resolve
the symptom I am seeing, but leaves a latent problem of the section anchor
machinery creating a block for a DECL that never will be emitted in the
block.  Making the flags calculation consistent solves the symptom but not
the problem.

	In summary, this patch restricts the section anchor mechnism to
not try to place VAR_DECLs in section anchor blocks when
flag_data_sections is enabled and the target supports named sections.

Bootstrapped and regression tested on powerpc-ibm-aix5.2.0.0.

Okay for mainline?

Thanks, David

: ADDPATCH middle-end :


	* varasm.c (use_blocks_for_decl_p): Do not use blocks for
	VAR_DECLs placed in unique sections.

Index: varasm.c
===================================================================
*** varasm.c	(revision 113115)
--- varasm.c	(working copy)
*************** use_blocks_for_decl_p (tree decl)
*** 927,932 ****
--- 927,939 ----
    if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
      return false;
  
+   /* There is no point using object blocks for something that is
+      isolated by definition.  */
+   if (TREE_CODE (decl) == VAR_DECL
+       && flag_data_sections
+       && targetm.have_named_sections)
+     return false;
+ 
    /* Detect decls created by dw2_force_const_mem.  Such decls are
       special because DECL_INITIAL doesn't specify the decl's true value.
       dw2_output_indirect_constants will instead call assemble_variable


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]