[PATCH] middle-end: Call get_constant_section with DECL not EXP.

David Edelsohn dje.gcc@gmail.com
Thu Jul 9 18:29:31 GMT 2020


output_constant_def_contents() can call get_constant_section() with an
EXP that is a CONSTRUCTOR, which is not a declaration.  This can hit
asserts in GCC machinery to choose a named section for the initialization
data that expects the parameters to be DECLs.

get_constant_section() is a wrapper around TARGET_ASM_SELECT_SECTION,
which is documented as:

Return the section into which @var{exp} should be placed.  You can
assume that @var{exp} is either a @code{VAR_DECL} node or a constant of
some sort.

A CONSTRUCTOR initializer is a "constant of some sort", but isn't
consistent with DECL_SECTION_NAME, etc.

This patch changes get_constant_section() and its callers to pass the
DECL within the EXP instead of the EXP, and to explicitly pass the reloc
information that must be determined from the EXP.

Another option is to remove get_constant_section() completely, replace
it with direct calls to targetm.asm_out.select_section() (for which it
now is a complete pass-through), and update the Target Hook
documentation.

What's the preferred path forward?

Thanks, David

gcc/ChangeLog

2020-07-09  David Edelsohn  <dje.gcc@gmail.com>

        * varasm.c (get_constant_section): Change first parameter from
        EXP to DECL and insert reloc second parameter.
        (build_constant_desc): Adjust call.
        (output_constant_def_contents): Adjust call.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-middle-end-Call-get_constant_section-with-DECL-not-E.patch
Type: application/octet-stream
Size: 2743 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200709/83e3c0cc/attachment.obj>


More information about the Gcc-patches mailing list