From ecbe2e8c3f8f4be87d5d30ad5d1fcc1986fa5c47 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Wed, 4 Jun 2025 10:28:58 -0700 Subject: [llvm] annotate interfaces in llvm/ObjCopy and llvm/Object for DLL export (#142668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/ObjCopy` and `llvm/Object` libraries. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS on Linux: - Add `#include "llvm/Support/Compiler.h"` to files where it was not auto-added by IDS due to no pre-existing block of include statements. - Manually annotate template class `CommonArchiveMemberHeader` with `LLVM_ABI` since IDS ignores templates and this is the simplest solution for DLL-exporting its child classes because it has methods defined out-of-line. Seems to be an uncommon situation. - Explicitly make `Archive` class non-copyable due to the class-level `LLVM_ABI` annotation. - Add default constructor to `ELFFile` so it can be instantiated for DLL-export as a base class. - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang --- llvm/lib/Object/XCOFFObjectFile.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp index 5a24643..c5a2ec2 100644 --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -93,8 +93,8 @@ uint8_t XCOFFRelocation::getRelocatedLength() const { return (Info & XR_BIASED_LENGTH_MASK) + 1; } -template struct ExceptionSectionEntry; -template struct ExceptionSectionEntry; +template struct LLVM_EXPORT_TEMPLATE ExceptionSectionEntry; +template struct LLVM_EXPORT_TEMPLATE ExceptionSectionEntry; template Expected getLoaderSecSymNameInStrTbl(const T *LoaderSecHeader, @@ -1375,11 +1375,11 @@ Expected XCOFFSymbolRef::getName() const { } // Explicitly instantiate template classes. -template struct XCOFFSectionHeader; -template struct XCOFFSectionHeader; +template struct LLVM_EXPORT_TEMPLATE XCOFFSectionHeader; +template struct LLVM_EXPORT_TEMPLATE XCOFFSectionHeader; -template struct XCOFFRelocation; -template struct XCOFFRelocation; +template struct LLVM_EXPORT_TEMPLATE XCOFFRelocation; +template struct LLVM_EXPORT_TEMPLATE XCOFFRelocation; template LLVM_EXPORT_TEMPLATE llvm::Expected> -- cgit v1.1