mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
108 lines
3.6 KiB
C++
108 lines
3.6 KiB
C++
//===--- ObjectFile.h - Object File Related Information ------*- C++ -*-===//
|
|
//
|
|
// Object File related data structures.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_ABI_OBJECTFILE_H
|
|
#define SWIFT_ABI_OBJECTFILE_H
|
|
|
|
#include "llvm/ADT/Optional.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
namespace swift {
|
|
|
|
/// Represents the nine reflection sections used by Swift + the Swift AST
|
|
/// section used by the debugger.
|
|
enum ReflectionSectionKind : uint8_t {
|
|
#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) KIND,
|
|
#include "llvm/BinaryFormat/Swift.def"
|
|
#undef HANDLE_SWIFT_SECTION
|
|
};
|
|
|
|
/// Abstract base class responsible for providing the correct reflection section
|
|
/// string identifier for a given object file type (Mach-O, ELF, COFF).
|
|
class SwiftObjectFileFormat {
|
|
public:
|
|
virtual ~SwiftObjectFileFormat() {}
|
|
virtual llvm::StringRef getSectionName(ReflectionSectionKind section) = 0;
|
|
virtual llvm::Optional<llvm::StringRef> getSegmentName() {
|
|
return {};
|
|
}
|
|
/// Get the name of the segment in the symbol rich binary that may contain
|
|
/// Swift metadata.
|
|
virtual llvm::Optional<llvm::StringRef> getSymbolRichSegmentName() {
|
|
return {};
|
|
}
|
|
/// Predicate to identify if the named section can contain reflection data.
|
|
virtual bool sectionContainsReflectionData(llvm::StringRef sectionName) = 0;
|
|
};
|
|
|
|
/// Responsible for providing the Mach-O reflection section identifiers.
|
|
class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
|
|
public:
|
|
llvm::StringRef getSectionName(ReflectionSectionKind section) override {
|
|
switch (section) {
|
|
#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
|
|
case KIND: \
|
|
return MACHO;
|
|
#include "llvm/BinaryFormat/Swift.def"
|
|
#undef HANDLE_SWIFT_SECTION
|
|
}
|
|
llvm_unreachable("Section type not found.");
|
|
}
|
|
|
|
llvm::Optional<llvm::StringRef> getSegmentName() override {
|
|
return {"__TEXT"};
|
|
}
|
|
|
|
llvm::Optional<llvm::StringRef> getSymbolRichSegmentName() override {
|
|
return {"__DWARF"};
|
|
}
|
|
|
|
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
|
|
return sectionName.startswith("__swift5_") || sectionName == "__const";
|
|
}
|
|
};
|
|
|
|
/// Responsible for providing the ELF reflection section identifiers.
|
|
class SwiftObjectFileFormatELF : public SwiftObjectFileFormat {
|
|
public:
|
|
llvm::StringRef getSectionName(ReflectionSectionKind section) override {
|
|
switch (section) {
|
|
#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
|
|
case KIND: \
|
|
return ELF;
|
|
#include "llvm/BinaryFormat/Swift.def"
|
|
#undef HANDLE_SWIFT_SECTION
|
|
}
|
|
llvm_unreachable("Section type not found.");
|
|
}
|
|
|
|
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
|
|
return sectionName.startswith("swift5_");
|
|
}
|
|
};
|
|
|
|
/// Responsible for providing the COFF reflection section identifiers
|
|
class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat {
|
|
public:
|
|
llvm::StringRef getSectionName(ReflectionSectionKind section) override {
|
|
switch (section) {
|
|
#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
|
|
case KIND: \
|
|
return COFF;
|
|
#include "llvm/BinaryFormat/Swift.def"
|
|
#undef HANDLE_SWIFT_SECTION
|
|
}
|
|
llvm_unreachable("Section not found.");
|
|
}
|
|
|
|
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
|
|
return sectionName.startswith(".sw5");
|
|
}
|
|
};
|
|
} // namespace swift
|
|
#endif // SWIFT_ABI_OBJECTFILE_H
|