Skip to content

Remote mirror metadata version 27251582 #3512

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/Reflection/Records.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "swift/Basic/RelativePointer.h"

const uint16_t SWIFT_REFLECTION_METADATA_VERSION = 1;

namespace swift {
namespace reflection {

Expand Down
4 changes: 4 additions & 0 deletions include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
extern "C" {
#endif

/// Get the metadata version supported by the Remote Mirror library.
uint16_t
swift_reflection_getSupportedMetadataVersion();

/// \returns An opaque reflection context.
SwiftReflectionContextRef
swift_reflection_createReflectionContext(
Expand Down
11 changes: 11 additions & 0 deletions lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,3 +930,14 @@ void IRGenModule::emitFieldMetadataRecord(const NominalTypeDecl *Decl) {
if (var)
addUsedGlobal(var);
}

void IRGenModule::emitReflectionMetadataVersion() {
auto Init =
llvm::ConstantInt::get(Int16Ty, SWIFT_REFLECTION_METADATA_VERSION);
auto Version = new llvm::GlobalVariable(Module, Int16Ty, /*constant*/ true,
llvm::GlobalValue::LinkOnceODRLinkage,
Init,
"__swift_reflection_version");
Version->setVisibility(llvm::GlobalValue::HiddenVisibility);
addUsedGlobal(Version);
}
1 change: 1 addition & 0 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
IGM.emitProtocolConformances();
IGM.emitTypeMetadataRecords();
IGM.emitBuiltinReflectionMetadata();
IGM.emitReflectionMetadataVersion();
}

// Okay, emit any definitions that we suddenly need.
Expand Down
1 change: 1 addition & 0 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ class IRGenModule {
void emitAssociatedTypeMetadataRecord(const ProtocolConformance *Conformance);
void emitFieldMetadataRecord(const NominalTypeDecl *Decl);
void emitBuiltinReflectionMetadata();
void emitReflectionMetadataVersion();
std::string getBuiltinTypeMetadataSectionName();
std::string getFieldTypeMetadataSectionName();
std::string getAssociatedTypeMetadataSectionName();
Expand Down
5 changes: 5 additions & 0 deletions stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ using namespace swift::remote;
using NativeReflectionContext
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>;

uint16_t
swift_reflection_getSupportedMetadataVersion() {
return SWIFT_REFLECTION_METADATA_VERSION;
}

SwiftReflectionContextRef
swift_reflection_createReflectionContext(void *ReaderContext,
PointerSizeFunction getPointerSize,
Expand Down
1 change: 1 addition & 0 deletions test/IRGen/reflection_metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

// STRIP_REFLECTION_METADATA-NOT: @"\01l__swift3_reflection_metadata"

// CHECK-DAG: @__swift_reflection_version = linkonce_odr hidden constant i16 {{[0-9]+}}
// CHECK-DAG: private constant [2 x i8] c"i\00", section "{{[^"]*}}swift3_reflstr{{[^"]*}}"
// CHECK-DAG: private constant [3 x i8] c"ms\00", section "{{[^"]*}}swift3_reflstr{{[^"]*}}"
// CHECK-DAG: private constant [3 x i8] c"me\00", section "{{[^"]*}}swift3_reflstr{{[^"]*}}"
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/unused.sil
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ bb0:
return %1 : $()
}

// CHECK-macho: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @frieda to i8*)], section "llvm.metadata", align 8
// 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
// 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"
// 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"

// CHECK: define linkonce_odr hidden void @qux()
// CHECK: define hidden void @fred()
Expand Down
3 changes: 3 additions & 0 deletions tools/swift-reflection-test/swift-reflection-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,8 @@ int main(int argc, char *argv[]) {

const char *BinaryFilename = argv[1];

uint16_t Version = swift_reflection_getSupportedMetadataVersion();
printf("Metadata version: %u\n", Version);

return doDumpHeapInstance(BinaryFilename);
}