[lld] [LLD][ELF] Don't instantiate ObjFile function but rather import it (PR #68025)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 12:54:10 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

<details>
<summary>Changes</summary>

Before this patch, with MSVC I was seeing the following warnings:
```
[304/334] Building CXX object tools\lld\ELF\CMakeFiles\lldELF.dir\InputFiles.cpp.obj
C:\git\llvm-project\lld\ELF\InputFiles.h(327): warning C4661: 'void lld::elf::ObjFile<llvm::object::ELF32LE>::importCmseSymbols(void)': no suitable definition provided for explicit template instantiation request
C:\git\llvm-project\lld\ELF\InputFiles.h(291): note: see declaration of 'lld::elf::ObjFile<llvm::object::ELF32LE>::importCmseSymbols'
C:\git\llvm-project\lld\ELF\InputFiles.h(327): warning C4661: 'void lld::elf::ObjFile<llvm::object::ELF32LE>::redirectCmseSymbols(void)': no suitable definition provided for explicit template instantiation request
C:\git\llvm-project\lld\ELF\InputFiles.h(292): note: see declaration of 'lld::elf::ObjFile<llvm::object::ELF32LE>::redirectCmseSymbols'
```

This patch removes `redirectCmseSymbols` which is not defined. And it imports `importCmseSymbols` in InputFiles.cpp, because it is already explicitly instantiated in ARM.cpp.

---
Full diff: https://github.com/llvm/llvm-project/pull/68025.diff


2 Files Affected:

- (modified) lld/ELF/InputFiles.cpp (+7) 
- (modified) lld/ELF/InputFiles.h (-1) 


``````````diff
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index fa0731854689b94..bb86269d49499cd 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -40,6 +40,13 @@ using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::elf;
 
+// This function is explicity instantiated in ARM.cpp, don't do it here to avoid
+// warnings with MSVC.
+extern template void ObjFile<ELF32LE>::importCmseSymbols();
+extern template void ObjFile<ELF32BE>::importCmseSymbols();
+extern template void ObjFile<ELF64LE>::importCmseSymbols();
+extern template void ObjFile<ELF64BE>::importCmseSymbols();
+
 bool InputFile::isInGroup;
 uint32_t InputFile::nextGroupId;
 
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index cc658bdc231988e..41c2ba4e307b36b 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -289,7 +289,6 @@ template <class ELFT> class ObjFile : public ELFFileBase {
   void initSectionsAndLocalSyms(bool ignoreComdats);
   void postParse();
   void importCmseSymbols();
-  void redirectCmseSymbols();
 
 private:
   void initializeSections(bool ignoreComdats,

``````````

</details>


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


More information about the llvm-commits mailing list