diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 21471ec9ea27..f8f95ce24d41 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -22,7 +22,6 @@ #include "llvm/Support/LEB128.h" using namespace llvm; -using namespace llvm::MachO; using namespace llvm::support; using namespace llvm::support::endian; using namespace lld; @@ -47,20 +46,20 @@ void MachHeaderSection::addLoadCommand(LoadCommand *lc) { } uint64_t MachHeaderSection::getSize() const { - return sizeof(mach_header_64) + sizeOfCmds; + return sizeof(MachO::mach_header_64) + sizeOfCmds; } void MachHeaderSection::writeTo(uint8_t *buf) const { - auto *hdr = reinterpret_cast(buf); - hdr->magic = MH_MAGIC_64; - hdr->cputype = CPU_TYPE_X86_64; - hdr->cpusubtype = CPU_SUBTYPE_X86_64_ALL | CPU_SUBTYPE_LIB64; + auto *hdr = reinterpret_cast(buf); + hdr->magic = MachO::MH_MAGIC_64; + hdr->cputype = MachO::CPU_TYPE_X86_64; + hdr->cpusubtype = MachO::CPU_SUBTYPE_X86_64_ALL | MachO::CPU_SUBTYPE_LIB64; hdr->filetype = config->outputType; hdr->ncmds = loadCommands.size(); hdr->sizeofcmds = sizeOfCmds; - hdr->flags = MH_NOUNDEFS | MH_DYLDLINK | MH_TWOLEVEL; - if (config->outputType == MH_DYLIB && !config->hasReexports) - hdr->flags |= MH_NO_REEXPORTED_DYLIBS; + hdr->flags = MachO::MH_NOUNDEFS | MachO::MH_DYLDLINK | MachO::MH_TWOLEVEL; + if (config->outputType == MachO::MH_DYLIB && !config->hasReexports) + hdr->flags |= MachO::MH_NO_REEXPORTED_DYLIBS; uint8_t *p = reinterpret_cast(hdr + 1); for (LoadCommand *lc : loadCommands) { @@ -75,7 +74,7 @@ PageZeroSection::PageZeroSection() GotSection::GotSection() : SyntheticSection(segment_names::dataConst, section_names::got) { align = 8; - flags = S_NON_LAZY_SYMBOL_POINTERS; + flags = MachO::S_NON_LAZY_SYMBOL_POINTERS; // TODO: section_64::reserved1 should be an index into the indirect symbol // table, which we do not currently emit @@ -116,38 +115,40 @@ void BindingSection::finalizeContents() { return; raw_svector_ostream os{contents}; - os << static_cast(BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | + os << static_cast(MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | in.got->parent->index); encodeULEB128(in.got->getSegmentOffset(), os); uint32_t entries_to_skip = 0; for (const Symbol *sym : in.got->getEntries()) { if (const auto *dysym = dyn_cast(sym)) { if (entries_to_skip != 0) { - os << static_cast(BIND_OPCODE_ADD_ADDR_ULEB); + os << static_cast(MachO::BIND_OPCODE_ADD_ADDR_ULEB); encodeULEB128(WordSize * entries_to_skip, os); entries_to_skip = 0; } // TODO: Implement compact encoding -- we only need to encode the // differences between consecutive symbol entries. - if (dysym->file->ordinal <= BIND_IMMEDIATE_MASK) { - os << static_cast(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | + if (dysym->file->ordinal <= MachO::BIND_IMMEDIATE_MASK) { + os << static_cast(MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | dysym->file->ordinal); } else { error("TODO: Support larger dylib symbol ordinals"); continue; } - os << static_cast(BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM) + os << static_cast( + MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM) << dysym->getName() << '\0' - << static_cast(BIND_OPCODE_SET_TYPE_IMM | BIND_TYPE_POINTER) - << static_cast(BIND_OPCODE_DO_BIND); + << static_cast(MachO::BIND_OPCODE_SET_TYPE_IMM | + MachO::BIND_TYPE_POINTER) + << static_cast(MachO::BIND_OPCODE_DO_BIND); } else { // We have a defined symbol with a pre-populated address; skip over it. ++entries_to_skip; } } - os << static_cast(BIND_OPCODE_DONE); + os << static_cast(MachO::BIND_OPCODE_DONE); } void BindingSection::writeTo(uint8_t *buf) const { @@ -219,7 +220,7 @@ ImageLoaderCacheSection::ImageLoaderCacheSection() { LazyPointerSection::LazyPointerSection() : SyntheticSection(segment_names::data, "__la_symbol_ptr") { align = 8; - flags = S_LAZY_SYMBOL_POINTERS; + flags = MachO::S_LAZY_SYMBOL_POINTERS; } uint64_t LazyPointerSection::getSize() const { @@ -265,20 +266,21 @@ void LazyBindingSection::writeTo(uint8_t *buf) const { uint32_t LazyBindingSection::encode(const DylibSymbol &sym) { uint32_t opstreamOffset = contents.size(); OutputSegment *dataSeg = in.lazyPointers->parent; - os << static_cast(BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | + os << static_cast(MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | dataSeg->index); uint64_t offset = in.lazyPointers->addr - dataSeg->firstSection()->addr + sym.stubsIndex * WordSize; encodeULEB128(offset, os); - if (sym.file->ordinal <= BIND_IMMEDIATE_MASK) - os << static_cast(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | + if (sym.file->ordinal <= MachO::BIND_IMMEDIATE_MASK) + os << static_cast(MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | sym.file->ordinal); else fatal("TODO: Support larger dylib symbol ordinals"); - os << static_cast(BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM) - << sym.getName() << '\0' << static_cast(BIND_OPCODE_DO_BIND) - << static_cast(BIND_OPCODE_DONE); + os << static_cast(MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM) + << sym.getName() << '\0' + << static_cast(MachO::BIND_OPCODE_DO_BIND) + << static_cast(MachO::BIND_OPCODE_DONE); return opstreamOffset; } @@ -321,7 +323,7 @@ void SymtabSection::writeTo(uint8_t *buf) const { // TODO support other symbol types // TODO populate n_desc if (auto *defined = dyn_cast(entry.sym)) { - nList->n_type = N_EXT | N_SECT; + nList->n_type = MachO::N_EXT | MachO::N_SECT; nList->n_sect = defined->isec->parent->index; // For the N_SECT symbol type, n_value is the address of the symbol nList->n_value = defined->value + defined->isec->getVA();