[PATCH] D104230: [gold] Release input files in claim_file

Timm Bäder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 14 08:09:40 PDT 2021


tbaeder created this revision.
tbaeder added a reviewer: tstellar.
tbaeder requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The linker might create several fds per file here and they are not being
closed with ld.bfd. This breaks the build when using clang+ld.bfd to
e.g. link libLLVM.so with LTO.

      

Gold does not seem to have this problem, but it does not break with this
patch either.

I've also tested this always enabled (not only when thinlto is disabled), and it seemed to work as well.
But the code talks about parallel thinlto backends, so I'm not sure if I've tested all relevant cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104230

Files:
  llvm/tools/gold/gold-plugin.cpp


Index: llvm/tools/gold/gold-plugin.cpp
===================================================================
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -556,6 +556,14 @@
     return *claimed ? LDPS_ERR : LDPS_OK;
   }
 
+  if (!options::thinlto) {
+    // Close the fd now. The linker opens it specifically for this claim_file
+    // call and doesn't close it.
+    // When thinlto is enabled, we need to keep it open but we can still close it
+    // when thinlto is disabled.
+    release_input_file(file->handle);
+  }
+
   std::unique_ptr<InputFile> Obj = std::move(*ObjOrErr);
 
   Modules.emplace_back();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104230.351878.patch
Type: text/x-patch
Size: 642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210614/fd93dbe4/attachment.bin>


More information about the llvm-commits mailing list