SVMProgramSection SVMMemoryLayout::getSectionKind(const MCSectionData *SD) const
{
    /*
     * Categorize a MCSection as one of the several predefined
     * SVMProgramSection types. This determines which program section
     * we'll lump it in with, or whether it'll be included as debug-only.
     *
     * This value can be specifically overridden with setSectionKind().
     * If we have no override, we calculate the proper section kind
     * using the section's name, size, type, and other data.
     */

    SectionKindOverrides_t::const_iterator it = SectionKindOverrides.find(SD);
    if (it != SectionKindOverrides.end())
        return it->second;

    const MCSection *S = &SD->getSection();
    SectionKind k = S->getKind();
    const MCSectionELF *SE = dyn_cast<MCSectionELF>(S);
    assert(SE);
    StringRef Name = SE->getSectionName();

    if (Name == ".metadata")
        return SPS_META;

    if (Name.startswith(".debug_"))
        return SPS_DEBUG;

    if (k.isBSS())
        return SPS_BSS;

    if (SE->getType() == ELF::SHT_PROGBITS) {
        if (k.isReadOnly() || k.isText())
            return SPS_RO;
        if (k.isGlobalWriteableData())
            return SPS_RW_PLAIN;
    }

    return SPS_DEBUG;
}