forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 344
[llvm] support Windows DLL build of LLVM #11117
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
Open
andrurogerz
wants to merge
6
commits into
swiftlang:stable/21.x
Choose a base branch
from
andrurogerz:swiftlang/stable/21.x
base: stable/21.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[llvm] support Windows DLL build of LLVM #11117
andrurogerz
wants to merge
6
commits into
swiftlang:stable/21.x
from
andrurogerz:swiftlang/stable/21.x
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@compnerd this PR contains the 6 commits missing to get the LLVM Windows DLL build working on |
@swift-ci please test |
## Purpose This PR is a re-application of llvm#145575 with independent definition of `ABI_BREAKING_EXPORT_ABI` that does not depend on `llvm/Support/Compiler.h`. It is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the ABI Breaking Checks interface in llvm/config. The 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 The effort to build LLVM as a Windows DLL is tracked in llvm#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). ## 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
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `Demangle` interface with a new `DEMANGLE_ABI` annotation, which behaves like the `LLVM_ABI`. This annotation currently has no meaningful impact on the LLVM build; however, it is a prerequisite to support an LLVM Windows DLL (shared library) build. ## Overview 1. Add a new `Demangle/Visibility.h` header file that defines a new `DEMANGLE_ABI` macro. The macro resolves to the proper DLL export/import annotation on Windows and a "default" visibility annotation elsewhere. 2. Add a new `LLVM_ENABLE_DEMANGLE_EXPORT_ANNOTATIONS ` `#cmakedefine` that is used to gate the definition of `DEMANGLE_ABI`. 3. Code-mod annotate the public `Demangle` interface using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool. 4. Manually fix-up `#include` statements for consistency. 5. Format the changes with `clang-format`. 6. Add a "stub" version of `Visibility.h` under `libcxxabi/src/demangle` that always defines `DEMANGLE_ABI` to nothing. 7. Update the canonical `libcxxabi/src/demangle/ItaniumDemangle.h` instead of the llvm copy, and run `cp-to-llvm.sh` to ensure the llvm copy matches. NOTE: we rely on `ccp-to-llvm.sh` not copying `Visibillity.h` as is already the case for `DemangleConfig.h`. ## Background This PR follows the pattern established with the `llvm-c` changes made in llvm#141701. This effort is tracked in llvm#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). ## 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 --------- Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
…47810) ## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm::cl::opt` explicit template instantiations for export with `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE`. This annotation currently has no meaningful impact on the LLVM build; however, it is a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in llvm#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). Annotating the `llvm::cl::opt` template instances for DLL export was not straight-forward like other explicit template instances that have already been annotated. Annotating them as documented [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst#templates) results in link errors when building a Windows DLL using MSVC. ## Overview There are two specific issues that appear when exporting the `llvm::cl::opt` templates and compiling a Windows DLL with MSVC: 1. We cannot export `opt<std::string>`. This is because MSVC exports all ancestor classes when exporting an instantiated template class. Since one of `opt`'s ancestor classes is its type argument (via `opt_storage`), it is an ancestor of `std::string`. Therefore, if we export `opt<std::string>` from the LLVM DLL, MSVC forces `std::basic_string` to also be exported. This leads to duplicate symbol errors and generally seems like a bad idea. Compiling with `clang-cl` does not exhibit this behavior. 2. The `opt` template instances other than `opt<bool>` get optimized out because they are not referenced in the TU (`opt<bool>` actually is). It is unclear exactly why MSVC optimizes these template instances away, but `clang-cl` does not. Adding explicit references to the instantiated `opt` template classes' vtables via implicit virtual destructor forces MSVC to export them. ## Validation Windows with MSVC Windows with Clang
## Overview Include `llvm-config.h` from `DemangleConfig.h` so `LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS` is defined correctly. The presence of this definition controls the definition of `LLVM_ABI` on Windows DLL builds. This include was missed in llvm#147564. ## Background This effort is tracked in llvm#109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307).
…limport This fixes a typo from 04f5198, fixing building for mingw targets with dylib enabled.
This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates symbols that were recently added to LLVM without proper annotations. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. This effort is tracked in llvm#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: - Add `LLVM_EXPORT_TEMPLATE` and `LLVM_TEMPLATE_ABI` annotations to explicitly instantiated instances of `llvm::object::SFrameParser`. 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
bf4f85e
to
32ffe48
Compare
@swift-ci please test |
@swift-ci please test llvm |
@swift-ci please test Windows |
Baseline run has the same LLVM test failures: #7334. |
@swift-ci please test macOS |
@swift-ci please test Linux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Cherry-pick missing changes from
llvm/main
that at required to build LLVM as a Windows DLL:9bd2aac
33f4582
7162f19
0489222
04f5198
11d97b3
Validation
On WIndows 11: