On Fri, Apr 29, 2022 at 01:52:49PM +0200, Ilya Leoshkevich wrote: > > This doesn't resolve the problem, unfortunately, because > > references to discarded comdat symbols are still kept in .rodata: > > > > `.text._ZN7testing15AssertionResultlsIPKcEERS0_RKT_' referenced in > > section `.rodata' of ../lib/libgtest.a(gtest-all.cc.o): defined in > > discarded section > > `.text._ZN7testing15AssertionResultlsIPKcEERS0_RKT_[_ZN7testing15Asse > > rt > > ionResultlsIPKcEERS0_RKT_]' of ../lib/libgtest.a(gtest-all.cc.o) > > > > (That's from building zlib-ng with ASan and your patch on s390). > > > > So I was rather thinking about adding a reloc parameter to > > mergeable_constant_section () and slightly changing the section > > name when it's nonzero, e.g. from .cst to .cstrel. > > After some experimenting, I don't think that what I propose here > is a good solution anymore, since it won't work with > -fno-merge-constants. > > What do you think about something like this? > > --- a/gcc/varasm.cc > +++ b/gcc/varasm.cc > @@ -7326,6 +7326,10 @@ default_elf_select_rtx_section (machine_mode > mode, rtx x, > return get_named_section (NULL, ".data.rel.ro", 3); > } > > + if (reloc) > + return targetm.asm_out.function_rodata_section > (current_function_decl, > + false); > + > return mergeable_constant_section (mode, align, 0); > } > > This would put constants with relocations into .rodata.<FUNC>. > default_function_rodata_section () already ensures that these sections > are in the right comdat group.
We don't really know if the emitted constant is purely for the current function, or also other functions (say emitted in as constant pool constant where constant pool constants are shared across the whole TU). For the former, putting it into current function's comdat is fine, for the latter certainly isn't. Jakub