@@ -1979,6 +1979,7 @@ void IRGenerator::emitEagerClassInitialization() {
19791979 IGM->DebugInfo ->emitArtificialFunction (RegisterIGF, RegisterIGF.CurFn );
19801980 RegisterFn->setAttributes (IGM->constructInitialAttributes ());
19811981 RegisterFn->setCallingConv (IGM->DefaultCC );
1982+ IGM->setColocateMetadataSection (RegisterFn);
19821983
19831984 for (ClassDecl *CD : ClassesForEagerInitialization) {
19841985 auto Ty = CD->getDeclaredType ()->getCanonicalType ();
@@ -2022,6 +2023,7 @@ void IRGenerator::emitObjCActorsNeedingSuperclassSwizzle() {
20222023 IGM->DebugInfo ->emitArtificialFunction (RegisterIGF, RegisterIGF.CurFn );
20232024 RegisterFn->setAttributes (IGM->constructInitialAttributes ());
20242025 RegisterFn->setCallingConv (IGM->DefaultCC );
2026+ IGM->setColocateMetadataSection (RegisterFn);
20252027
20262028 // Look up the SwiftNativeNSObject class.
20272029 auto swiftNativeNSObjectName =
@@ -5858,3 +5860,23 @@ IRGenModule::getOrCreateHelperFunction(StringRef fnName, llvm::Type *resultTy,
58585860
58595861 return fn;
58605862}
5863+
5864+ void IRGenModule::setColocateMetadataSection (llvm::Function *f) {
5865+ if (!IRGen.Opts .CollocatedMetadataFunctions )
5866+ return ;
5867+
5868+ switch (TargetInfo.OutputObjectFormat ) {
5869+ case llvm::Triple::MachO:
5870+ f->setSection (" __TEXT, __textg_swiftm, regular, pure_instructions" );
5871+ break ;
5872+ case llvm::Triple::DXContainer:
5873+ case llvm::Triple::GOFF:
5874+ case llvm::Triple::SPIRV:
5875+ case llvm::Triple::UnknownObjectFormat:
5876+ case llvm::Triple::Wasm:
5877+ case llvm::Triple::ELF:
5878+ case llvm::Triple::XCOFF:
5879+ case llvm::Triple::COFF:
5880+ break ;
5881+ }
5882+ }
0 commit comments