Skip to content

Commit 1a43552

Browse files
authored
[llvm] annotate interfaces in llvm/LTO for DLL export (llvm#142499)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/LTO` library. 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 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 on Linux: - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers ## 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
1 parent 9788521 commit 1a43552

File tree

13 files changed

+221
-194
lines changed

13 files changed

+221
-194
lines changed

llvm/include/llvm/InterfaceStub/ELFObjHandler.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_INTERFACESTUB_ELFOBJHANDLER_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/Error.h"
1819
#include "llvm/Support/MemoryBufferRef.h"
1920
#include <memory>
@@ -24,7 +25,7 @@ namespace ifs {
2425
struct IFSStub;
2526

2627
/// Attempt to read a binary ELF file from a MemoryBuffer.
27-
Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
28+
LLVM_ABI Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
2829

2930
/// Attempt to write a binary ELF stub.
3031
/// This function determines appropriate ELFType using the passed ELFTarget and
@@ -34,8 +35,8 @@ Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
3435
/// @param Stub Source ELFStub to generate a binary ELF stub from.
3536
/// @param WriteIfChanged Whether or not to preserve timestamp if
3637
/// the output stays the same.
37-
Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub,
38-
bool WriteIfChanged = false);
38+
LLVM_ABI Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub,
39+
bool WriteIfChanged = false);
3940

4041
} // end namespace ifs
4142
} // end namespace llvm

llvm/include/llvm/InterfaceStub/IFSHandler.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define LLVM_INTERFACESTUB_IFSHANDLER_H
1717

1818
#include "IFSStub.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Support/Error.h"
2021
#include "llvm/Support/VersionTuple.h"
2122
#include <memory>
@@ -36,29 +37,30 @@ struct IFSStub;
3637
const VersionTuple IFSVersionCurrent(3, 0);
3738

3839
/// Attempts to read an IFS interface file from a StringRef buffer.
39-
Expected<std::unique_ptr<IFSStub>> readIFSFromBuffer(StringRef Buf);
40+
LLVM_ABI Expected<std::unique_ptr<IFSStub>> readIFSFromBuffer(StringRef Buf);
4041

4142
/// Attempts to write an IFS interface file to a raw_ostream.
42-
Error writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub);
43+
LLVM_ABI Error writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub);
4344

4445
/// Override the target platform inforation in the text stub.
45-
Error overrideIFSTarget(IFSStub &Stub, std::optional<IFSArch> OverrideArch,
46-
std::optional<IFSEndiannessType> OverrideEndianness,
47-
std::optional<IFSBitWidthType> OverrideBitWidth,
48-
std::optional<std::string> OverrideTriple);
46+
LLVM_ABI Error
47+
overrideIFSTarget(IFSStub &Stub, std::optional<IFSArch> OverrideArch,
48+
std::optional<IFSEndiannessType> OverrideEndianness,
49+
std::optional<IFSBitWidthType> OverrideBitWidth,
50+
std::optional<std::string> OverrideTriple);
4951

5052
/// Validate the target platform inforation in the text stub.
51-
Error validateIFSTarget(IFSStub &Stub, bool ParseTriple);
53+
LLVM_ABI Error validateIFSTarget(IFSStub &Stub, bool ParseTriple);
5254

5355
/// Strips target platform information from the text stub.
54-
void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
55-
bool StripEndianness, bool StripBitWidth);
56+
LLVM_ABI void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
57+
bool StripEndianness, bool StripBitWidth);
5658

57-
Error filterIFSSyms(IFSStub &Stub, bool StripUndefined,
58-
const std::vector<std::string> &Exclude = {});
59+
LLVM_ABI Error filterIFSSyms(IFSStub &Stub, bool StripUndefined,
60+
const std::vector<std::string> &Exclude = {});
5961

6062
/// Parse llvm triple string into a IFSTarget struct.
61-
IFSTarget parseTriple(StringRef TripleStr);
63+
LLVM_ABI IFSTarget parseTriple(StringRef TripleStr);
6264

6365
} // end namespace ifs
6466
} // end namespace llvm

llvm/include/llvm/InterfaceStub/IFSStub.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_INTERFACESTUB_IFSSTUB_H
1515
#define LLVM_INTERFACESTUB_IFSSTUB_H
1616

17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/VersionTuple.h"
1819
#include <optional>
1920
#include <vector>
@@ -69,7 +70,7 @@ struct IFSTarget {
6970
std::optional<IFSEndiannessType> Endianness;
7071
std::optional<IFSBitWidthType> BitWidth;
7172

72-
bool empty();
73+
LLVM_ABI bool empty();
7374
};
7475

7576
inline bool operator==(const IFSTarget &Lhs, const IFSTarget &Rhs) {
@@ -95,8 +96,8 @@ struct IFSStub {
9596
std::vector<IFSSymbol> Symbols;
9697

9798
IFSStub() = default;
98-
IFSStub(const IFSStub &Stub);
99-
IFSStub(IFSStub &&Stub);
99+
LLVM_ABI IFSStub(const IFSStub &Stub);
100+
LLVM_ABI IFSStub(IFSStub &&Stub);
100101
virtual ~IFSStub() = default;
101102
};
102103

@@ -107,50 +108,50 @@ struct IFSStub {
107108
// structure can be used for 2 different yaml schema.
108109
struct IFSStubTriple : IFSStub {
109110
IFSStubTriple() = default;
110-
IFSStubTriple(const IFSStub &Stub);
111-
IFSStubTriple(const IFSStubTriple &Stub);
112-
IFSStubTriple(IFSStubTriple &&Stub);
111+
LLVM_ABI IFSStubTriple(const IFSStub &Stub);
112+
LLVM_ABI IFSStubTriple(const IFSStubTriple &Stub);
113+
LLVM_ABI IFSStubTriple(IFSStubTriple &&Stub);
113114
};
114115

115116
/// This function convert bit width type from IFS enum to ELF format
116117
/// Currently, ELFCLASS32 and ELFCLASS64 are supported.
117118
///
118119
/// @param BitWidth IFS bit width type.
119-
uint8_t convertIFSBitWidthToELF(IFSBitWidthType BitWidth);
120+
LLVM_ABI uint8_t convertIFSBitWidthToELF(IFSBitWidthType BitWidth);
120121

121122
/// This function convert endianness type from IFS enum to ELF format
122123
/// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
123124
///
124125
/// @param Endianness IFS endianness type.
125-
uint8_t convertIFSEndiannessToELF(IFSEndiannessType Endianness);
126+
LLVM_ABI uint8_t convertIFSEndiannessToELF(IFSEndiannessType Endianness);
126127

127128
/// This function convert symbol type from IFS enum to ELF format
128129
/// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
129130
///
130131
/// @param SymbolType IFS symbol type.
131-
uint8_t convertIFSSymbolTypeToELF(IFSSymbolType SymbolType);
132+
LLVM_ABI uint8_t convertIFSSymbolTypeToELF(IFSSymbolType SymbolType);
132133

133134
/// This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file
134135
/// Currently, ELFCLASS32 and ELFCLASS64 are supported.
135136
/// Other endianness types are mapped to IFSBitWidthType::Unknown.
136137
///
137138
/// @param BitWidth e_ident[EI_CLASS] value to extract bit width from.
138-
IFSBitWidthType convertELFBitWidthToIFS(uint8_t BitWidth);
139+
LLVM_ABI IFSBitWidthType convertELFBitWidthToIFS(uint8_t BitWidth);
139140

140141
/// This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file
141142
/// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
142143
/// Other endianness types are mapped to IFSEndiannessType::Unknown.
143144
///
144145
/// @param Endianness e_ident[EI_DATA] value to extract endianness type from.
145-
IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
146+
LLVM_ABI IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
146147

147148
/// This function extracts symbol type from a symbol's st_info member and
148149
/// maps it to an IFSSymbolType enum.
149150
/// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
150151
/// Other symbol types are mapped to IFSSymbolType::Unknown.
151152
///
152153
/// @param SymbolType Binary symbol st_info to extract symbol type from.
153-
IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType);
154+
LLVM_ABI IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType);
154155
} // namespace ifs
155156
} // end namespace llvm
156157

llvm/include/llvm/LTO/Config.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/LegacyPassManager.h"
2323
#include "llvm/Passes/PassBuilder.h"
2424
#include "llvm/Support/CodeGen.h"
25+
#include "llvm/Support/Compiler.h"
2526
#include "llvm/Target/TargetOptions.h"
2627

2728
#include <functional>
@@ -277,9 +278,9 @@ struct Config {
277278
///
278279
/// SaveTempsArgs can be specified to select which temps to save.
279280
/// If SaveTempsArgs is not provided, all temps are saved.
280-
Error addSaveTemps(std::string OutputFileName,
281-
bool UseInputModulePath = false,
282-
const DenseSet<StringRef> &SaveTempsArgs = {});
281+
LLVM_ABI Error addSaveTemps(std::string OutputFileName,
282+
bool UseInputModulePath = false,
283+
const DenseSet<StringRef> &SaveTempsArgs = {});
283284
};
284285

285286
struct LTOLLVMDiagnosticHandler : public DiagnosticHandler {

0 commit comments

Comments
 (0)