Skip to content

Commit c360ba8

Browse files
committed
Emit typerefs and metadata source strings as relative offsets to globals
MCJIT doesn't like offset relocations into the data sections, so the capture descriptors and their typerefs/metadata source encoded strings will need to be emitted as globals and not go into the reflection data sections.
1 parent c05e48b commit c360ba8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/IRGen/GenReflection.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,19 @@ class ReflectionMetadataBuilder : public ConstantBuilder<> {
183183
});
184184
}
185185

186-
void addTypeRef(Module *ModuleContext, CanType type) {
186+
/// Add a 32-bit relative offset to a mangled typeref string
187+
/// in the typeref reflection section, or globally if 'global' is 'true'.
188+
void addTypeRef(Module *ModuleContext, CanType type, bool global = false) {
187189
assert(type);
188190
Mangle::Mangler mangler(/*DWARFMangling*/false,
189191
/*usePunyCode*/ true,
190192
/*OptimizeProtocolNames*/ false);
191193
mangler.setModuleContext(ModuleContext);
192194
mangler.mangleType(type, 0);
193-
auto mangledName = IGM.getAddrOfStringForTypeRef(mangler.finalize());
195+
auto mangledName = global
196+
? IGM.getAddrOfGlobalString(mangler.finalize(),
197+
/*willBeRelativelyAddressed*/ true)
198+
: IGM.getAddrOfStringForTypeRef(mangler.finalize());
194199
addRelativeAddress(mangledName);
195200
}
196201

@@ -488,7 +493,8 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
488493
MetadataSourceEncoder Encoder(OS);
489494
Encoder.visit(Source);
490495

491-
auto EncodedSource = IGM.getAddrOfStringForTypeRef(OS.str());
496+
auto EncodedSource = IGM.getAddrOfGlobalString(OS.str(),
497+
/*willBeRelativelyAddressed*/ true);
492498
addRelativeAddress(EncodedSource);
493499
}
494500
}
@@ -638,15 +644,16 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
638644

639645
// Now add typerefs of all of the captures.
640646
for (auto CaptureType : CaptureTypes) {
641-
addTypeRef(Callee.getModule().getSwiftModule(), CaptureType);
647+
addTypeRef(Callee.getModule().getSwiftModule(), CaptureType,
648+
/*global*/ true);
642649
}
643650

644651
// Add the pairs that make up the generic param -> metadata source map
645652
// to the struct.
646653
for (auto GenericAndSource : MetadataSources) {
647654
auto GenericParam = GenericAndSource.first->getCanonicalType();
648655
auto Source = GenericAndSource.second;
649-
addTypeRef(nullptr, GenericParam);
656+
addTypeRef(nullptr, GenericParam, /*global*/ true);
650657
addMetadataSource(Source);
651658
}
652659
}

0 commit comments

Comments
 (0)