[lld] [llvm] [LLD] [COFF] Fix linking import libraries with -wholearchive: (PR #122806)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 02:29:18 PST 2025


================
@@ -746,6 +746,26 @@ std::optional<Symbol *> ObjFile::createDefined(
   if (sectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
     return nullptr;
 
+  if (sym.isEmptySectionDeclaration()) {
+    // As there is no coff_section in the object file for these, make a
+    // new virtual one, with everything zeroed out (i.e. an empty section),
+    // with only the name and characteristics set.
+    StringRef name = getName();
+    auto *hdr = make<coff_section>();
+    memset(hdr, 0, sizeof(*hdr));
+    strncpy(hdr->Name, name.data(),
+            std::min(name.size(), (size_t)COFF::NameSize));
+    // We have no idea what characteristics should be assumed here; pick
+    // a default. This matches what is used for .idata sections in the regular
+    // object files in import libraries.
+    hdr->Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
+                           IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_4BYTES;
+    auto *sc = make<SectionChunk>(this, hdr);
+    chunks.push_back(sc);
+    return make<DefinedRegular>(this, /*Name*/ "", /*IsCOMDAT*/ false,
----------------
cjacek wrote:

That's `/*Name=*/""` according to https://llvm.org/docs/CodingStandards.html#comment-formatting

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


More information about the llvm-commits mailing list