https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94134
Stephen Casner <casner at acm dot org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target| |pdp11-aout --- Comment #1 from Stephen Casner <casner at acm dot org> --- I would be happy to work on implementing a fix for this bug if someone can point me in the right direction. I tried defining a TARGET_ASM_SELECT_SECTION function for the pdp11-aout target that always returns data_section, but the result was unchanged. I verified that function was only called once when compiling my test program, that was at the point the .data directive was emitted. Then I stepped through the code in varasm.c to understand a bit about why this happens. Because the test program variable is not initialized to a nonzero value, bss_initializer_p returns true, and consequently get_variable_section returns lcomm_section. Because lcomm_section is of style SECTION_NOSWITCH, assemble_variable calls assemble_noswitch_variable to generate the output rather than calling switch_to_section and assemble_variable_contents as is what happens to generate the .data directive before my test program variable that _is_ initialized to a nonzero value. assemble_noswitch_variable generates the assembler output by calling the callback of the section, which for lcomm_section is emit_local. emit_local calls ASM_OUTPUT_ALIGNED_LOCAL which has been defined for the pdp11-aout target and implemented in pdp11_asm_output_var. A partial fix might be to have that function output a .bss directive ahead of the zero-initialized variable. A side comment is that I have not seen any .bss directive even in the output from the real C program that led me to observe this bug. But since we can't switch in_section to lcomm_section, I don't know to avoid emitting .bss ahead of every zero-initialized (or uninitialized) variable even when there are several in a row. Furthermore, the comment for #define SECTION_NOSWITCH says that it is for sections that we cannot switch to with an assembler directive (like .bss), so perhaps the logic leading to the choice of lcomm_section is not appropriate for the pdp11_aout target. In addition, if the "static" is removed from the zero-initialized variable declaration in my test program so it is global, then TREE_PUBLIC is true so it is not assigned to the lcomm_section and instead falls through to be assigned to the .data section. It seems that zero-initialized variables should be assigned to the same section whether local or global.