- private:
-
- /// SectionList - This is the list of sections that we have emitted to the
- /// file. Once the file has been completely built, the segment load command
- /// SectionCommands are constructed from this info.
-
- std::vector<MachOSection*> SectionList;
-
- /// SectionLookup - This is a mapping from section name to SectionList entry
-
- std::map<std::string, MachOSection*> SectionLookup;
-
- /// GVSection - This is a mapping from a GlobalValue to a MachOSection,
- /// to aid in emitting relocations.
-
- std::map<GlobalValue*, MachOSection*> GVSection;
-
- /// GVOffset - This is a mapping from a GlobalValue to an offset from the
- /// start of the section in which the GV resides, to aid in emitting
- /// relocations.
-
- std::map<GlobalValue*, intptr_t> GVOffset;
-
- /// getSection - Return the section with the specified name, creating a new
- /// section if one does not already exist.
-
- MachOSection *getSection(const std::string &seg, const std::string §,
- unsigned Flags = 0) {
- MachOSection *MOS = SectionLookup[seg+sect];
- if (MOS) return MOS;
-
- MOS = new MachOSection(seg, sect);
- SectionList.push_back(MOS);
- MOS->Index = SectionList.size();
- MOS->flags = MachOSection::S_REGULAR | Flags;
- SectionLookup[seg+sect] = MOS;
- return MOS;
- }
- MachOSection *getTextSection(bool isCode = true) {
- if (isCode)
- return getSection("__TEXT", "__text",
- MachOSection::S_ATTR_PURE_INSTRUCTIONS |
- MachOSection::S_ATTR_SOME_INSTRUCTIONS);
- else
- return getSection("__TEXT", "__text");
- }
- MachOSection *getBSSSection() {
- return getSection("__DATA", "__bss", MachOSection::S_ZEROFILL);
- }
- MachOSection *getDataSection() {
- return getSection("__DATA", "__data");
- }
- MachOSection *getConstSection(Constant *C) {
- const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
- if (CVA && CVA->isCString())
- return getSection("__TEXT", "__cstring",
- MachOSection::S_CSTRING_LITERALS);
-
- const Type *Ty = C->getType();
- if (Ty->isPrimitiveType() || Ty->isInteger()) {
- unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty);
- switch(Size) {
- default: break; // Fall through to __TEXT,__const
- case 4:
- return getSection("__TEXT", "__literal4",
- MachOSection::S_4BYTE_LITERALS);
- case 8:
- return getSection("__TEXT", "__literal8",
- MachOSection::S_8BYTE_LITERALS);
- case 16:
- return getSection("__TEXT", "__literal16",
- MachOSection::S_16BYTE_LITERALS);
- }
- }
- return getSection("__TEXT", "__const");
- }
- MachOSection *getJumpTableSection() {
- if (TM.getRelocationModel() == Reloc::PIC_)
- return getTextSection(false);
- else
- return getSection("__TEXT", "__const");
- }
-
- /// MachOSymTab - This struct contains information about the offsets and
- /// size of symbol table information.
- /// segment.
- struct MachOSymTab {
- uint32_t cmd; // LC_SYMTAB
- uint32_t cmdsize; // sizeof( MachOSymTab )
- uint32_t symoff; // symbol table offset
- uint32_t nsyms; // number of symbol table entries
- uint32_t stroff; // string table offset
- uint32_t strsize; // string table size in bytes
-
- // Constants for the cmd field
- // see <mach-o/loader.h>
- enum { LC_SYMTAB = 0x02 // link-edit stab symbol table info
- };
-
- MachOSymTab() : cmd(LC_SYMTAB), cmdsize(6 * sizeof(uint32_t)), symoff(0),
- nsyms(0), stroff(0), strsize(0) { }
- };
-
- /// SymTab - The "stab" style symbol table information
- MachOSymTab SymTab;
- /// DySymTab - symbol table info for the dynamic link editor
- MachODySymTab DySymTab;
-
- protected:
-
- /// SymbolTable - This is the list of symbols we have emitted to the file.
- /// This actually gets rearranged before emission to the file (to put the
- /// local symbols first in the list).
- std::vector<MachOSym> SymbolTable;
-
- /// SymT - A buffer to hold the symbol table before we write it out at the
- /// appropriate location in the file.
- DataBuffer SymT;
-
- /// StrT - A buffer to hold the string table before we write it out at the
- /// appropriate location in the file.
- DataBuffer StrT;