Skip to content

Commit ecbe2e8

Browse files
authored
[llvm] annotate interfaces in llvm/ObjCopy and llvm/Object for DLL export (#142668)
## 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
1 parent 68a346f commit ecbe2e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+457
-377
lines changed

llvm/include/llvm/ObjCopy/COFF/COFFObjcopy.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLVM_OBJCOPY_COFF_COFFOBJCOPY_H
1010
#define LLVM_OBJCOPY_COFF_COFFOBJCOPY_H
1111

12+
#include "llvm/Support/Compiler.h"
13+
1214
namespace llvm {
1315
class Error;
1416
class raw_ostream;
@@ -26,8 +28,10 @@ namespace coff {
2628
/// Apply the transformations described by \p Config and \p COFFConfig
2729
/// to \p In and writes the result into \p Out.
2830
/// \returns any Error encountered whilst performing the operation.
29-
Error executeObjcopyOnBinary(const CommonConfig &Config, const COFFConfig &,
30-
object::COFFObjectFile &In, raw_ostream &Out);
31+
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
32+
const COFFConfig &,
33+
object::COFFObjectFile &In,
34+
raw_ostream &Out);
3135

3236
} // end namespace coff
3337
} // end namespace objcopy

llvm/include/llvm/ObjCopy/CommonConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/StringMap.h"
1717
#include "llvm/ADT/StringRef.h"
1818
#include "llvm/Object/ELFTypes.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Support/Compression.h"
2021
#include "llvm/Support/GlobPattern.h"
2122
#include "llvm/Support/MemoryBuffer.h"
@@ -104,7 +105,7 @@ class NameOrPattern {
104105
public:
105106
// ErrorCallback is used to handle recoverable errors. An Error returned
106107
// by the callback aborts the parsing and is then returned by this function.
107-
static Expected<NameOrPattern>
108+
LLVM_ABI static Expected<NameOrPattern>
108109
create(StringRef Pattern, MatchStyle MS,
109110
llvm::function_ref<Error(Error)> ErrorCallback);
110111

llvm/include/llvm/ObjCopy/ConfigManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
#include "llvm/ObjCopy/ELF/ELFConfig.h"
1515
#include "llvm/ObjCopy/MachO/MachOConfig.h"
1616
#include "llvm/ObjCopy/MultiFormatConfig.h"
17-
#include "llvm/ObjCopy/wasm/WasmConfig.h"
1817
#include "llvm/ObjCopy/XCOFF/XCOFFConfig.h"
18+
#include "llvm/ObjCopy/wasm/WasmConfig.h"
19+
#include "llvm/Support/Compiler.h"
1920

2021
namespace llvm {
2122
namespace objcopy {
2223

23-
struct ConfigManager : public MultiFormatConfig {
24+
struct LLVM_ABI ConfigManager : public MultiFormatConfig {
2425
virtual ~ConfigManager() {}
2526

2627
const CommonConfig &getCommonConfig() const override { return Common; }

llvm/include/llvm/ObjCopy/ELF/ELFObjcopy.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLVM_OBJCOPY_ELF_ELFOBJCOPY_H
1010
#define LLVM_OBJCOPY_ELF_ELFOBJCOPY_H
1111

12+
#include "llvm/Support/Compiler.h"
13+
1214
namespace llvm {
1315
class Error;
1416
class MemoryBuffer;
@@ -27,24 +29,25 @@ namespace elf {
2729
/// \p In, which must represent an IHex file, and writes the result
2830
/// into \p Out.
2931
/// \returns any Error encountered whilst performing the operation.
30-
Error executeObjcopyOnIHex(const CommonConfig &Config,
31-
const ELFConfig &ELFConfig, MemoryBuffer &In,
32-
raw_ostream &Out);
32+
LLVM_ABI Error executeObjcopyOnIHex(const CommonConfig &Config,
33+
const ELFConfig &ELFConfig,
34+
MemoryBuffer &In, raw_ostream &Out);
3335

3436
/// Apply the transformations described by \p Config and \p ELFConfig to
3537
/// \p In, which is treated as a raw binary input, and writes the result
3638
/// into \p Out.
3739
/// \returns any Error encountered whilst performing the operation.
38-
Error executeObjcopyOnRawBinary(const CommonConfig &Config,
39-
const ELFConfig &ELFConfig, MemoryBuffer &In,
40-
raw_ostream &Out);
40+
LLVM_ABI Error executeObjcopyOnRawBinary(const CommonConfig &Config,
41+
const ELFConfig &ELFConfig,
42+
MemoryBuffer &In, raw_ostream &Out);
4143

4244
/// Apply the transformations described by \p Config and \p ELFConfig to
4345
/// \p In and writes the result into \p Out.
4446
/// \returns any Error encountered whilst performing the operation.
45-
Error executeObjcopyOnBinary(const CommonConfig &Config,
46-
const ELFConfig &ELFConfig,
47-
object::ELFObjectFileBase &In, raw_ostream &Out);
47+
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
48+
const ELFConfig &ELFConfig,
49+
object::ELFObjectFileBase &In,
50+
raw_ostream &Out);
4851

4952
} // end namespace elf
5053
} // end namespace objcopy

llvm/include/llvm/ObjCopy/MachO/MachOObjcopy.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLVM_OBJCOPY_MACHO_MACHOOBJCOPY_H
1010
#define LLVM_OBJCOPY_MACHO_MACHOOBJCOPY_H
1111

12+
#include "llvm/Support/Compiler.h"
13+
1214
namespace llvm {
1315
class Error;
1416
class raw_ostream;
@@ -27,14 +29,15 @@ namespace macho {
2729
/// Apply the transformations described by \p Config and \p MachOConfig to
2830
/// \p In and writes the result into \p Out.
2931
/// \returns any Error encountered whilst performing the operation.
30-
Error executeObjcopyOnBinary(const CommonConfig &Config,
31-
const MachOConfig &MachOConfig,
32-
object::MachOObjectFile &In, raw_ostream &Out);
32+
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
33+
const MachOConfig &MachOConfig,
34+
object::MachOObjectFile &In,
35+
raw_ostream &Out);
3336

3437
/// Apply the transformations described by \p Config and \p MachOConfig to
3538
/// \p In and writes the result into \p Out.
3639
/// \returns any Error encountered whilst performing the operation.
37-
Error executeObjcopyOnMachOUniversalBinary(
40+
LLVM_ABI Error executeObjcopyOnMachOUniversalBinary(
3841
const MultiFormatConfig &Config, const object::MachOUniversalBinary &In,
3942
raw_ostream &Out);
4043

llvm/include/llvm/ObjCopy/ObjCopy.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_OBJCOPY_OBJCOPY_H
1010
#define LLVM_OBJCOPY_OBJCOPY_H
1111

12+
#include "llvm/Support/Compiler.h"
1213
#include "llvm/Support/Error.h"
1314

1415
namespace llvm {
@@ -26,15 +27,15 @@ class MultiFormatConfig;
2627
/// each member in archive \p Ar.
2728
/// Writes a result in a file specified by \p Config.OutputFilename.
2829
/// \returns any Error encountered whilst performing the operation.
29-
Error executeObjcopyOnArchive(const MultiFormatConfig &Config,
30-
const object::Archive &Ar);
30+
LLVM_ABI Error executeObjcopyOnArchive(const MultiFormatConfig &Config,
31+
const object::Archive &Ar);
3132

3233
/// Applies the transformations described by \p Config to \p In and writes
3334
/// the result into \p Out. This function does the dispatch based on the
3435
/// format of the input binary (COFF, ELF, MachO or wasm).
3536
/// \returns any Error encountered whilst performing the operation.
36-
Error executeObjcopyOnBinary(const MultiFormatConfig &Config,
37-
object::Binary &In, raw_ostream &Out);
37+
LLVM_ABI Error executeObjcopyOnBinary(const MultiFormatConfig &Config,
38+
object::Binary &In, raw_ostream &Out);
3839

3940
} // end namespace objcopy
4041
} // end namespace llvm

llvm/include/llvm/ObjCopy/wasm/WasmObjcopy.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLVM_OBJCOPY_WASM_WASMOBJCOPY_H
1010
#define LLVM_OBJCOPY_WASM_WASMOBJCOPY_H
1111

12+
#include "llvm/Support/Compiler.h"
13+
1214
namespace llvm {
1315
class Error;
1416
class raw_ostream;
@@ -25,8 +27,10 @@ namespace wasm {
2527
/// Apply the transformations described by \p Config and \p WasmConfig
2628
/// to \p In and writes the result into \p Out.
2729
/// \returns any Error encountered whilst performing the operation.
28-
Error executeObjcopyOnBinary(const CommonConfig &Config, const WasmConfig &,
29-
object::WasmObjectFile &In, raw_ostream &Out);
30+
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
31+
const WasmConfig &,
32+
object::WasmObjectFile &In,
33+
raw_ostream &Out);
3034

3135
} // end namespace wasm
3236
} // end namespace objcopy

llvm/include/llvm/Object/Archive.h

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/iterator_range.h"
1919
#include "llvm/Object/Binary.h"
2020
#include "llvm/Support/Chrono.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/Error.h"
2223
#include "llvm/Support/FileSystem.h"
2324
#include "llvm/Support/MemoryBuffer.h"
@@ -61,10 +62,11 @@ class AbstractArchiveMemberHeader {
6162
virtual Expected<const char *> getNextChildLoc() const = 0;
6263
virtual Expected<bool> isThin() const = 0;
6364

64-
Expected<sys::fs::perms> getAccessMode() const;
65-
Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const;
66-
Expected<unsigned> getUID() const;
67-
Expected<unsigned> getGID() const;
65+
LLVM_ABI Expected<sys::fs::perms> getAccessMode() const;
66+
LLVM_ABI Expected<sys::TimePoint<std::chrono::seconds>>
67+
getLastModified() const;
68+
LLVM_ABI Expected<unsigned> getUID() const;
69+
LLVM_ABI Expected<unsigned> getGID() const;
6870

6971
/// Returns the size in bytes of the format-defined member header of the
7072
/// concrete archive type.
@@ -74,7 +76,7 @@ class AbstractArchiveMemberHeader {
7476
};
7577

7678
template <typename T>
77-
class CommonArchiveMemberHeader : public AbstractArchiveMemberHeader {
79+
class LLVM_ABI CommonArchiveMemberHeader : public AbstractArchiveMemberHeader {
7880
public:
7981
CommonArchiveMemberHeader(const Archive *Parent, const T *RawHeaderPtr)
8082
: AbstractArchiveMemberHeader(Parent), ArMemHdr(RawHeaderPtr){};
@@ -99,7 +101,8 @@ struct UnixArMemHdrType {
99101
char Terminator[2];
100102
};
101103

102-
class ArchiveMemberHeader : public CommonArchiveMemberHeader<UnixArMemHdrType> {
104+
class LLVM_ABI ArchiveMemberHeader
105+
: public CommonArchiveMemberHeader<UnixArMemHdrType> {
103106
public:
104107
ArchiveMemberHeader(const Archive *Parent, const char *RawHeaderPtr,
105108
uint64_t Size, Error *Err);
@@ -133,7 +136,7 @@ struct BigArMemHdrType {
133136
};
134137

135138
// Define file member header of AIX big archive.
136-
class BigArchiveMemberHeader
139+
class LLVM_ABI BigArchiveMemberHeader
137140
: public CommonArchiveMemberHeader<BigArMemHdrType> {
138141

139142
public:
@@ -153,7 +156,7 @@ class BigArchiveMemberHeader
153156
Expected<bool> isThin() const override { return false; }
154157
};
155158

156-
class Archive : public Binary {
159+
class LLVM_ABI Archive : public Binary {
157160
virtual void anchor();
158161

159162
public:
@@ -171,8 +174,8 @@ class Archive : public Binary {
171174
Expected<bool> isThinMember() const;
172175

173176
public:
174-
Child(const Archive *Parent, const char *Start, Error *Err);
175-
Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);
177+
LLVM_ABI Child(const Archive *Parent, const char *Start, Error *Err);
178+
LLVM_ABI Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);
176179

177180
Child(const Child &C)
178181
: Parent(C.Parent), Data(C.Data), StartOfFile(C.StartOfFile) {
@@ -218,10 +221,10 @@ class Archive : public Binary {
218221
}
219222

220223
const Archive *getParent() const { return Parent; }
221-
Expected<Child> getNext() const;
224+
LLVM_ABI Expected<Child> getNext() const;
222225

223-
Expected<StringRef> getName() const;
224-
Expected<std::string> getFullName() const;
226+
LLVM_ABI Expected<StringRef> getName() const;
227+
LLVM_ABI Expected<std::string> getFullName() const;
225228
Expected<StringRef> getRawName() const { return Header->getRawName(); }
226229

227230
Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const {
@@ -240,17 +243,17 @@ class Archive : public Binary {
240243
}
241244

242245
/// \return the size of the archive member without the header or padding.
243-
Expected<uint64_t> getSize() const;
246+
LLVM_ABI Expected<uint64_t> getSize() const;
244247
/// \return the size in the archive header for this member.
245-
Expected<uint64_t> getRawSize() const;
248+
LLVM_ABI Expected<uint64_t> getRawSize() const;
246249

247-
Expected<StringRef> getBuffer() const;
248-
uint64_t getChildOffset() const;
250+
LLVM_ABI Expected<StringRef> getBuffer() const;
251+
LLVM_ABI uint64_t getChildOffset() const;
249252
uint64_t getDataOffset() const { return getChildOffset() + StartOfFile; }
250253

251-
Expected<MemoryBufferRef> getMemoryBufferRef() const;
254+
LLVM_ABI Expected<MemoryBufferRef> getMemoryBufferRef() const;
252255

253-
Expected<std::unique_ptr<Binary>>
256+
LLVM_ABI Expected<std::unique_ptr<Binary>>
254257
getAsBinary(LLVMContext *Context = nullptr) const;
255258
};
256259

@@ -299,10 +302,10 @@ class Archive : public Binary {
299302
return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
300303
}
301304

302-
StringRef getName() const;
303-
Expected<Child> getMember() const;
304-
Symbol getNext() const;
305-
bool isECSymbol() const;
305+
LLVM_ABI StringRef getName() const;
306+
LLVM_ABI Expected<Child> getMember() const;
307+
LLVM_ABI Symbol getNext() const;
308+
LLVM_ABI bool isECSymbol() const;
306309
};
307310

308311
class symbol_iterator {
@@ -331,6 +334,10 @@ class Archive : public Binary {
331334
Archive(MemoryBufferRef Source, Error &Err);
332335
static Expected<std::unique_ptr<Archive>> create(MemoryBufferRef Source);
333336

337+
// Explicitly non-copyable.
338+
Archive(Archive const &) = delete;
339+
Archive &operator=(Archive const &) = delete;
340+
334341
/// Size field is 10 decimal digits long
335342
static const uint64_t MaxMemberSize = 9999999999;
336343

@@ -416,7 +423,7 @@ class BigArchive : public Archive {
416423
bool Has64BitGlobalSymtab = false;
417424

418425
public:
419-
BigArchive(MemoryBufferRef Source, Error &Err);
426+
LLVM_ABI BigArchive(MemoryBufferRef Source, Error &Err);
420427
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
421428
uint64_t getLastChildOffset() const { return LastChildOffset; }
422429
bool isEmpty() const override { return getFirstChildOffset() == 0; }

0 commit comments

Comments
 (0)