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....@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.
0001-middle-end-Call-get_constant_section-with-DECL-not-E.patch
Description: Binary data