https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92499
--- Comment #5 from sandra at gcc dot gnu.org --- Richard Sandiford complained that my patch to not put objects containing flexible arrays in small data was an ABI change for references across compilation units, so I've been taking another look at this to see if I can find a different solution. The thing that triggered the link error reported in GLIBC is that the nios2 back end generates uses gp-relative addressing for a locally declared object of such a type, but was inconsistently placing the (zero-initialized) object in .bss instead of .sbss. I spent some time in the debugger on this one -- the problem is that get_variable_section returns lcomm_section in this instance, without checking whether the object is "small", or deferring to the backend to choose a section. Eventually in the nios2 back end the ASM_OUTPUT_ALIGNED_LOCAL hook looks at the size to decide whether to emit the local in .sbss or .bss, but the size it has at that point is the size of the initializer, not the declared size of the type. Local objects with nonzero initializers are placed in .sdata and objects with external linkage are also placed in .sdata/.sbss consistently with the use of gp-relative addressing. The MIPS back end has the same issue; it puts the zero-initialized local object in .comm, while the other cases end up in .sdata/.sbss. I also observed that the MIPS backend is emitting an incorrect .size directive (using the size of the non-flexible part of the object instead of the size of the initializer) for the cases it does put in .sdata/.sbss. I don't know if that is actually used by the assembler in a way that is harmful, though. So I think we could fix this without changing the ABI by fixing get_variable_section not to short-circuit the criteria the rest of the compiler uses to decide whether an object belongs in a small data section. That could optionally be combined with target-specific changes not to consider flexibly-sized objects with internal linkage not to be "small" for the purposes of either section placement or gp-relative addressing.