@@ -623,7 +623,12 @@ class ReflectionMetadataBuilder {
623623
624624 var->setSection (section);
625625
626- IGM.addUsedGlobal (var);
626+ // Only mark the reflection record as used when emitting for the runtime.
627+ // In ReflectionMetadataMode::DebuggerOnly mode we want to allow the linker
628+ // to remove/dead-strip these.
629+ if (IGM.IRGen .Opts .ReflectionMetadata == ReflectionMetadataMode::Runtime) {
630+ IGM.addUsedGlobal (var);
631+ }
627632
628633 disableAddressSanitizer (IGM, var);
629634
@@ -1335,7 +1340,7 @@ llvm::Constant *IRGenModule::getAddrOfFieldName(StringRef Name) {
13351340llvm::Constant *
13361341IRGenModule::getAddrOfBoxDescriptor (SILType BoxedType,
13371342 CanGenericSignature genericSig) {
1338- if (! IRGen.Opts .EnableReflectionMetadata )
1343+ if (IRGen.Opts .ReflectionMetadata != ReflectionMetadataMode::Runtime )
13391344 return llvm::Constant::getNullValue (CaptureDescriptorPtrTy);
13401345
13411346 BoxDescriptorBuilder builder (*this , BoxedType, genericSig);
@@ -1350,7 +1355,7 @@ IRGenModule::getAddrOfCaptureDescriptor(SILFunction &Caller,
13501355 CanSILFunctionType SubstCalleeType,
13511356 SubstitutionMap Subs,
13521357 const HeapLayout &Layout) {
1353- if (! IRGen.Opts .EnableReflectionMetadata )
1358+ if (IRGen.Opts .ReflectionMetadata != ReflectionMetadataMode::Runtime )
13541359 return llvm::Constant::getNullValue (CaptureDescriptorPtrTy);
13551360
13561361 if (CaptureDescriptorBuilder::hasOpenedExistential (OrigCalleeType, Layout))
@@ -1369,7 +1374,7 @@ emitAssociatedTypeMetadataRecord(const RootProtocolConformance *conformance) {
13691374 if (!normalConf)
13701375 return ;
13711376
1372- if (! IRGen.Opts .EnableReflectionMetadata )
1377+ if (IRGen.Opts .ReflectionMetadata != ReflectionMetadataMode::Runtime )
13731378 return ;
13741379
13751380 SmallVector<std::pair<StringRef, CanType>, 2 > AssociatedTypes;
@@ -1428,7 +1433,7 @@ void IRGenerator::emitBuiltinReflectionMetadata() {
14281433}
14291434
14301435void IRGenModule::emitFieldDescriptor (const NominalTypeDecl *D) {
1431- if (! IRGen.Opts .EnableReflectionMetadata )
1436+ if (IRGen.Opts .ReflectionMetadata == ReflectionMetadataMode::None )
14321437 return ;
14331438
14341439 auto T = D->getDeclaredTypeInContext ()->getCanonicalType ();
0 commit comments