[llvm] [ThinLTO] Don't mark calloc function dead (PR #72673)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 09:32:53 PST 2023


================
@@ -644,7 +646,11 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
     // FIXME: instead of this check, it would be desirable to compute GUIDs
     // based on mangled name, but this requires an access to the Target Triple
     // and would be relatively invasive on the codebase.
-    if (GlobalRes.IRName != Sym.getIRName()) {
+    if ((GlobalRes.IRName != Sym.getIRName()) ||
+        // The dead store elimination pass can fold malloc + memset calls into
+        // a single call to calloc. Prevent thin LTO from marking calloc a dead
+        // function otherwise we may face link errors.
+        (!CallocName.empty() && GlobalRes.IRName == CallocName)) {
       GlobalRes.Partition = GlobalResolution::External;
----------------
eleviant wrote:

The problem with calloc is that two libcalls are being folded into third libcall. When using thin LTO we can import function calling malloc (new operator) from one TU and later fold malloc followed by memset into calloc. I don't know about other related problems (there might be).



https://github.com/llvm/llvm-project/pull/72673


More information about the llvm-commits mailing list