https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94134
--- Comment #9 from Stephen Casner <casner at acm dot org> --- Thank you all for your prompt action on this bug. I have some comments and questions if you are willing to help with my education about gcc internals: 1. pdp11-aout does not have a .lcommon or .lcomm section, just .text, .data and .bss. But also I'm missing something about the concept of a NOSWITCH_SECTION that you can't switch to with an assembler directive -- how do you tell the assembler to assign a variable to that section if you don't emit a directive? 2. Good point about optimization possibly omitting the variables in my test case. Of course, the variables were used in my real program where I first observed this problem, and I was trying to reduce my test case to the minimum. If I had tried optimization and seen them removed, I would have expanded the test case. 3. The goal that I am working toward is to have gcc and ld work correctly for the -msplit option in pdp11-aout. For that case, instructions and data are stored in separate, overlapping 64KB address spaces, so even if a variable is const it can't go in the .text section. 4. I assumed that putting switch_to_section in the ASM_OUTPUT_ALIGNED_LOCAL function might not be legal since that is in the callback of a section so it might confuse the state of the caller. But if that is valid, then switching to bss_section is the right thing to do because pdp11-aout does have .bss. Emitting the variable in whatever section was currently active is clearly wrong. 5. Fixing the extra blank line for .globl is also good, but I was unsure why the code was as it is. Also I didn't figure out how there was a tab before .globl since it wasn't in the string constant. 6. I agree that verifying the generated assembly language is a sufficient check. But the way I run this code now is in emulation using SimH. 7. Emitting the zero-initialized variable into .data when it happens to follow a nonzero-initialized variable is also not correct, or at least suboptimal. If there is a vary large uninitialized array, that would make the final executable output file much larger. (OK, these days a full 64KB is still a pittance, but on principal it's suboptimal.) Therefore, switching to .bss in ASM_OUTPUT{_ALIGNED{,_DECL}_}_LOCAL is good. 8. When the variables are not static (hence 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. So I think we do need a TARGET_ASM_SELECT_SECTION function for the pdp11-aout target implemented by a pdp11_select_section function that looks at bss_initializer_p (decl) to choose between .data and .bss. Or does it need anything more of the logic like this from get_variable_section, or maybe define bss_noswitch_section to be bss_section if that makes sense? if (ADDR_SPACE_GENERIC_P (as) && !DECL_THREAD_LOCAL_P (decl) && !(prefer_noswitch_p && targetm.have_switchable_bss_sections) && bss_initializer_p (decl)) { if (!TREE_PUBLIC (decl) && !((flag_sanitize & SANITIZE_ADDRESS) && asan_protect_global (decl))) return lcomm_section; if (bss_noswitch_section) return bss_noswitch_section; }