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

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 09:26:59 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;
----------------
minglotus-6 wrote:

> Dead store elimination pass may fold malloc + memset calls into a single call to calloc. If calloc is not preserved and is not being called directly it can be marked dead during thin link and result in link error.

Would this happen for other built-in libc calls? The current way of preserving it doesn't seem general enough as it handles `calloc` specially

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


More information about the llvm-commits mailing list