https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116887
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=47610
--- Comment #22 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(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.
In PR47610 fix (r169855) SECTION_RELRO is (intentionally??) only applied for
decl == NULL.
So should we just extend it to cover decl != NULL, i.e. something like
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -6863,6 +6863,9 @@ default_section_type_flags (tree decl, const char *name,
int reloc)
if (decl && TREE_CODE (decl) == FUNCTION_DECL)
flags = SECTION_CODE;
+ else if (strcmp (name, ".data.rel.ro") == 0
+ || strcmp (name, ".data.rel.ro.local") == 0)
+ flags = SECTION_WRITE | SECTION_RELRO;
else if (decl)
{
enum section_category category
@@ -6876,12 +6879,7 @@ default_section_type_flags (tree decl, const char *name,
int reloc)
flags = SECTION_WRITE;
}
else
- {
- flags = SECTION_WRITE;
- if (strcmp (name, ".data.rel.ro") == 0
- || strcmp (name, ".data.rel.ro.local") == 0)
- flags |= SECTION_RELRO;
- }
+ flags = SECTION_WRITE;
if (decl && DECL_P (decl) && DECL_COMDAT_GROUP (decl))
flags |= SECTION_LINKONCE;
???