Skip to content

Commit da724b3

Browse files
authored
Merge pull request #20574 from compnerd/lazy-metadata
IRGen: force lazy metadata initialization for PE/COFF
2 parents 2de83cf + 13d56a4 commit da724b3

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ class IRGenOptions {
171171
/// Bypass resilience when accessing resilient frameworks.
172172
unsigned EnableResilienceBypass : 1;
173173

174+
/// Force lazy initialization of class metadata
175+
/// Used on Windows to avoid cross-module references.
176+
unsigned LazyInitializeClassMetadata : 1;
177+
174178
/// The path to load legacy type layouts from.
175179
StringRef ReadTypeInfoPath;
176180

@@ -221,10 +225,10 @@ class IRGenOptions {
221225
EmbedMode(IRGenEmbedMode::None), HasValueNamesSetting(false),
222226
ValueNames(false), EnableReflectionMetadata(true),
223227
EnableReflectionNames(true), EnableClassResilience(false),
224-
EnableResilienceBypass(false), UseIncrementalLLVMCodeGen(true),
225-
UseSwiftCall(false), GenerateProfile(false),
226-
EnableDynamicReplacementChaining(false), CmdArgs(),
227-
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
228+
EnableResilienceBypass(false), LazyInitializeClassMetadata(false),
229+
UseIncrementalLLVMCodeGen(true), UseSwiftCall(false),
230+
GenerateProfile(false), EnableDynamicReplacementChaining(false),
231+
CmdArgs(), SanitizeCoverage(llvm::SanitizerCoverageOptions()),
228232
TypeInfoFilter(TypeInfoDumpFilter::All) {}
229233

230234
// Get a hash of all options which influence the llvm compilation but are not

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
10591059
Opts.EnableResilienceBypass = true;
10601060
}
10611061

1062+
// PE/COFF cannot deal with the cross-module reference to the metadata parent
1063+
// (e.g. NativeObject). Force the lazy initialization of the VWT always.
1064+
Opts.LazyInitializeClassMetadata = Triple.isOSBinFormatCOFF();
1065+
10621066
if (const Arg *A = Args.getLastArg(OPT_read_type_info_path_EQ)) {
10631067
Opts.ReadTypeInfoPath = A->getValue();
10641068
}

lib/IRGen/GenClass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ namespace {
276276
return (ClassHasMissingMembers ||
277277
ClassHasResilientMembers ||
278278
ClassHasResilientAncestry ||
279-
ClassHasGenericAncestry);
279+
ClassHasGenericAncestry ||
280+
IGM.getOptions().LazyInitializeClassMetadata);
280281
}
281282

282283
bool doesMetadataRequireRelocation() const {

test/IRGen/dllimport.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public func g() {
4040
// CHECK-NO-OPT-DAG: declare dllimport void @swift_deallocObject(%swift.refcounted*, i32, i32)
4141
// CHECK-NO-OPT-DAG: declare dllimport void @swift_release(%swift.refcounted*)
4242
// CHECK-NO-OPT-DAG: declare dllimport %swift.refcounted* @swift_retain(%swift.refcounted* returned)
43-
// CHECK-NO-OPT-DAG: @"$s9dllexport1cCN" = external dllimport global %swift.type
4443
// CHECK-NO-OPT-DAG: @"$s9dllexport1pMp" = external dllimport global %swift.protocol
4544
// CHECK-NO-OPT-DAG: @"$sytN" = external dllimport global %swift.full_type
4645
// CHECK-NO-OPT-DAG: @"$sBoWV" = external dllimport global i8*
@@ -51,7 +50,6 @@ public func g() {
5150

5251
// CHECK-OPT-DAG: declare dllimport %swift.refcounted* @swift_retain(%swift.refcounted* returned) local_unnamed_addr
5352
// CHECK-OPT-DAG: @"$sBoWV" = external dllimport global i8*
54-
// CHECK-OPT-DAG: @"$s9dllexport1cCN" = external dllimport global %swift.type
5553
// CHECK-OPT-DAG: @"__imp_$s9dllexport1pMp" = external externally_initialized constant %swift.protocol*
5654
// CHECK-OPT-DAG: declare dllimport swiftcc i8* @"$s9dllexport2ciAA1cCvau"()
5755
// CHECK-OPT-DAG: declare dllimport swiftcc %swift.metadata_response @"$s9dllexport1cCMa"(i32)

0 commit comments

Comments
 (0)