https://gcc.gnu.org/g:e3290933ead698742f59e4abc4da694e73191203

commit r14-11503-ge3290933ead698742f59e4abc4da694e73191203
Author: Richard Biener <rguent...@suse.de>
Date:   Fri Feb 28 14:09:29 2025 +0100

    lto/91299 - weak definition inlined with LTO
    
    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.
    
    (cherry picked from commit bc34db5b12e008f6ec4fdf4ebd22263c8617e5e3)

Diff:
---
 gcc/lto/lto-symtab.cc                |  2 +-
 gcc/testsuite/gcc.dg/lto/pr91299_0.c | 16 ++++++++++++++++
 gcc/testsuite/gcc.dg/lto/pr91299_1.c |  6 ++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/lto/lto-symtab.cc b/gcc/lto/lto-symtab.cc
index a40218beac55..2e2eb4bd8148 100644
--- a/gcc/lto/lto-symtab.cc
+++ b/gcc/lto/lto-symtab.cc
@@ -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
index 000000000000..d9a8b21d6b84
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr91299_0.c
@@ -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
index 000000000000..29a28520f7b5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr91299_1.c
@@ -0,0 +1,6 @@
+/* { dg-options "-fno-lto" } */
+
+int get_t(void)
+{
+    return 1;
+}

Reply via email to