Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Object][NFC] Add extern template declarations needed by llvm-objdump #109156

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

fsfod
Copy link
Contributor

@fsfod fsfod commented Sep 18, 2024

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.

@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Thomas Fransham (fsfod)

Changes

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.


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

2 Files Affected:

  • (modified) llvm/include/llvm/Object/XCOFFObjectFile.h (+8)
  • (modified) llvm/lib/Object/XCOFFObjectFile.cpp (+13-10)
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/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)

These symbols are implicitly imported from the LLVM shared library by
llvm-objdump, but for windows they need to be explicitly exported when LLVM is
built as shared library.
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.
@fsfod fsfod force-pushed the exported-api/xcoff-extern-template branch from 248db71 to c12c02a Compare September 18, 2024 15:55
@fsfod fsfod changed the title [XCOFF][NFC] Add extern template declarations needed by llvm-objdump [Object][NFC] Add extern template declarations needed by llvm-objdump Sep 18, 2024
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically homes a canonical copy of the template types rather than relying on the ODR based emission.

@vgvassilev vgvassilev merged commit 92da37b into llvm:main Sep 20, 2024
8 checks passed
@fsfod fsfod deleted the exported-api/xcoff-extern-template branch September 20, 2024 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants