Index: llvm/lib/MC/MCContext.cpp =================================================================== --- llvm/lib/MC/MCContext.cpp +++ llvm/lib/MC/MCContext.cpp @@ -294,8 +294,16 @@ Begin = createTempSymbol(BeginSymName, false); // Otherwise, return a new section. - return Entry = new (MachOAllocator.Allocate()) MCSectionMachO( + auto Result = new (MachOAllocator.Allocate()) MCSectionMachO( Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin); + + auto *F = new MCDataFragment(); + Result->getFragmentList().insert(Result->begin(), F); + F->setParent(Result); + if (Begin) + Begin->setFragment(F); + + return Result; } void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) { Index: llvm/lib/MC/MCObjectFileInfo.cpp =================================================================== --- llvm/lib/MC/MCObjectFileInfo.cpp +++ llvm/lib/MC/MCObjectFileInfo.cpp @@ -950,8 +950,27 @@ } MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const { - return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP, - 0, utostr(Hash)); + switch (TT.getObjectFormat()) { + case Triple::MachO: + return Ctx->getMachOSection("__DWARF", "__debug_types", MachO::S_ATTR_DEBUG, + SectionKind::getMetadata(), + "debug_types_begin"); + case Triple::COFF: + + return Ctx->getCOFFSection(".debug_types", + COFF::IMAGE_SCN_MEM_DISCARDABLE | + COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ, + SectionKind::getMetadata(), "debug_types"); + case Triple::ELF: + return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP, + 0, utostr(Hash)); + case Triple::Wasm: + return Ctx->getWasmSection(".debug_info", SectionKind::getMetadata()); + case Triple::UnknownObjectFormat: + report_fatal_error("DWARF types section for unknown object file format."); + break; + } } MCSection *