in MachODump.cpp [4550:4680]
static void PrintSection(const char *sectname, const char *segname,
uint64_t addr, uint64_t size, uint32_t offset,
uint32_t align, uint32_t reloff, uint32_t nreloc,
uint32_t flags, uint32_t reserved1, uint32_t reserved2,
uint32_t cmd, const char *sg_segname,
uint32_t filetype, uint32_t object_size,
bool verbose) {
outs() << "Section\n";
outs() << " sectname " << format("%.16s\n", sectname);
outs() << " segname " << format("%.16s", segname);
if (filetype != MachO::MH_OBJECT && strncmp(sg_segname, segname, 16) != 0)
outs() << " (does not match segment)\n";
else
outs() << "\n";
if (cmd == MachO::LC_SEGMENT_64) {
outs() << " addr " << format("0x%016" PRIx64, addr) << "\n";
outs() << " size " << format("0x%016" PRIx64, size);
} else {
outs() << " addr " << format("0x%08" PRIx64, addr) << "\n";
outs() << " size " << format("0x%08" PRIx64, size);
}
if ((flags & MachO::S_ZEROFILL) != 0 && offset + size > object_size)
outs() << " (past end of file)\n";
else
outs() << "\n";
outs() << " offset " << offset;
if (offset > object_size)
outs() << " (past end of file)\n";
else
outs() << "\n";
uint32_t align_shifted = 1 << align;
outs() << " align 2^" << align << " (" << align_shifted << ")\n";
outs() << " reloff " << reloff;
if (reloff > object_size)
outs() << " (past end of file)\n";
else
outs() << "\n";
outs() << " nreloc " << nreloc;
if (reloff + nreloc * sizeof(struct MachO::relocation_info) > object_size)
outs() << " (past end of file)\n";
else
outs() << "\n";
uint32_t section_type = flags & MachO::SECTION_TYPE;
if (verbose) {
outs() << " type";
if (section_type == MachO::S_REGULAR)
outs() << " S_REGULAR\n";
else if (section_type == MachO::S_ZEROFILL)
outs() << " S_ZEROFILL\n";
else if (section_type == MachO::S_CSTRING_LITERALS)
outs() << " S_CSTRING_LITERALS\n";
else if (section_type == MachO::S_4BYTE_LITERALS)
outs() << " S_4BYTE_LITERALS\n";
else if (section_type == MachO::S_8BYTE_LITERALS)
outs() << " S_8BYTE_LITERALS\n";
else if (section_type == MachO::S_16BYTE_LITERALS)
outs() << " S_16BYTE_LITERALS\n";
else if (section_type == MachO::S_LITERAL_POINTERS)
outs() << " S_LITERAL_POINTERS\n";
else if (section_type == MachO::S_NON_LAZY_SYMBOL_POINTERS)
outs() << " S_NON_LAZY_SYMBOL_POINTERS\n";
else if (section_type == MachO::S_LAZY_SYMBOL_POINTERS)
outs() << " S_LAZY_SYMBOL_POINTERS\n";
else if (section_type == MachO::S_SYMBOL_STUBS)
outs() << " S_SYMBOL_STUBS\n";
else if (section_type == MachO::S_MOD_INIT_FUNC_POINTERS)
outs() << " S_MOD_INIT_FUNC_POINTERS\n";
else if (section_type == MachO::S_MOD_TERM_FUNC_POINTERS)
outs() << " S_MOD_TERM_FUNC_POINTERS\n";
else if (section_type == MachO::S_COALESCED)
outs() << " S_COALESCED\n";
else if (section_type == MachO::S_INTERPOSING)
outs() << " S_INTERPOSING\n";
else if (section_type == MachO::S_DTRACE_DOF)
outs() << " S_DTRACE_DOF\n";
else if (section_type == MachO::S_LAZY_DYLIB_SYMBOL_POINTERS)
outs() << " S_LAZY_DYLIB_SYMBOL_POINTERS\n";
else if (section_type == MachO::S_THREAD_LOCAL_REGULAR)
outs() << " S_THREAD_LOCAL_REGULAR\n";
else if (section_type == MachO::S_THREAD_LOCAL_ZEROFILL)
outs() << " S_THREAD_LOCAL_ZEROFILL\n";
else if (section_type == MachO::S_THREAD_LOCAL_VARIABLES)
outs() << " S_THREAD_LOCAL_VARIABLES\n";
else if (section_type == MachO::S_THREAD_LOCAL_VARIABLE_POINTERS)
outs() << " S_THREAD_LOCAL_VARIABLE_POINTERS\n";
else if (section_type == MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS)
outs() << " S_THREAD_LOCAL_INIT_FUNCTION_POINTERS\n";
else
outs() << format("0x%08" PRIx32, section_type) << "\n";
outs() << "attributes";
uint32_t section_attributes = flags & MachO::SECTION_ATTRIBUTES;
if (section_attributes & MachO::S_ATTR_PURE_INSTRUCTIONS)
outs() << " PURE_INSTRUCTIONS";
if (section_attributes & MachO::S_ATTR_NO_TOC)
outs() << " NO_TOC";
if (section_attributes & MachO::S_ATTR_STRIP_STATIC_SYMS)
outs() << " STRIP_STATIC_SYMS";
if (section_attributes & MachO::S_ATTR_NO_DEAD_STRIP)
outs() << " NO_DEAD_STRIP";
if (section_attributes & MachO::S_ATTR_LIVE_SUPPORT)
outs() << " LIVE_SUPPORT";
if (section_attributes & MachO::S_ATTR_SELF_MODIFYING_CODE)
outs() << " SELF_MODIFYING_CODE";
if (section_attributes & MachO::S_ATTR_DEBUG)
outs() << " DEBUG";
if (section_attributes & MachO::S_ATTR_SOME_INSTRUCTIONS)
outs() << " SOME_INSTRUCTIONS";
if (section_attributes & MachO::S_ATTR_EXT_RELOC)
outs() << " EXT_RELOC";
if (section_attributes & MachO::S_ATTR_LOC_RELOC)
outs() << " LOC_RELOC";
if (section_attributes == 0)
outs() << " (none)";
outs() << "\n";
} else
outs() << " flags " << format("0x%08" PRIx32, flags) << "\n";
outs() << " reserved1 " << reserved1;
if (section_type == MachO::S_SYMBOL_STUBS ||
section_type == MachO::S_LAZY_SYMBOL_POINTERS ||
section_type == MachO::S_LAZY_DYLIB_SYMBOL_POINTERS ||
section_type == MachO::S_NON_LAZY_SYMBOL_POINTERS ||
section_type == MachO::S_THREAD_LOCAL_VARIABLE_POINTERS)
outs() << " (index into indirect symbol table)\n";
else
outs() << "\n";
outs() << " reserved2 " << reserved2;
if (section_type == MachO::S_SYMBOL_STUBS)
outs() << " (size of stubs)\n";
else
outs() << "\n";
}