[llvm] get Linux `-fvisibility=hidden` shared library build working with GCC (#151365) ## Purpose Add missing annotations so that LLVM can build as a shared library on Linux with `-fvisibility=hidden` using GCC. ## Overview Add a couple of annotations that make GCC happy: * Add `LLVM_TEMPLATE_ABI` to the `extern` declaration of `LoopBase<MachineBasicBlock, MachineLoop>`. The instantiation of this of this template is already properly annotated with `LLVM_EXPORT_TEMPLATE` and this declaration was missed. This omission did not cause problems with MSVC or Clang but results in undefined reference to the destructor with GCC. * Add `LLVM_ATTRIBUTE_VISIBILITY_DEFAULT` to the template declaration for `InnerAnalysisManagerProxy::Key`. `LLVM_ABI` cannot be used here because MSVC disallows storage-class specifiers on class members outside of the class declaration (C2720). Since `LLVM_ATTRIBUTE_VISIBILITY_DEFAULT` only applies to non-Windows targets, it can be used in its place. Omitting this annotation does not cause problems with Clang but results in undefined reference to `InnerAnalysisManagerProxy::Key` fields for for explicitly instantiated declarations when compiling with GCC. ## 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). ## Validation On Fedora 42, build with GCC `LLVM_BUILD_LLVM_DYLIB=ON`, `LLVM_BUILD_LLVM_DYLIB_VIS=ON`, and `LLVM_LINK_LLVM_DYLIB=ON`. ``` cmake -B build -S llvm -G Ninja -DLLVM_ENABLE_PROJECTS="llvm;clang;clang-tools-extra;lldb;lld" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_BUILD_TESTS=ON -DLLVM_BUILD_EXAMPLES=ON -DLLDB_ENABLE_PYTHON=NO -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB_VIS=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCLANG_LINK_CLANG_DYLIB=OFF -DCMAKE_BUILD_TYPE=Release ninja -C build ```
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.