https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116887
--- Comment #21 from Florian Weimer <fw at gcc dot gnu.org> --- (In reply to chenglulu from comment #20) > (In reply to Florian Weimer from comment #18) > > (In reply to chenglulu from comment #17) > > > I don't think it can be completely avoided. But I don't understand why the > > > public code does not set the SECTION_RELRO flag when putting decl into > > > ".data.rel.ro" via __attribute__. > > > > I'm not aware of a way to set the RELRO flag directly. We want to write to > > these variables during initialization, so we cannot make them const. I > > assume we could move the definition into a separate TU and only have the > > section attribute on a definition. This would then rely on more relaxed > > section merging in the linker. The particular instance that triggered this > > bug report would be fairly straightforward to fix, but doing this for e.g. > > _rtld_global_ro is more difficult. > > Um, sorry. I don't quite understand the difference between _rtld_global_ro > and __dlfo_main in this regard. The definition of _rtld_global_ro with its initializer might not be as easily moved to a separate file from any accesses. There's even an architecture-dependent #include <dl-procruntime.c> right in the middle. So I'd rather see proper GCC support for mixing RELRO definitions and code access, whatever that means.