Skip to content

Commit c05815a

Browse files
committed
IRGen: make the section mapping more explicit
We would previously default to ELF. Although the behaviur here is preserved, we are explicitly mapping the section/segment name based on the output object format. NFC.
1 parent 9db508a commit c05815a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,6 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
912912
auto targetMachine = irgen.createTargetMachine();
913913
if (!targetMachine) return;
914914

915-
const llvm::Triple &Triple = Ctx.LangOpts.Target;
916915
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, VMContext,
917916
OutputPath, Opts.getSingleOutputFilename());
918917
initLLVMModule(IGM);
@@ -924,13 +923,19 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
924923
llvm::GlobalVariable::InternalLinkage,
925924
Data, "__Swift_AST");
926925
std::string Section;
927-
if (Triple.isOSBinFormatMachO())
928-
Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName;
929-
else if (Triple.isOSBinFormatCOFF())
926+
switch (IGM.TargetInfo.OutputObjectFormat) {
927+
case llvm::Triple::UnknownObjectFormat:
928+
llvm_unreachable("unknown object format");
929+
case llvm::Triple::COFF:
930930
Section = COFFASTSectionName;
931-
else
931+
break;
932+
case llvm::Triple::ELF:
932933
Section = ELFASTSectionName;
933-
934+
break;
935+
case llvm::Triple::MachO:
936+
Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName;
937+
break;
938+
}
934939
ASTSym->setSection(Section);
935940
ASTSym->setAlignment(8);
936941
::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, IGM.getModule(),

0 commit comments

Comments
 (0)