Skip to content

[llvm] annotate interfaces in llvm/ObjCopy and llvm/Object for DLL export #142668

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

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions llvm/include/llvm/ObjCopy/COFF/COFFObjcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLVM_OBJCOPY_COFF_COFFOBJCOPY_H
#define LLVM_OBJCOPY_COFF_COFFOBJCOPY_H

#include "llvm/Support/Compiler.h"

namespace llvm {
class Error;
class raw_ostream;
Expand All @@ -26,8 +28,10 @@ namespace coff {
/// Apply the transformations described by \p Config and \p COFFConfig
/// to \p In and writes the result into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnBinary(const CommonConfig &Config, const COFFConfig &,
object::COFFObjectFile &In, raw_ostream &Out);
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
const COFFConfig &,
object::COFFObjectFile &In,
raw_ostream &Out);

} // end namespace coff
} // end namespace objcopy
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/ObjCopy/CommonConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/ELFTypes.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/GlobPattern.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down Expand Up @@ -104,7 +105,7 @@ class NameOrPattern {
public:
// ErrorCallback is used to handle recoverable errors. An Error returned
// by the callback aborts the parsing and is then returned by this function.
static Expected<NameOrPattern>
LLVM_ABI static Expected<NameOrPattern>
create(StringRef Pattern, MatchStyle MS,
llvm::function_ref<Error(Error)> ErrorCallback);

Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/ObjCopy/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
#include "llvm/ObjCopy/ELF/ELFConfig.h"
#include "llvm/ObjCopy/MachO/MachOConfig.h"
#include "llvm/ObjCopy/MultiFormatConfig.h"
#include "llvm/ObjCopy/wasm/WasmConfig.h"
#include "llvm/ObjCopy/XCOFF/XCOFFConfig.h"
#include "llvm/ObjCopy/wasm/WasmConfig.h"
#include "llvm/Support/Compiler.h"

namespace llvm {
namespace objcopy {

struct ConfigManager : public MultiFormatConfig {
struct LLVM_ABI ConfigManager : public MultiFormatConfig {
virtual ~ConfigManager() {}

const CommonConfig &getCommonConfig() const override { return Common; }
Expand Down
21 changes: 12 additions & 9 deletions llvm/include/llvm/ObjCopy/ELF/ELFObjcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLVM_OBJCOPY_ELF_ELFOBJCOPY_H
#define LLVM_OBJCOPY_ELF_ELFOBJCOPY_H

#include "llvm/Support/Compiler.h"

namespace llvm {
class Error;
class MemoryBuffer;
Expand All @@ -27,24 +29,25 @@ namespace elf {
/// \p In, which must represent an IHex file, and writes the result
/// into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnIHex(const CommonConfig &Config,
const ELFConfig &ELFConfig, MemoryBuffer &In,
raw_ostream &Out);
LLVM_ABI Error executeObjcopyOnIHex(const CommonConfig &Config,
const ELFConfig &ELFConfig,
MemoryBuffer &In, raw_ostream &Out);

/// Apply the transformations described by \p Config and \p ELFConfig to
/// \p In, which is treated as a raw binary input, and writes the result
/// into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnRawBinary(const CommonConfig &Config,
const ELFConfig &ELFConfig, MemoryBuffer &In,
raw_ostream &Out);
LLVM_ABI Error executeObjcopyOnRawBinary(const CommonConfig &Config,
const ELFConfig &ELFConfig,
MemoryBuffer &In, raw_ostream &Out);

/// Apply the transformations described by \p Config and \p ELFConfig to
/// \p In and writes the result into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnBinary(const CommonConfig &Config,
const ELFConfig &ELFConfig,
object::ELFObjectFileBase &In, raw_ostream &Out);
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
const ELFConfig &ELFConfig,
object::ELFObjectFileBase &In,
raw_ostream &Out);

} // end namespace elf
} // end namespace objcopy
Expand Down
11 changes: 7 additions & 4 deletions llvm/include/llvm/ObjCopy/MachO/MachOObjcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLVM_OBJCOPY_MACHO_MACHOOBJCOPY_H
#define LLVM_OBJCOPY_MACHO_MACHOOBJCOPY_H

#include "llvm/Support/Compiler.h"

namespace llvm {
class Error;
class raw_ostream;
Expand All @@ -27,14 +29,15 @@ namespace macho {
/// Apply the transformations described by \p Config and \p MachOConfig to
/// \p In and writes the result into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnBinary(const CommonConfig &Config,
const MachOConfig &MachOConfig,
object::MachOObjectFile &In, raw_ostream &Out);
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
const MachOConfig &MachOConfig,
object::MachOObjectFile &In,
raw_ostream &Out);

/// Apply the transformations described by \p Config and \p MachOConfig to
/// \p In and writes the result into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnMachOUniversalBinary(
LLVM_ABI Error executeObjcopyOnMachOUniversalBinary(
const MultiFormatConfig &Config, const object::MachOUniversalBinary &In,
raw_ostream &Out);

Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/ObjCopy/ObjCopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_OBJCOPY_OBJCOPY_H
#define LLVM_OBJCOPY_OBJCOPY_H

#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"

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

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

} // end namespace objcopy
} // end namespace llvm
Expand Down
8 changes: 6 additions & 2 deletions llvm/include/llvm/ObjCopy/wasm/WasmObjcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLVM_OBJCOPY_WASM_WASMOBJCOPY_H
#define LLVM_OBJCOPY_WASM_WASMOBJCOPY_H

#include "llvm/Support/Compiler.h"

namespace llvm {
class Error;
class raw_ostream;
Expand All @@ -25,8 +27,10 @@ namespace wasm {
/// Apply the transformations described by \p Config and \p WasmConfig
/// to \p In and writes the result into \p Out.
/// \returns any Error encountered whilst performing the operation.
Error executeObjcopyOnBinary(const CommonConfig &Config, const WasmConfig &,
object::WasmObjectFile &In, raw_ostream &Out);
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config,
const WasmConfig &,
object::WasmObjectFile &In,
raw_ostream &Out);

} // end namespace wasm
} // end namespace objcopy
Expand Down
55 changes: 31 additions & 24 deletions llvm/include/llvm/Object/Archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/Object/Binary.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down Expand Up @@ -61,10 +62,11 @@ class AbstractArchiveMemberHeader {
virtual Expected<const char *> getNextChildLoc() const = 0;
virtual Expected<bool> isThin() const = 0;

Expected<sys::fs::perms> getAccessMode() const;
Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const;
Expected<unsigned> getUID() const;
Expected<unsigned> getGID() const;
LLVM_ABI Expected<sys::fs::perms> getAccessMode() const;
LLVM_ABI Expected<sys::TimePoint<std::chrono::seconds>>
getLastModified() const;
LLVM_ABI Expected<unsigned> getUID() const;
LLVM_ABI Expected<unsigned> getGID() const;

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

template <typename T>
class CommonArchiveMemberHeader : public AbstractArchiveMemberHeader {
class LLVM_ABI CommonArchiveMemberHeader : public AbstractArchiveMemberHeader {
public:
CommonArchiveMemberHeader(const Archive *Parent, const T *RawHeaderPtr)
: AbstractArchiveMemberHeader(Parent), ArMemHdr(RawHeaderPtr){};
Expand All @@ -99,7 +101,8 @@ struct UnixArMemHdrType {
char Terminator[2];
};

class ArchiveMemberHeader : public CommonArchiveMemberHeader<UnixArMemHdrType> {
class LLVM_ABI ArchiveMemberHeader
: public CommonArchiveMemberHeader<UnixArMemHdrType> {
public:
ArchiveMemberHeader(const Archive *Parent, const char *RawHeaderPtr,
uint64_t Size, Error *Err);
Expand Down Expand Up @@ -133,7 +136,7 @@ struct BigArMemHdrType {
};

// Define file member header of AIX big archive.
class BigArchiveMemberHeader
class LLVM_ABI BigArchiveMemberHeader
: public CommonArchiveMemberHeader<BigArMemHdrType> {

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

class Archive : public Binary {
class LLVM_ABI Archive : public Binary {
virtual void anchor();

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

public:
Child(const Archive *Parent, const char *Start, Error *Err);
Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);
LLVM_ABI Child(const Archive *Parent, const char *Start, Error *Err);
LLVM_ABI Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);

Child(const Child &C)
: Parent(C.Parent), Data(C.Data), StartOfFile(C.StartOfFile) {
Expand Down Expand Up @@ -218,10 +221,10 @@ class Archive : public Binary {
}

const Archive *getParent() const { return Parent; }
Expected<Child> getNext() const;
LLVM_ABI Expected<Child> getNext() const;

Expected<StringRef> getName() const;
Expected<std::string> getFullName() const;
LLVM_ABI Expected<StringRef> getName() const;
LLVM_ABI Expected<std::string> getFullName() const;
Expected<StringRef> getRawName() const { return Header->getRawName(); }

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

/// \return the size of the archive member without the header or padding.
Expected<uint64_t> getSize() const;
LLVM_ABI Expected<uint64_t> getSize() const;
/// \return the size in the archive header for this member.
Expected<uint64_t> getRawSize() const;
LLVM_ABI Expected<uint64_t> getRawSize() const;

Expected<StringRef> getBuffer() const;
uint64_t getChildOffset() const;
LLVM_ABI Expected<StringRef> getBuffer() const;
LLVM_ABI uint64_t getChildOffset() const;
uint64_t getDataOffset() const { return getChildOffset() + StartOfFile; }

Expected<MemoryBufferRef> getMemoryBufferRef() const;
LLVM_ABI Expected<MemoryBufferRef> getMemoryBufferRef() const;

Expected<std::unique_ptr<Binary>>
LLVM_ABI Expected<std::unique_ptr<Binary>>
getAsBinary(LLVMContext *Context = nullptr) const;
};

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

StringRef getName() const;
Expected<Child> getMember() const;
Symbol getNext() const;
bool isECSymbol() const;
LLVM_ABI StringRef getName() const;
LLVM_ABI Expected<Child> getMember() const;
LLVM_ABI Symbol getNext() const;
LLVM_ABI bool isECSymbol() const;
};

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

// Explicitly non-copyable.
Archive(Archive const &) = delete;
Archive &operator=(Archive const &) = delete;

/// Size field is 10 decimal digits long
static const uint64_t MaxMemberSize = 9999999999;

Expand Down Expand Up @@ -416,7 +423,7 @@ class BigArchive : public Archive {
bool Has64BitGlobalSymtab = false;

public:
BigArchive(MemoryBufferRef Source, Error &Err);
LLVM_ABI BigArchive(MemoryBufferRef Source, Error &Err);
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
uint64_t getLastChildOffset() const { return LastChildOffset; }
bool isEmpty() const override { return getFirstChildOffset() == 0; }
Expand Down
Loading