Skip to content

Commit 787b0dc

Browse files
authored
Merge pull request #3419 from bitjammer/remote-mirror-metadata-version
SwiftRemoteMirror: Add reflection metadata version query API
2 parents 865b23a + fd46a60 commit 787b0dc

File tree

8 files changed

+28
-2
lines changed

8 files changed

+28
-2
lines changed

include/swift/Reflection/Records.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "swift/Basic/RelativePointer.h"
2121

22+
const uint16_t SWIFT_REFLECTION_METADATA_VERSION = 1;
23+
2224
namespace swift {
2325
namespace reflection {
2426

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
extern "C" {
3737
#endif
3838

39+
/// Get the metadata version supported by the Remote Mirror library.
40+
uint16_t
41+
swift_reflection_getSupportedMetadataVersion();
42+
3943
/// \returns An opaque reflection context.
4044
SwiftReflectionContextRef
4145
swift_reflection_createReflectionContext(

lib/IRGen/GenReflection.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,3 +930,13 @@ void IRGenModule::emitFieldMetadataRecord(const NominalTypeDecl *Decl) {
930930
if (var)
931931
addUsedGlobal(var);
932932
}
933+
934+
void IRGenModule::emitReflectionMetadataVersion() {
935+
auto Init =
936+
llvm::ConstantInt::get(Int16Ty, SWIFT_REFLECTION_METADATA_VERSION);
937+
auto Version = new llvm::GlobalVariable(Module, Int16Ty, /*constant*/ true,
938+
llvm::GlobalValue::LinkOnceODRLinkage,
939+
Init,
940+
"__swift_reflection_version");
941+
addUsedGlobal(Version);
942+
}

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
623623
IGM.emitProtocolConformances();
624624
IGM.emitTypeMetadataRecords();
625625
IGM.emitBuiltinReflectionMetadata();
626+
IGM.emitReflectionMetadataVersion();
626627
}
627628

628629
// Okay, emit any definitions that we suddenly need.

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ class IRGenModule {
743743
void emitAssociatedTypeMetadataRecord(const ProtocolConformance *Conformance);
744744
void emitFieldMetadataRecord(const NominalTypeDecl *Decl);
745745
void emitBuiltinReflectionMetadata();
746+
void emitReflectionMetadataVersion();
746747
std::string getBuiltinTypeMetadataSectionName();
747748
std::string getFieldTypeMetadataSectionName();
748749
std::string getAssociatedTypeMetadataSectionName();

stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ using namespace swift::remote;
2222
using NativeReflectionContext
2323
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>;
2424

25+
uint16_t
26+
swift_reflection_getSupportedMetadataVersion() {
27+
return SWIFT_REFLECTION_METADATA_VERSION;
28+
}
29+
2530
SwiftReflectionContextRef
2631
swift_reflection_createReflectionContext(void *ReaderContext,
2732
PointerSizeFunction getPointerSize,

test/IRGen/unused.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ bb0:
4545
return %1 : $()
4646
}
4747

48-
// CHECK-macho: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @frieda to i8*)], section "llvm.metadata", align 8
49-
// CHECK-elf: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @frieda to i8*), i8* getelementptr inbounds ([0 x i8], [0 x i8]* @_swift1_autolink_entries, i32 0, i32 0)], section "llvm.metadata", align 8
48+
// CHECK-macho: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @frieda to i8*), i8* bitcast (i16* @__swift_reflection_version to i8*)], section "llvm.metadata"
49+
// CHECK-elf: @llvm.used = appending global [3 x i8*] [i8* bitcast (void ()* @frieda to i8*), i8* bitcast (i16* @__swift_reflection_version to i8*), i8* getelementptr inbounds ([0 x i8], [0 x i8]* @_swift1_autolink_entries, i32 0, i32 0)], section "llvm.metadata"
5050

5151
// CHECK: define linkonce_odr hidden void @qux()
5252
// CHECK: define hidden void @fred()

tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,5 +465,8 @@ int main(int argc, char *argv[]) {
465465

466466
const char *BinaryFilename = argv[1];
467467

468+
uint16_t Version = swift_reflection_getSupportedMetadataVersion();
469+
printf("Metadata version: %u\n", Version);
470+
468471
return doDumpHeapInstance(BinaryFilename);
469472
}

0 commit comments

Comments
 (0)