]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lto/91299 - weak definition inlined with LTO
authorRichard Biener <rguenther@suse.de>
Fri, 28 Feb 2025 13:09:29 +0000 (14:09 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 28 Feb 2025 14:18:07 +0000 (15:18 +0100)
The following fixes a thinko in the handling of interposed weak
definitions which confused the interposition check in
get_availability by setting DECL_EXTERNAL too early.

PR lto/91299
gcc/lto/
* lto-symtab.cc (lto_symtab_merge_symbols): Set DECL_EXTERNAL
only after calling get_availability.

gcc/testsuite/
* gcc.dg/lto/pr91299_0.c: New testcase.
* gcc.dg/lto/pr91299_1.c: Likewise.

gcc/lto/lto-symtab.cc
gcc/testsuite/gcc.dg/lto/pr91299_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr91299_1.c [new file with mode: 0644]

index bc3c144e4441ccd8f1bd8877375e89193fd2d460..66674a4415f84cc7d3e68ea18d9300062c614d36 100644 (file)
@@ -1016,7 +1016,6 @@ lto_symtab_merge_symbols (void)
                  || node->resolution == LDPR_RESOLVED_EXEC
                  || node->resolution == LDPR_RESOLVED_DYN))
            {
-             DECL_EXTERNAL (node->decl) = 1;
              /* If alias to local symbol was preempted by external definition,
                 we know it is not pointing to the local symbol.  Remove it.  */
              if (node->alias
@@ -1042,6 +1041,7 @@ lto_symtab_merge_symbols (void)
                      node->remove_all_references ();
                    }
                }
+             DECL_EXTERNAL (node->decl) = 1;
            }
 
          if (!(cnode = dyn_cast <cgraph_node *> (node))
diff --git a/gcc/testsuite/gcc.dg/lto/pr91299_0.c b/gcc/testsuite/gcc.dg/lto/pr91299_0.c
new file mode 100644 (file)
index 0000000..d9a8b21
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O2 -flto } } } */
+
+__attribute__((weak)) int get_t(void)
+{
+  return 0;
+}
+
+int a;
+int main(void)
+{
+  a = get_t();
+  if (a != 1)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr91299_1.c b/gcc/testsuite/gcc.dg/lto/pr91299_1.c
new file mode 100644 (file)
index 0000000..29a2852
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-options "-fno-lto" } */
+
+int get_t(void)
+{
+    return 1;
+}