[lld] 1752f28 - [lld-macho][nfc] Remove `MachO::` prefix where possible

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 10:28:39 PST 2021


Author: Jez Ng
Date: 2021-03-11T13:28:08-05:00
New Revision: 1752f28506859220d893aa9303b51f386f2e6995

URL: https://github.com/llvm/llvm-project/commit/1752f28506859220d893aa9303b51f386f2e6995
DIFF: https://github.com/llvm/llvm-project/commit/1752f28506859220d893aa9303b51f386f2e6995.diff

LOG: [lld-macho][nfc] Remove `MachO::` prefix where possible

Previously, SyntheticSections.cpp did not have a top-level `using namespace
llvm::MachO` because it caused a naming conflict: `llvm::MachO::Symbol` would
collide with `lld::macho::Symbol`.

`MachO::Symbol` represents the symbols defined in InterfaceFiles (TBDs). By
moving the inclusion of InterfaceFile.h into our .cpp files, we can avoid this
name collision in other files where we are only dealing with LLD's own symbols.

Along the way, I removed all unnecessary "MachO::" prefixes in our code.

Cons of this approach: If TextAPI/MachO/Symbol.h gets included via some other
header file in the future, we could run into this collision again.

Alternative 1: Have either TextAPI/MachO or BinaryFormat/MachO.h use a different
namespace. Most of the benefit of `using namespace llvm::MachO` comes from being
able to use things in BinaryFormat/MachO.h conveniently; if TextAPI was under a
different (and fully-qualified) namespace like `llvm::tapi` that would solve our
problems. Cons: lots of files across llvm-project will need to be updated, and
folks who own the TextAPI code need to agree to the name change.

Alternative 2: Rename our Symbol to something like `LldSymbol`. I think this is
ugly.

Personally I think alternative #1 is ideal, but I'm not sure the effort to do it is
worthwhile, this diff's halfway solution seems good enough to me. Thoughts?

Reviewed By: #lld-macho, oontvoo, MaskRay

Differential Revision: https://reviews.llvm.org/D98149

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/DriverUtils.cpp
    lld/MachO/InputFiles.cpp
    lld/MachO/InputFiles.h
    lld/MachO/InputSection.cpp
    lld/MachO/MergedOutputSection.cpp
    lld/MachO/SyntheticSections.cpp
    lld/MachO/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 29582e00d0c9..995c18bb9121 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -589,13 +589,12 @@ static TargetInfo *createTargetInfo(InputArgList &args) {
     fatal("must specify -arch");
   PlatformKind platform = parsePlatformVersion(args);
 
-  config->target =
-      MachO::Target(MachO::getArchitectureFromName(archName), platform);
+  config->target = Target(getArchitectureFromName(archName), platform);
 
-  switch (MachO::getCPUTypeFromArchitecture(config->target.Arch).first) {
-  case MachO::CPU_TYPE_X86_64:
+  switch (getCPUTypeFromArchitecture(config->target.Arch).first) {
+  case CPU_TYPE_X86_64:
     return createX86_64TargetInfo();
-  case MachO::CPU_TYPE_ARM64:
+  case CPU_TYPE_ARM64:
     return createARM64TargetInfo();
   default:
     fatal("missing or unsupported -arch " + archName);

diff  --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index ede2f971a94f..faa9b760d904 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/TextAPI/MachO/InterfaceFile.h"
 #include "llvm/TextAPI/MachO/TextAPIReader.h"
 
 using namespace llvm;

diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 9b677223aa50..1f73e893c2c7 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -67,6 +67,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TarWriter.h"
 #include "llvm/TextAPI/MachO/Architecture.h"
+#include "llvm/TextAPI/MachO/InterfaceFile.h"
 
 using namespace llvm;
 using namespace llvm::MachO;
@@ -111,9 +112,9 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
 
   // If this is a regular non-fat file, return it.
   const char *buf = mbref.getBufferStart();
-  auto *hdr = reinterpret_cast<const MachO::fat_header *>(buf);
+  const auto *hdr = reinterpret_cast<const fat_header *>(buf);
   if (mbref.getBufferSize() < sizeof(uint32_t) ||
-      read32be(&hdr->magic) != MachO::FAT_MAGIC) {
+      read32be(&hdr->magic) != FAT_MAGIC) {
     if (tar)
       tar->append(relativeToRoot(path), mbref.getBuffer());
     return mbref;
@@ -123,7 +124,7 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
   // multiple real files for 
diff erent CPU ISAs. Here, we search for a
   // file that matches with the current link target and returns it as
   // a MemoryBufferRef.
-  auto *arch = reinterpret_cast<const MachO::fat_arch *>(buf + sizeof(*hdr));
+  const auto *arch = reinterpret_cast<const fat_arch *>(buf + sizeof(*hdr));
 
   for (uint32_t i = 0, n = read32be(&hdr->nfat_arch); i < n; ++i) {
     if (reinterpret_cast<const char *>(arch + i + 1) >
@@ -149,6 +150,9 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
   return None;
 }
 
+InputFile::InputFile(Kind kind, const InterfaceFile &interface)
+    : id(idCount++), fileKind(kind), name(saver.save(interface.getPath())) {}
+
 void ObjFile::parseSections(ArrayRef<section_64> sections) {
   subsections.reserve(sections.size());
   auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
@@ -500,8 +504,7 @@ ObjFile::ObjFile(MemoryBufferRef mb, uint32_t modTime, StringRef archiveName)
   auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
   auto *hdr = reinterpret_cast<const mach_header_64 *>(mb.getBufferStart());
 
-  MachO::Architecture arch =
-      MachO::getArchitectureFromCpuType(hdr->cputype, hdr->cpusubtype);
+  Architecture arch = getArchitectureFromCpuType(hdr->cputype, hdr->cpusubtype);
   if (arch != config->target.Arch) {
     error(toString(this) + " has architecture " + getArchitectureName(arch) +
           " which is incompatible with target architecture " +

diff  --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index e122c4cb10b7..6d6cabe42cf4 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -19,7 +19,6 @@
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/TextAPI/MachO/InterfaceFile.h"
 #include "llvm/TextAPI/MachO/TextAPIReader.h"
 
 #include <map>
@@ -29,6 +28,9 @@ namespace llvm {
 namespace lto {
 class InputFile;
 } // namespace lto
+namespace MachO {
+class InterfaceFile;
+} // namespace MachO
 class TarWriter;
 } // namespace llvm
 
@@ -78,8 +80,7 @@ class InputFile {
   InputFile(Kind kind, MemoryBufferRef mb)
       : mb(mb), id(idCount++), fileKind(kind), name(mb.getBufferIdentifier()) {}
 
-  InputFile(Kind kind, const llvm::MachO::InterfaceFile &interface)
-      : id(idCount++), fileKind(kind), name(saver.save(interface.getPath())) {}
+  InputFile(Kind, const llvm::MachO::InterfaceFile &);
 
 private:
   const Kind fileKind;

diff  --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 8e996e324d26..18c2543ddf6c 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -90,11 +90,11 @@ void InputSection::writeTo(uint8_t *buf) {
 }
 
 bool macho::isCodeSection(InputSection *isec) {
-  uint32_t type = isec->flags & MachO::SECTION_TYPE;
+  uint32_t type = isec->flags & SECTION_TYPE;
   if (type != S_REGULAR && type != S_COALESCED)
     return false;
 
-  uint32_t attr = isec->flags & MachO::SECTION_ATTRIBUTES_USR;
+  uint32_t attr = isec->flags & SECTION_ATTRIBUTES_USR;
   if (attr == S_ATTR_PURE_INSTRUCTIONS)
     return true;
 

diff  --git a/lld/MachO/MergedOutputSection.cpp b/lld/MachO/MergedOutputSection.cpp
index 2d0be2538347..15e957250dd0 100644
--- a/lld/MachO/MergedOutputSection.cpp
+++ b/lld/MachO/MergedOutputSection.cpp
@@ -54,19 +54,18 @@ void MergedOutputSection::writeTo(uint8_t *buf) const {
 // are actually merged. The logic presented here was written without
 // any form of informed research.
 void MergedOutputSection::mergeFlags(uint32_t inputFlags) {
-  uint8_t sectionFlag = MachO::SECTION_TYPE & inputFlags;
-  if (sectionFlag != (MachO::SECTION_TYPE & flags))
+  uint8_t sectionFlag = SECTION_TYPE & inputFlags;
+  if (sectionFlag != (SECTION_TYPE & flags))
     error("Cannot add merge section; inconsistent type flags " +
           Twine(sectionFlag));
 
-  uint32_t inconsistentFlags =
-      MachO::S_ATTR_DEBUG | MachO::S_ATTR_STRIP_STATIC_SYMS |
-      MachO::S_ATTR_NO_DEAD_STRIP | MachO::S_ATTR_LIVE_SUPPORT;
+  uint32_t inconsistentFlags = S_ATTR_DEBUG | S_ATTR_STRIP_STATIC_SYMS |
+                               S_ATTR_NO_DEAD_STRIP | S_ATTR_LIVE_SUPPORT;
   if ((inputFlags ^ flags) & inconsistentFlags)
     error("Cannot add merge section; cannot merge inconsistent flags");
 
   // Negate pure instruction presence if any section isn't pure.
-  uint32_t pureMask = ~MachO::S_ATTR_PURE_INSTRUCTIONS | (inputFlags & flags);
+  uint32_t pureMask = ~S_ATTR_PURE_INSTRUCTIONS | (inputFlags & flags);
 
   // Merge the rest
   flags |= inputFlags;

diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 501fac0b6653..f679e1d7c6c6 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -31,6 +31,7 @@
 #endif
 
 using namespace llvm;
+using namespace llvm::MachO;
 using namespace llvm::support;
 using namespace llvm::support::endian;
 using namespace lld;
@@ -55,53 +56,53 @@ void MachHeaderSection::addLoadCommand(LoadCommand *lc) {
 }
 
 uint64_t MachHeaderSection::getSize() const {
-  return sizeof(MachO::mach_header_64) + sizeOfCmds + config->headerPad;
+  return sizeof(mach_header_64) + sizeOfCmds + config->headerPad;
 }
 
 static uint32_t cpuSubtype() {
   uint32_t subtype = target->cpuSubtype;
 
-  if (config->outputType == MachO::MH_EXECUTE && !config->staticLink &&
-      target->cpuSubtype == MachO::CPU_SUBTYPE_X86_64_ALL &&
-      config->target.Platform == MachO::PlatformKind::macOS &&
+  if (config->outputType == MH_EXECUTE && !config->staticLink &&
+      target->cpuSubtype == CPU_SUBTYPE_X86_64_ALL &&
+      config->target.Platform == PlatformKind::macOS &&
       config->platformInfo.minimum >= VersionTuple(10, 5))
-    subtype |= MachO::CPU_SUBTYPE_LIB64;
+    subtype |= CPU_SUBTYPE_LIB64;
 
   return subtype;
 }
 
 void MachHeaderSection::writeTo(uint8_t *buf) const {
-  auto *hdr = reinterpret_cast<MachO::mach_header_64 *>(buf);
-  hdr->magic = MachO::MH_MAGIC_64;
+  auto *hdr = reinterpret_cast<mach_header_64 *>(buf);
+  hdr->magic = MH_MAGIC_64;
   hdr->cputype = target->cpuType;
   hdr->cpusubtype = cpuSubtype();
   hdr->filetype = config->outputType;
   hdr->ncmds = loadCommands.size();
   hdr->sizeofcmds = sizeOfCmds;
-  hdr->flags = MachO::MH_DYLDLINK;
+  hdr->flags = MH_DYLDLINK;
 
   if (config->namespaceKind == NamespaceKind::twolevel)
-    hdr->flags |= MachO::MH_NOUNDEFS | MachO::MH_TWOLEVEL;
+    hdr->flags |= MH_NOUNDEFS | MH_TWOLEVEL;
 
-  if (config->outputType == MachO::MH_DYLIB && !config->hasReexports)
-    hdr->flags |= MachO::MH_NO_REEXPORTED_DYLIBS;
+  if (config->outputType == MH_DYLIB && !config->hasReexports)
+    hdr->flags |= MH_NO_REEXPORTED_DYLIBS;
 
   if (config->markDeadStrippableDylib)
-    hdr->flags |= MachO::MH_DEAD_STRIPPABLE_DYLIB;
+    hdr->flags |= MH_DEAD_STRIPPABLE_DYLIB;
 
-  if (config->outputType == MachO::MH_EXECUTE && config->isPic)
-    hdr->flags |= MachO::MH_PIE;
+  if (config->outputType == MH_EXECUTE && config->isPic)
+    hdr->flags |= MH_PIE;
 
   if (in.exports->hasWeakSymbol || in.weakBinding->hasNonWeakDefinition())
-    hdr->flags |= MachO::MH_WEAK_DEFINES;
+    hdr->flags |= MH_WEAK_DEFINES;
 
   if (in.exports->hasWeakSymbol || in.weakBinding->hasEntry())
-    hdr->flags |= MachO::MH_BINDS_TO_WEAK;
+    hdr->flags |= MH_BINDS_TO_WEAK;
 
   for (const OutputSegment *seg : outputSegments) {
     for (const OutputSection *osec : seg->getSections()) {
       if (isThreadLocalVariables(osec->flags)) {
-        hdr->flags |= MachO::MH_HAS_TLV_DESCRIPTORS;
+        hdr->flags |= MH_HAS_TLV_DESCRIPTORS;
         break;
       }
     }
@@ -138,7 +139,6 @@ struct Rebase {
 // using a single DO_REBASE opcode. To take advantage of it, we delay emitting
 // `DO_REBASE` until we have reached the end of a contiguous sequence.
 static void encodeDoRebase(Rebase &rebase, raw_svector_ostream &os) {
-  using namespace llvm::MachO;
   assert(rebase.consecutiveCount != 0);
   if (rebase.consecutiveCount <= REBASE_IMMEDIATE_MASK) {
     os << static_cast<uint8_t>(REBASE_OPCODE_DO_REBASE_IMM_TIMES |
@@ -152,7 +152,6 @@ static void encodeDoRebase(Rebase &rebase, raw_svector_ostream &os) {
 
 static void encodeRebase(const OutputSection *osec, uint64_t outSecOff,
                          Rebase &lastRebase, raw_svector_ostream &os) {
-  using namespace llvm::MachO;
   OutputSegment *seg = osec->parent;
   uint64_t offset = osec->getSegmentOffset() + outSecOff;
   if (lastRebase.segment != seg || lastRebase.offset != offset) {
@@ -178,7 +177,6 @@ static void encodeRebase(const OutputSection *osec, uint64_t outSecOff,
 }
 
 void RebaseSection::finalizeContents() {
-  using namespace llvm::MachO;
   if (locations.empty())
     return;
 
@@ -212,7 +210,7 @@ NonLazyPointerSectionBase::NonLazyPointerSectionBase(const char *segname,
                                                      const char *name)
     : SyntheticSection(segname, name) {
   align = WordSize;
-  flags = MachO::S_NON_LAZY_SYMBOL_POINTERS;
+  flags = S_NON_LAZY_SYMBOL_POINTERS;
 }
 
 void NonLazyPointerSectionBase::addEntry(Symbol *sym) {
@@ -252,7 +250,6 @@ static void encodeBinding(const Symbol *sym, const OutputSection *osec,
                           uint64_t outSecOff, int64_t addend,
                           bool isWeakBinding, Binding &lastBinding,
                           raw_svector_ostream &os) {
-  using namespace llvm::MachO;
   OutputSegment *seg = osec->parent;
   uint64_t offset = osec->getSegmentOffset() + outSecOff;
   if (lastBinding.segment != seg) {
@@ -287,12 +284,11 @@ static void encodeBinding(const Symbol *sym, const OutputSection *osec,
 // Non-weak bindings need to have their dylib ordinal encoded as well.
 static int16_t ordinalForDylibSymbol(const DylibSymbol &dysym) {
   return config->namespaceKind == NamespaceKind::flat || dysym.isDynamicLookup()
-             ? (int16_t)MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP
+             ? static_cast<int16_t>(BIND_SPECIAL_DYLIB_FLAT_LOOKUP)
              : dysym.getFile()->ordinal;
 }
 
 static void encodeDylibOrdinal(int16_t ordinal, raw_svector_ostream &os) {
-  using namespace llvm::MachO;
   if (ordinal <= 0) {
     os << static_cast<uint8_t>(BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
                                (ordinal & BIND_IMMEDIATE_MASK));
@@ -306,7 +302,6 @@ static void encodeDylibOrdinal(int16_t ordinal, raw_svector_ostream &os) {
 
 static void encodeWeakOverride(const Defined *defined,
                                raw_svector_ostream &os) {
-  using namespace llvm::MachO;
   os << static_cast<uint8_t>(BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM |
                              BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION)
      << defined->getName() << '\0';
@@ -351,7 +346,7 @@ void BindingSection::finalizeContents() {
     }
   }
   if (!bindings.empty())
-    os << static_cast<uint8_t>(MachO::BIND_OPCODE_DONE);
+    os << static_cast<uint8_t>(BIND_OPCODE_DONE);
 }
 
 void BindingSection::writeTo(uint8_t *buf) const {
@@ -385,7 +380,7 @@ void WeakBindingSection::finalizeContents() {
     }
   }
   if (!bindings.empty() || !definitions.empty())
-    os << static_cast<uint8_t>(MachO::BIND_OPCODE_DONE);
+    os << static_cast<uint8_t>(BIND_OPCODE_DONE);
 }
 
 void WeakBindingSection::writeTo(uint8_t *buf) const {
@@ -422,8 +417,7 @@ void macho::addNonLazyBindingEntries(const Symbol *sym,
 
 StubsSection::StubsSection()
     : SyntheticSection(segment_names::text, "__stubs") {
-  flags = MachO::S_SYMBOL_STUBS | MachO::S_ATTR_SOME_INSTRUCTIONS |
-          MachO::S_ATTR_PURE_INSTRUCTIONS;
+  flags = S_SYMBOL_STUBS | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
   // The stubs section comprises machine instructions, which are aligned to
   // 4 bytes on the archs we care about.
   align = 4;
@@ -451,7 +445,7 @@ bool StubsSection::addEntry(Symbol *sym) {
 
 StubHelperSection::StubHelperSection()
     : SyntheticSection(segment_names::text, "__stub_helper") {
-  flags = MachO::S_ATTR_SOME_INSTRUCTIONS | MachO::S_ATTR_PURE_INSTRUCTIONS;
+  flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
   align = 4; // This section comprises machine instructions
 }
 
@@ -499,7 +493,7 @@ ImageLoaderCacheSection::ImageLoaderCacheSection() {
 LazyPointerSection::LazyPointerSection()
     : SyntheticSection(segment_names::data, "__la_symbol_ptr") {
   align = WordSize;
-  flags = MachO::S_LAZY_SYMBOL_POINTERS;
+  flags = S_LAZY_SYMBOL_POINTERS;
 }
 
 uint64_t LazyPointerSection::getSize() const {
@@ -557,20 +551,20 @@ void LazyBindingSection::addEntry(DylibSymbol *dysym) {
 uint32_t LazyBindingSection::encode(const DylibSymbol &sym) {
   uint32_t opstreamOffset = contents.size();
   OutputSegment *dataSeg = in.lazyPointers->parent;
-  os << static_cast<uint8_t>(MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB |
+  os << static_cast<uint8_t>(BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB |
                              dataSeg->index);
   uint64_t offset = in.lazyPointers->addr - dataSeg->firstSection()->addr +
                     sym.stubsIndex * WordSize;
   encodeULEB128(offset, os);
   encodeDylibOrdinal(ordinalForDylibSymbol(sym), os);
 
-  uint8_t flags = MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM;
+  uint8_t flags = BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM;
   if (sym.isWeakRef())
-    flags |= MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT;
+    flags |= BIND_SYMBOL_FLAGS_WEAK_IMPORT;
 
   os << flags << sym.getName() << '\0'
-     << static_cast<uint8_t>(MachO::BIND_OPCODE_DO_BIND)
-     << static_cast<uint8_t>(MachO::BIND_OPCODE_DONE);
+     << static_cast<uint8_t>(BIND_OPCODE_DO_BIND)
+     << static_cast<uint8_t>(BIND_OPCODE_DONE);
   return opstreamOffset;
 }
 
@@ -658,7 +652,7 @@ uint64_t SymtabSection::getRawSize() const {
 }
 
 void SymtabSection::emitBeginSourceStab(DWARFUnit *compileUnit) {
-  StabsEntry stab(MachO::N_SO);
+  StabsEntry stab(N_SO);
   SmallString<261> dir(compileUnit->getCompilationDir());
   StringRef sep = sys::path::get_separator();
   // We don't use `path::append` here because we want an empty `dir` to result
@@ -671,13 +665,13 @@ void SymtabSection::emitBeginSourceStab(DWARFUnit *compileUnit) {
 }
 
 void SymtabSection::emitEndSourceStab() {
-  StabsEntry stab(MachO::N_SO);
+  StabsEntry stab(N_SO);
   stab.sect = 1;
   stabs.emplace_back(std::move(stab));
 }
 
 void SymtabSection::emitObjectFileStab(ObjFile *file) {
-  StabsEntry stab(MachO::N_OSO);
+  StabsEntry stab(N_OSO);
   stab.sect = target->cpuSubtype;
   SmallString<261> path(!file->archiveName.empty() ? file->archiveName
                                                    : file->getName());
@@ -695,7 +689,7 @@ void SymtabSection::emitObjectFileStab(ObjFile *file) {
 }
 
 void SymtabSection::emitEndFunStab(Defined *defined) {
-  StabsEntry stab(MachO::N_FUN);
+  StabsEntry stab(N_FUN);
   // FIXME this should be the size of the symbol. Using the section size in
   // lieu is only correct if .subsections_via_symbols is set.
   stab.value = defined->isec->getSize();
@@ -746,11 +740,11 @@ void SymtabSection::emitStabs() {
     symStab.value = defined->getVA();
 
     if (isCodeSection(isec)) {
-      symStab.type = MachO::N_FUN;
+      symStab.type = N_FUN;
       stabs.emplace_back(std::move(symStab));
       emitEndFunStab(defined);
     } else {
-      symStab.type = defined->isExternal() ? MachO::N_GSYM : MachO::N_STSYM;
+      symStab.type = defined->isExternal() ? N_GSYM : N_STSYM;
       stabs.emplace_back(std::move(symStab));
     }
   }
@@ -837,41 +831,41 @@ void SymtabSection::writeTo(uint8_t *buf) const {
         // Private external -- dylib scoped symbol.
         // Promote to non-external at link time.
         assert(defined->isExternal() && "invalid input file");
-        scope = MachO::N_PEXT;
+        scope = N_PEXT;
       } else if (defined->isExternal()) {
         // Normal global symbol.
-        scope = MachO::N_EXT;
+        scope = N_EXT;
       } else {
         // TU-local symbol from localSymbols.
         scope = 0;
       }
 
       if (defined->isAbsolute()) {
-        nList->n_type = scope | MachO::N_ABS;
-        nList->n_sect = MachO::NO_SECT;
+        nList->n_type = scope | N_ABS;
+        nList->n_sect = NO_SECT;
         nList->n_value = defined->value;
       } else {
-        nList->n_type = scope | MachO::N_SECT;
+        nList->n_type = scope | 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->getVA();
       }
-      nList->n_desc |= defined->isExternalWeakDef() ? MachO::N_WEAK_DEF : 0;
+      nList->n_desc |= defined->isExternalWeakDef() ? N_WEAK_DEF : 0;
     } else if (auto *dysym = dyn_cast<DylibSymbol>(entry.sym)) {
       uint16_t n_desc = nList->n_desc;
       int16_t ordinal = ordinalForDylibSymbol(*dysym);
-      if (ordinal == MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP)
-        MachO::SET_LIBRARY_ORDINAL(n_desc, MachO::DYNAMIC_LOOKUP_ORDINAL);
-      else if (ordinal == MachO::BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE)
-        MachO::SET_LIBRARY_ORDINAL(n_desc, MachO::EXECUTABLE_ORDINAL);
+      if (ordinal == BIND_SPECIAL_DYLIB_FLAT_LOOKUP)
+        SET_LIBRARY_ORDINAL(n_desc, DYNAMIC_LOOKUP_ORDINAL);
+      else if (ordinal == BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE)
+        SET_LIBRARY_ORDINAL(n_desc, EXECUTABLE_ORDINAL);
       else {
         assert(ordinal > 0);
-        MachO::SET_LIBRARY_ORDINAL(n_desc, static_cast<uint8_t>(ordinal));
+        SET_LIBRARY_ORDINAL(n_desc, static_cast<uint8_t>(ordinal));
       }
 
-      nList->n_type = MachO::N_EXT;
-      n_desc |= dysym->isWeakDef() ? MachO::N_WEAK_DEF : 0;
-      n_desc |= dysym->isWeakRef() ? MachO::N_WEAK_REF : 0;
+      nList->n_type = N_EXT;
+      n_desc |= dysym->isWeakDef() ? N_WEAK_DEF : 0;
+      n_desc |= dysym->isWeakRef() ? N_WEAK_REF : 0;
       nList->n_desc = n_desc;
     }
     ++nList;
@@ -905,7 +899,7 @@ void IndirectSymtabSection::finalizeContents() {
 
 static uint32_t indirectValue(const Symbol *sym) {
   return sym->symtabIndex != UINT32_MAX ? sym->symtabIndex
-                                        : MachO::INDIRECT_SYMBOL_LOCAL;
+                                        : INDIRECT_SYMBOL_LOCAL;
 }
 
 void IndirectSymtabSection::writeTo(uint8_t *buf) const {
@@ -992,7 +986,6 @@ void CodeSignatureSection::writeHashes(uint8_t *buf) const {
 }
 
 void CodeSignatureSection::writeTo(uint8_t *buf) const {
-  using namespace llvm::MachO;
   uint32_t signatureSize = static_cast<uint32_t>(getSize());
   auto *superBlob = reinterpret_cast<CS_SuperBlob *>(buf);
   write32be(&superBlob->magic, CSMAGIC_EMBEDDED_SIGNATURE);

diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index e775afe19a2a..78245f5d5f7e 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -552,7 +552,7 @@ void Writer::createLoadCommands() {
   for (InputFile *file : inputFiles) {
     if (auto *dylibFile = dyn_cast<DylibFile>(file)) {
       if (dylibFile->isBundleLoader) {
-        dylibFile->ordinal = MachO::BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE;
+        dylibFile->ordinal = BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE;
         // Shortcut since bundle-loader does not re-export the symbols.
 
         dylibFile->reexport = false;


        


More information about the llvm-commits mailing list