diff options
| author | Nick Kledzik <kledzik@apple.com> | 2014-05-30 22:51:04 +0000 |
|---|---|---|
| committer | Nick Kledzik <kledzik@apple.com> | 2014-05-30 22:51:04 +0000 |
| commit | acfad8025008ae6cfea6174c547fbf48f6193666 (patch) | |
| tree | cfa9c0c0c3f6029c746d5bbebe854d124861498e /lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | |
| parent | 5435224a5389ce1173a51a960de6b8e2e2957174 (diff) | |
| download | bcm5719-llvm-acfad8025008ae6cfea6174c547fbf48f6193666.tar.gz bcm5719-llvm-acfad8025008ae6cfea6174c547fbf48f6193666.zip | |
[mach-o] Add support for custom sections
llvm-svn: 209928
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp')
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index 60f2ffbd8e8..4f2edbc4a45 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -83,8 +83,25 @@ static Atom::Scope atomScope(uint8_t scope) { } static DefinedAtom::ContentType atomTypeFromSection(const Section §ion) { - // FIX ME - return DefinedAtom::typeCode; + if (section.attributes & S_ATTR_PURE_INSTRUCTIONS) + return DefinedAtom::typeCode; + if (section.segmentName.equals("__TEXT")) { + if (section.sectionName.equals("__StaticInit")) + return DefinedAtom::typeCode; + if (section.sectionName.equals("__gcc_except_tab")) + return DefinedAtom::typeLSDA; + if (section.sectionName.startswith("__text")) + return DefinedAtom::typeCode; + if (section.sectionName.startswith("__const")) + return DefinedAtom::typeConstant; + } else if (section.segmentName.equals("__DATA")) { + if (section.sectionName.startswith("__data")) + return DefinedAtom::typeData; + if (section.sectionName.startswith("__const")) + return DefinedAtom::typeConstData; + } + + return DefinedAtom::typeUnknown; } static error_code @@ -124,8 +141,19 @@ processSymbol(const NormalizedFile &normalizedFile, MachOFile &file, DefinedAtom::Merge m = DefinedAtom::mergeNo; if (sym.desc & N_WEAK_DEF) m = DefinedAtom::mergeAsWeak; - file.addDefinedAtom(sym.name, atomScope(sym.scope), - atomTypeFromSection(section), m, atomContent, copyRefs); + DefinedAtom::ContentType type = atomTypeFromSection(section); + if (type == DefinedAtom::typeUnknown) { + // Mach-O needs a segment and section name. Concatentate those two + // with a / seperator (e.g. "seg/sect") to fit into the lld model + // of just a section name. + std::string segSectName = section.segmentName.str() + + "/" + section.sectionName.str(); + file.addDefinedAtomInCustomSection(sym.name, atomScope(sym.scope), type, + m, atomContent, segSectName, true); + } else { + file.addDefinedAtom(sym.name, atomScope(sym.scope), type, m, atomContent, + copyRefs); + } } return error_code::success(); } |

