At least two ports (hppa and loongarch) need to set SECTION_RELRO for
.data.rel.ro{,.local} in section_type_flags (PR52999 and PR116887), and
I cannot see a reason not to just set it in the generic code.
With this applied we can also remove the hppa-specific
pa_section_type_flags in a future patch.
gcc/ChangeLog:
PR target/116887
* varasm.cc (default_section_type_flags): Always set
SECTION_RELRO if name is .data.rel.ro{,.local}.
gcc/testsuite/ChangeLog:
PR target/116887
* gcc.dg/pr116887.c: New test.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fpic" } */
+
+struct link_map
+{
+ struct link_map *l_next;
+};
+struct rtld_global
+{
+ struct link_map *_ns_loaded;
+ char buf[4096];
+ struct link_map _dl_rtld_map;
+};
+extern struct rtld_global _rtld_global;
+static int _dlfo_main __attribute__ ((section (".data.rel.ro"), used));
+void
+_dlfo_process_initial (int ns)
+{
+ for (struct link_map *l = _rtld_global._ns_loaded; l != ((void *)0);
+ l = l->l_next)
+ if (l == &_rtld_global._dl_rtld_map)
+ asm ("");
+}
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
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;