[llvm] 92da37b - [Object][NFC] Add extern template declarations needed by llvm-objdump (#109156)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 19 23:50:48 PDT 2024


Author: Thomas Fransham
Date: 2024-09-20T09:50:45+03:00
New Revision: 92da37b08f95844576c5d5502712bab0961e2f27

URL: https://github.com/llvm/llvm-project/commit/92da37b08f95844576c5d5502712bab0961e2f27
DIFF: https://github.com/llvm/llvm-project/commit/92da37b08f95844576c5d5502712bab0961e2f27.diff

LOG: [Object][NFC] Add extern template declarations needed by llvm-objdump (#109156)

These symbols are implicitly imported from the LLVM shared library by
llvm-objdump on ELF like platforms, but for windows they need to be
explicitly exported when LLVM is built as shared library.
I also add visibility macros for XCOFFObjectFile::getExceptionEntries
that can't automatically be added by clang tooling since it doesn't
store the source locations for explicit function template
instantiations.

Added: 
    

Modified: 
    llvm/include/llvm/Object/ELF.h
    llvm/include/llvm/Object/XCOFFObjectFile.h
    llvm/lib/Object/ELF.cpp
    llvm/lib/Object/XCOFFObjectFile.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index 8a363741ee6287..6aff1e62276b03 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -21,6 +21,7 @@
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Object/ELFTypes.h"
 #include "llvm/Object/Error.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataExtractor.h"
 #include "llvm/Support/Error.h"
 #include <cassert>
@@ -1367,6 +1368,11 @@ inline uint32_t hashGnu(StringRef Name) {
   return H;
 }
 
+extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF32LE>;
+extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF32BE>;
+extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF64LE>;
+extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF64BE>;
+
 } // end namespace object
 } // end namespace llvm
 

diff  --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h
index 5a7cd8e38f2b76..ec48843cd5320b 100644
--- a/llvm/include/llvm/Object/XCOFFObjectFile.h
+++ b/llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/BinaryFormat/XCOFF.h"
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Endian.h"
 #include <limits>
 
@@ -775,6 +776,13 @@ struct XCOFFSymbolEntry64 {
   uint8_t NumberOfAuxEntries;
 };
 
+extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<XCOFFRelocation32>>
+XCOFFObjectFile::relocations<XCOFFSectionHeader32, XCOFFRelocation32>(
+    const XCOFFSectionHeader32 &Sec) const;
+extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<XCOFFRelocation64>>
+XCOFFObjectFile::relocations<XCOFFSectionHeader64, XCOFFRelocation64>(
+    const XCOFFSectionHeader64 &Sec) const;
+
 class XCOFFSymbolRef : public SymbolRef {
 public:
   enum { NAME_IN_STR_TBL_MAGIC = 0x0 };

diff  --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index c66736fb2c9194..9a9e762d1e51d6 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -9,6 +9,7 @@
 #include "llvm/Object/ELF.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/BinaryFormat/ELF.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataExtractor.h"
 
 using namespace llvm;
@@ -980,7 +981,7 @@ ELFFile<ELFT>::getSectionAndRelocations(
   return SecToRelocMap;
 }
 
-template class llvm::object::ELFFile<ELF32LE>;
-template class llvm::object::ELFFile<ELF32BE>;
-template class llvm::object::ELFFile<ELF64LE>;
-template class llvm::object::ELFFile<ELF64BE>;
+template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF32LE>;
+template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF32BE>;
+template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF64LE>;
+template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF64BE>;

diff  --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index 6efb8759d13fbd..cc0da5db524256 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Object/XCOFFObjectFile.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataExtractor.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include <cstddef>
@@ -1060,9 +1061,9 @@ Expected<ArrayRef<ExceptEnt>> XCOFFObjectFile::getExceptionEntries() const {
       ExceptEntStart, ExceptEntStart + getSectionSize(DRI) / sizeof(ExceptEnt));
 }
 
-template Expected<ArrayRef<ExceptionSectionEntry32>>
+template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<ExceptionSectionEntry32>>
 XCOFFObjectFile::getExceptionEntries() const;
-template Expected<ArrayRef<ExceptionSectionEntry64>>
+template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<ExceptionSectionEntry64>>
 XCOFFObjectFile::getExceptionEntries() const;
 
 Expected<XCOFFStringTable>
@@ -1376,14 +1377,16 @@ template struct XCOFFSectionHeader<XCOFFSectionHeader64>;
 template struct XCOFFRelocation<llvm::support::ubig32_t>;
 template struct XCOFFRelocation<llvm::support::ubig64_t>;
 
-template llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation64>>
-llvm::object::XCOFFObjectFile::relocations<llvm::object::XCOFFSectionHeader64,
-                                           llvm::object::XCOFFRelocation64>(
-    llvm::object::XCOFFSectionHeader64 const &) const;
-template llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation32>>
-llvm::object::XCOFFObjectFile::relocations<llvm::object::XCOFFSectionHeader32,
-                                           llvm::object::XCOFFRelocation32>(
-    llvm::object::XCOFFSectionHeader32 const &) const;
+template LLVM_EXPORT_TEMPLATE
+    llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation64>>
+    llvm::object::XCOFFObjectFile::relocations<
+        llvm::object::XCOFFSectionHeader64, llvm::object::XCOFFRelocation64>(
+        llvm::object::XCOFFSectionHeader64 const &) const;
+template LLVM_EXPORT_TEMPLATE
+    llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation32>>
+    llvm::object::XCOFFObjectFile::relocations<
+        llvm::object::XCOFFSectionHeader32, llvm::object::XCOFFRelocation32>(
+        llvm::object::XCOFFSectionHeader32 const &) const;
 
 bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes) {
   if (Bytes.size() < 4)


        


More information about the llvm-commits mailing list