@@ -1111,6 +1111,8 @@ void IRGenerator::emitGlobalTopLevel(llvm::StringSet<> *linkerDirectives) {
1111
1111
IRGenModule *IGM = Iter.second ;
1112
1112
IGM->finishEmitAfterTopLevel ();
1113
1113
}
1114
+
1115
+ emitEntryPointInfo ();
1114
1116
}
1115
1117
1116
1118
void IRGenModule::finishEmitAfterTopLevel () {
@@ -1757,6 +1759,47 @@ void IRGenModule::emitVTableStubs() {
1757
1759
}
1758
1760
}
1759
1761
1762
+ static std::string getEntryPointSection (IRGenModule &IGM) {
1763
+ std::string sectionName;
1764
+ switch (IGM.TargetInfo .OutputObjectFormat ) {
1765
+ case llvm::Triple::UnknownObjectFormat:
1766
+ llvm_unreachable (" Don't know how to emit field records table for "
1767
+ " the selected object format." );
1768
+ case llvm::Triple::MachO:
1769
+ sectionName = " __TEXT, __swift5_entry, regular, no_dead_strip" ;
1770
+ break ;
1771
+ case llvm::Triple::ELF:
1772
+ case llvm::Triple::Wasm:
1773
+ sectionName = " swift5_entry" ;
1774
+ break ;
1775
+ case llvm::Triple::XCOFF:
1776
+ case llvm::Triple::COFF:
1777
+ sectionName = " .sw5entr$B" ;
1778
+ break ;
1779
+ }
1780
+ return sectionName;
1781
+ }
1782
+
1783
+ void IRGenerator::emitEntryPointInfo () {
1784
+ if (Opts.IntegratedREPL ) {
1785
+ return ;
1786
+ }
1787
+ SILFunction *entrypoint = nullptr ;
1788
+ if (!(entrypoint = SIL.lookUpFunction (SWIFT_ENTRY_POINT_FUNCTION))) {
1789
+ return ;
1790
+ }
1791
+ auto &IGM = *getGenModule (entrypoint);
1792
+ ConstantInitBuilder builder (IGM);
1793
+ auto entrypointInfo = builder.beginStruct ();
1794
+ entrypointInfo.addRelativeAddress (
1795
+ IGM.getAddrOfSILFunction (entrypoint, NotForDefinition));
1796
+ auto var = entrypointInfo.finishAndCreateGlobal (
1797
+ " \x01 l_entry_point" , Alignment (4 ),
1798
+ /* isConstant*/ true , llvm::GlobalValue::PrivateLinkage);
1799
+ var->setSection (getEntryPointSection (IGM));
1800
+ IGM.addUsedGlobal (var);
1801
+ }
1802
+
1760
1803
static IRLinkage
1761
1804
getIRLinkage (const UniversalLinkageInfo &info, SILLinkage linkage,
1762
1805
ForDefinition_t isDefinition, bool isWeakImported,
0 commit comments