]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Always set SECTION_RELRO for or .data.rel.ro{,.local} [PR116887]
authorXi Ruoyao <xry111@xry111.site>
Thu, 10 Oct 2024 18:44:27 +0000 (02:44 +0800)
committerXi Ruoyao <xry111@xry111.site>
Fri, 1 Nov 2024 17:19:51 +0000 (01:19 +0800)
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.

gcc/testsuite/gcc.dg/pr116887.c [new file with mode: 0644]
gcc/varasm.cc

diff --git a/gcc/testsuite/gcc.dg/pr116887.c b/gcc/testsuite/gcc.dg/pr116887.c
new file mode 100644 (file)
index 0000000..b7255e0
--- /dev/null
@@ -0,0 +1,23 @@
+/* { 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 ("");
+}
index deefbac5b7b218a8ef8f7647db8df51f463140d1..0712b4860294362f54b7c4cb8b6dc5f4175ef356 100644 (file)
@@ -6884,6 +6884,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
@@ -6897,12 +6900,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;