Skip to content

Commit 086bdac

Browse files
committed
Merge pull request #41066 from apple/ABI-Add-predicate-to-identify-sections-containing-reflection-data
[ABI] Add predicate to identify sections containing reflection data (cherry picked from commit 56a614a)
1 parent fb033ce commit 086bdac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/swift/ABI/ObjectFile.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SwiftObjectFileFormat {
2828
public:
2929
virtual ~SwiftObjectFileFormat() {}
3030
virtual llvm::StringRef getSectionName(ReflectionSectionKind section) = 0;
31+
/// Predicate to identify if the named section can contain reflection data.
32+
virtual bool sectionContainsReflectionData(llvm::StringRef sectionName) = 0;
3133
};
3234

3335
/// Responsible for providing the Mach-O reflection section identifiers.
@@ -50,6 +52,15 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
5052
}
5153
llvm_unreachable("Section type not found.");
5254
}
55+
56+
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
57+
// For Mach-O, the caller must call this function twice, once with just the
58+
// section name (ex `__swift5_fieldmd`), and again with the segment
59+
// qualified section name (ex `__DATA,__const`).
60+
return sectionName.startswith("__swift5_") ||
61+
sectionName == "__DATA_CONST,__const" ||
62+
sectionName == "__DATA,__const";
63+
}
5364
};
5465

5566
/// Responsible for providing the ELF reflection section identifiers.
@@ -72,6 +83,10 @@ class SwiftObjectFileFormatELF : public SwiftObjectFileFormat {
7283
}
7384
llvm_unreachable("Section type not found.");
7485
}
86+
87+
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
88+
return sectionName.startswith("swift5_");
89+
}
7590
};
7691

7792
/// Responsible for providing the COFF reflection section identifiers
@@ -94,6 +109,10 @@ class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat {
94109
}
95110
llvm_unreachable("Section not found.");
96111
}
112+
113+
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
114+
return sectionName.startswith(".sw5");
115+
}
97116
};
98117
} // namespace swift
99118
#endif // SWIFT_ABI_OBJECTFILE_H

0 commit comments

Comments
 (0)