]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lto: Fix SegFault in ICF caused by missing body
authorMichal Jires <mjires@suse.cz>
Fri, 19 Dec 2025 16:09:16 +0000 (17:09 +0100)
committerMichal Jires <mjires@suse.cz>
Sun, 11 Jan 2026 21:48:55 +0000 (22:48 +0100)
During LTO symbol merging, weak symbols may be resolved to external
definition.
We reset the symbol, so the body might be released in unreachability
pass. But we didn't mark the symbol with body_removed, so ICF assumed
the body was still there causing SegFault.

gcc/lto/ChangeLog:

* lto-symtab.cc (lto_symtab_merge_symbols): Set body_removed
for symbols resolved outside of IR.

gcc/testsuite/ChangeLog:

* gcc.dg/lto/attr-weakref-2_0.c: New test.
* gcc.dg/lto/attr-weakref-2_1.c: New test.

gcc/lto/lto-symtab.cc
gcc/testsuite/gcc.dg/lto/attr-weakref-2_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/attr-weakref-2_1.c [new file with mode: 0644]

index b8759a7fef5511cf6760cb42a5ae2e331eb14f36..b458462dc2376479e8a5deaf8ee1c40084039029 100644 (file)
@@ -1043,6 +1043,7 @@ lto_symtab_merge_symbols (void)
                      node->analyzed = node->definition = false;
                      node->remove_all_references ();
                    }
+                 node->body_removed = true;
                }
              DECL_EXTERNAL (node->decl) = 1;
            }
diff --git a/gcc/testsuite/gcc.dg/lto/attr-weakref-2_0.c b/gcc/testsuite/gcc.dg/lto/attr-weakref-2_0.c
new file mode 100644 (file)
index 0000000..a55ef28
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-lto-do link } */
+/* { dg-lto-options {{-O2 -flto}} } */
+
+#define __weak __attribute__((__weak__))
+void __weak other() {}
+void __weak fn() {}
+
+int main() {
+  fn();
+  other();
+}
diff --git a/gcc/testsuite/gcc.dg/lto/attr-weakref-2_1.c b/gcc/testsuite/gcc.dg/lto/attr-weakref-2_1.c
new file mode 100644 (file)
index 0000000..639093f
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-options {{-fno-lto}} } */
+
+void fn() {}