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.
node->analyzed = node->definition = false;
node->remove_all_references ();
}
+ node->body_removed = true;
}
DECL_EXTERNAL (node->decl) = 1;
}
--- /dev/null
+/* { dg-lto-do link } */
+/* { dg-lto-options {{-O2 -flto}} } */
+
+#define __weak __attribute__((__weak__))
+void __weak other() {}
+void __weak fn() {}
+
+int main() {
+ fn();
+ other();
+}
--- /dev/null
+/* { dg-options {{-fno-lto}} } */
+
+void fn() {}