-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add functionality that returns correct reflection section name for different object files (Mach-O, ELF, COFF) #33358
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
adrian-prantl
merged 1 commit into
swiftlang:master
from
augusto2112:reflection-section-constants
Aug 11, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//===--- ObjectFile.h - Object File Related Information ------*- C++ -*-===// | ||
// | ||
// Object File related data structures. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_ABI_OBJECTFILE_H | ||
#define SWIFT_ABI_OBJECTFILE_H | ||
|
||
#include "llvm/Support/ErrorHandling.h" | ||
#include "llvm/ADT/StringRef.h" | ||
|
||
namespace swift { | ||
|
||
/// Represents the six reflection sections used by Swift | ||
enum ReflectionSectionKind : uint8_t { | ||
fieldmd, | ||
assocty, | ||
builtin, | ||
capture, | ||
typeref, | ||
reflstr | ||
}; | ||
|
||
/// 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; | ||
}; | ||
|
||
/// Responsible for providing the Mach-O reflection section identifiers. | ||
class SwiftObjectFileFormatMachO : SwiftObjectFileFormat { | ||
public: | ||
llvm::StringRef getSectionName(ReflectionSectionKind section) override { | ||
switch (section) { | ||
case fieldmd: | ||
return "__swift5_fieldmd"; | ||
case assocty: | ||
return "__swift5_assocty"; | ||
case builtin: | ||
return "__swift5_builtin"; | ||
case capture: | ||
return "__swift5_capture"; | ||
case typeref: | ||
return "__swift5_typeref"; | ||
case reflstr: | ||
return "__swift5_reflstr"; | ||
} | ||
llvm_unreachable("Section type not found."); | ||
} | ||
}; | ||
|
||
/// Responsible for providing the ELF reflection section identifiers. | ||
class SwiftObjectFileFormatELF : SwiftObjectFileFormat { | ||
public: | ||
llvm::StringRef getSectionName(ReflectionSectionKind section) override { | ||
switch (section) { | ||
case fieldmd: | ||
return "swift5_fieldmd"; | ||
case assocty: | ||
return "swift5_assocty"; | ||
case builtin: | ||
return "swift5_builtin"; | ||
case capture: | ||
return "swift5_capture"; | ||
case typeref: | ||
return "swift5_typeref"; | ||
case reflstr: | ||
return "swift5_reflstr"; | ||
} | ||
llvm_unreachable("Section type not found."); | ||
} | ||
}; | ||
|
||
/// Responsible for providing the COFF reflection section identifiers | ||
class SwiftObjectFileFormatCOFF : SwiftObjectFileFormat { | ||
public: | ||
llvm::StringRef getSectionName(ReflectionSectionKind section) override { | ||
switch (section) { | ||
case fieldmd: | ||
return ".sw5flmd"; | ||
case assocty: | ||
return ".sw5asty"; | ||
case builtin: | ||
return ".sw5bltn"; | ||
case capture: | ||
return ".sw5cptr"; | ||
case typeref: | ||
return ".sw5tyrf"; | ||
case reflstr: | ||
return ".sw5rfst"; | ||
} | ||
llvm_unreachable("Section not found."); | ||
} | ||
}; | ||
} // namespace swift | ||
#endif // SWIFT_ABI_OBJECTFILE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.