Skip to content

Commit fd46a60

Browse files
committed
IRGen: Emit reflection metadata version into Swift binaries
Emit a 16-bit constant that tracks the version of the reflection metadata emitted into binaries. This can be used to cross-check what is supported by the SwiftRemoteMirror library with the new version API. rdar://problem/27251582
1 parent 941ec1e commit fd46a60

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

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();

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()

0 commit comments

Comments
 (0)