[llvm] 83dc473 - Fix -fsplit-lto-unit with ifuncs

Daniel Kiss via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 07:36:19 PDT 2023


Author: Daniel Kiss
Date: 2023-03-21T15:36:13+01:00
New Revision: 83dc4734ba69da95d8c879bb174a1169b3f9e0b8

URL: https://github.com/llvm/llvm-project/commit/83dc4734ba69da95d8c879bb174a1169b3f9e0b8
DIFF: https://github.com/llvm/llvm-project/commit/83dc4734ba69da95d8c879bb174a1169b3f9e0b8.diff

LOG: Fix -fsplit-lto-unit with ifuncs

ifuncs can't take part of the whole-program devirtualization so no need them to be copied to the merged module.
The corresponding resolver function also kept out which caused the crash.

Fixes #60962 #57870

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D144982

Added: 
    llvm/test/ThinLTO/X86/ifunc_splitlto.ll

Modified: 
    llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 6700970100859..d3384c86c390f 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -196,6 +196,13 @@ void simplifyExternals(Module &M) {
     F.eraseFromParent();
   }
 
+  for (GlobalIFunc &I : llvm::make_early_inc_range(M.ifuncs())) {
+    if (I.use_empty())
+      I.eraseFromParent();
+    else
+      assert(I.getResolverFunction() && "ifunc misses its resolver function");
+  }
+
   for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
     if (GV.isDeclaration() && GV.use_empty()) {
       GV.eraseFromParent();

diff  --git a/llvm/test/ThinLTO/X86/ifunc_splitlto.ll b/llvm/test/ThinLTO/X86/ifunc_splitlto.ll
new file mode 100644
index 0000000000000..360eaa10086b2
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/ifunc_splitlto.ll
@@ -0,0 +1,31 @@
+; regresstion test for https://github.com/llvm/llvm-project/issues/60962
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
+; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
+; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at i = ifunc ptr (ptr, i64), ptr @hoge
+
+ at g = constant i8 1, !type !0
+ at assoc = private constant i8 2, !associated !1
+
+define ptr @hoge() !type !2 {
+bb:
+  ret ptr null
+}
+
+; M0: @g = external constant
+; M0: @i = ifunc ptr (ptr, i64), ptr @hoge
+; M0: define ptr @hoge()
+; M0-NOT: @assoc
+; M1: @g = constant i8 1
+; M1: @assoc = private constant i8 2
+; M1-NOT: @i = ifunc ptr (ptr, i64), ptr @hoge
+; M1-NOT: define ptr @hoge()
+
+!0 = !{i32 0, !"typeid"}
+!1 = !{ptr @g}
+!2 = !{i64 0, !3}
+!3 = distinct !{}


        


More information about the llvm-commits mailing list