[lld-macho][NFC] Drop unnecessary macho:: namespace prefix on unambiguous references...
authorGreg McGary <gkm@fb.com>
Tue, 30 Mar 2021 00:19:29 +0000 (17:19 -0700)
committerGreg McGary <gkm@fb.com>
Tue, 30 Mar 2021 21:58:35 +0000 (14:58 -0700)
Within `lld/macho/`, only `InputFiles.cpp` and `Symbols.h` require the `macho::` namespace qualifier to disambiguate references to `class Symbol`.

Add braces to outer `for` of a 5-level single-line `if`/`for` nest.

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

lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/X86_64.cpp
lld/MachO/Driver.cpp
lld/MachO/InputSection.cpp
lld/MachO/MapFile.cpp
lld/MachO/UnwindInfoSection.cpp
lld/MachO/Writer.cpp

index 14fcee2..55c688b 100644 (file)
@@ -33,7 +33,7 @@ struct ARM64 : TargetInfo {
   void relocateOne(uint8_t *loc, const Reloc &, uint64_t va,
                    uint64_t pc) const override;
 
-  void writeStub(uint8_t *buf, const macho::Symbol &) const override;
+  void writeStub(uint8_t *buf, const Symbol &) const override;
   void writeStubHelperHeader(uint8_t *buf) const override;
   void writeStubHelperEntry(uint8_t *buf, const DylibSymbol &,
                             uint64_t entryAddr) const override;
@@ -217,7 +217,7 @@ static constexpr uint32_t stubCode[] = {
     0xd61f0200, // 08: br    x16
 };
 
-void ARM64::writeStub(uint8_t *buf8, const macho::Symbol &sym) const {
+void ARM64::writeStub(uint8_t *buf8, const Symbol &sym) const {
   auto *buf32 = reinterpret_cast<uint32_t *>(buf8);
   uint64_t pcPageBits =
       pageBits(in.stubs->addr + sym.stubsIndex * sizeof(stubCode));
index d4bb841..44e7d37 100644 (file)
@@ -30,7 +30,7 @@ struct X86_64 : TargetInfo {
   void relocateOne(uint8_t *loc, const Reloc &, uint64_t va,
                    uint64_t relocVA) const override;
 
-  void writeStub(uint8_t *buf, const macho::Symbol &) const override;
+  void writeStub(uint8_t *buf, const Symbol &) const override;
   void writeStubHelperHeader(uint8_t *buf) const override;
   void writeStubHelperEntry(uint8_t *buf, const DylibSymbol &,
                             uint64_t entryAddr) const override;
@@ -138,7 +138,7 @@ static constexpr uint8_t stub[] = {
     0xff, 0x25, 0, 0, 0, 0, // jmpq *__la_symbol_ptr(%rip)
 };
 
-void X86_64::writeStub(uint8_t *buf, const macho::Symbol &sym) const {
+void X86_64::writeStub(uint8_t *buf, const Symbol &sym) const {
   memcpy(buf, stub, 2); // just copy the two nonzero bytes
   uint64_t stubAddr = in.stubs->addr + sym.stubsIndex * sizeof(stub);
   writeRipRelative({&sym, "stub"}, buf, stubAddr, sizeof(stub),
index 96f8195..46ff984 100644 (file)
@@ -513,7 +513,7 @@ static void compileBitcodeFiles() {
 // any CommonSymbols.
 static void replaceCommonSymbols() {
   TimeTraceScope timeScope("Replace common symbols");
-  for (macho::Symbol *sym : symtab->getSymbols()) {
+  for (Symbol *sym : symtab->getSymbols()) {
     auto *common = dyn_cast<CommonSymbol>(sym);
     if (common == nullptr)
       continue;
index 03d2fc5..a925449 100644 (file)
@@ -34,8 +34,7 @@ uint64_t InputSection::getFileSize() const {
 
 uint64_t InputSection::getVA() const { return parent->addr + outSecOff; }
 
-static uint64_t resolveSymbolVA(uint8_t *loc, const lld::macho::Symbol &sym,
-                                uint8_t type) {
+static uint64_t resolveSymbolVA(uint8_t *loc, const Symbol &sym, uint8_t type) {
   const RelocAttrs &relocAttrs = target->getRelocAttrs(type);
   if (relocAttrs.hasAttr(RelocAttrBits::BRANCH)) {
     if (sym.isInStubs())
index 621b52f..acc89e4 100644 (file)
@@ -76,7 +76,7 @@ static std::vector<Defined *> getSymbols() {
 // Construct a map from symbols to their stringified representations.
 // Demangling symbols (which is what toString() does) is slow, so
 // we do that in batch using parallel-for.
-static DenseMap<macho::Symbol *, std::string>
+static DenseMap<Symbol *, std::string>
 getSymbolStrings(ArrayRef<Defined *> syms) {
   std::vector<std::string> str(syms.size());
   parallelForEachN(0, syms.size(), [&](size_t i) {
@@ -84,7 +84,7 @@ getSymbolStrings(ArrayRef<Defined *> syms) {
     os << toString(*syms[i]);
   });
 
-  DenseMap<macho::Symbol *, std::string> ret;
+  DenseMap<Symbol *, std::string> ret;
   for (size_t i = 0, e = syms.size(); i < e; ++i)
     ret[syms[i]] = std::move(str[i]);
   return ret;
@@ -126,7 +126,7 @@ void macho::writeMapFile() {
   // Collect symbol info that we want to print out.
   std::vector<Defined *> syms = getSymbols();
   SymbolMapTy sectionSyms = getSectionSyms(syms);
-  DenseMap<lld::macho::Symbol *, std::string> symStr = getSymbolStrings(syms);
+  DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms);
 
   // Dump table of sections
   os << "# Sections:\n";
@@ -144,7 +144,7 @@ void macho::writeMapFile() {
   os << "# Symbols:\n";
   os << "# Address\t    File  Name\n";
   for (InputSection *isec : inputSections) {
-    for (macho::Symbol *sym : sectionSyms[isec]) {
+    for (Symbol *sym : sectionSyms[isec]) {
       os << format("0x%08llX\t[%3u] %s\n", sym->getVA(),
                    readerToFileOrdinal[sym->getFile()], symStr[sym].c_str());
     }
index 0f26ea3..ed7ae57 100644 (file)
@@ -100,7 +100,7 @@ bool UnwindInfoSection::isNeeded() const {
   return (compactUnwindSection != nullptr);
 }
 
-SmallDenseMap<std::pair<InputSection *, uint64_t /* addend */>, macho::Symbol *>
+SmallDenseMap<std::pair<InputSection *, uint64_t /* addend */>, Symbol *>
     personalityTable;
 
 // Compact unwind relocations have different semantics, so we handle them in a
@@ -118,7 +118,7 @@ void macho::prepareCompactUnwind(InputSection *isec) {
         offsetof(struct CompactUnwindEntry64, personality))
       continue;
 
-    if (auto *s = r.referent.dyn_cast<lld::macho::Symbol *>()) {
+    if (auto *s = r.referent.dyn_cast<Symbol *>()) {
       if (auto *undefined = dyn_cast<Undefined>(s)) {
         treatUndefinedSymbol(*undefined);
         // treatUndefinedSymbol() can replace s with a DylibSymbol; re-check.
@@ -127,7 +127,7 @@ void macho::prepareCompactUnwind(InputSection *isec) {
       }
       if (auto *defined = dyn_cast<Defined>(s)) {
         // Check if we have created a synthetic symbol at the same address.
-        macho::Symbol *&personality =
+        Symbol *&personality =
             personalityTable[{defined->isec, defined->value}];
         if (personality == nullptr) {
           personality = defined;
@@ -146,7 +146,7 @@ void macho::prepareCompactUnwind(InputSection *isec) {
       // Personality functions can be referenced via section relocations
       // if they live in the same object file. Create placeholder synthetic
       // symbols for them in the GOT.
-      macho::Symbol *&s = personalityTable[{referentIsec, r.addend}];
+      Symbol *&s = personalityTable[{referentIsec, r.addend}];
       if (s == nullptr) {
         s = make<Defined>("<internal>", nullptr, referentIsec, r.addend, false,
                           false, false);
@@ -181,7 +181,7 @@ static void relocateCompactUnwind(MergedOutputSection *compactUnwindSection,
 
     for (const Reloc &r : isec->relocs) {
       uint64_t referentVA = 0;
-      if (auto *referentSym = r.referent.dyn_cast<macho::Symbol *>()) {
+      if (auto *referentSym = r.referent.dyn_cast<Symbol *>()) {
         if (!isa<Undefined>(referentSym)) {
           assert(referentSym->isInGot());
           if (auto *defined = dyn_cast<Defined>(referentSym))
index 38a6627..aa85aa3 100644 (file)
@@ -484,8 +484,8 @@ static bool needsBinding(const Symbol *sym) {
   return false;
 }
 
-static void prepareSymbolRelocation(lld::macho::Symbol *sym,
-                                    const InputSection *isec, const Reloc &r) {
+static void prepareSymbolRelocation(Symbol *sym, const InputSection *isec,
+                                    const Reloc &r) {
   const RelocAttrs &relocAttrs = target->getRelocAttrs(r.type);
 
   if (relocAttrs.hasAttr(RelocAttrBits::BRANCH)) {
@@ -520,10 +520,10 @@ void Writer::scanRelocations() {
         // minuend, and doesn't have the usual UNSIGNED semantics. We don't want
         // to emit rebase opcodes for it.
         it = std::next(it);
-        assert(isa<Defined>(it->referent.dyn_cast<lld::macho::Symbol *>()));
+        assert(isa<Defined>(it->referent.dyn_cast<Symbol *>()));
         continue;
       }
-      if (auto *sym = r.referent.dyn_cast<lld::macho::Symbol *>()) {
+      if (auto *sym = r.referent.dyn_cast<Symbol *>()) {
         if (auto *undefined = dyn_cast<Undefined>(sym))
           treatUndefinedSymbol(*undefined);
         // treatUndefinedSymbol() can replace sym with a DylibSymbol; re-check.
@@ -540,7 +540,7 @@ void Writer::scanRelocations() {
 
 void Writer::scanSymbols() {
   TimeTraceScope timeScope("Scan symbols");
-  for (const macho::Symbol *sym : symtab->getSymbols()) {
+  for (const Symbol *sym : symtab->getSymbols()) {
     if (const auto *defined = dyn_cast<Defined>(sym)) {
       if (defined->overridesWeakDef)
         in.weakBinding->addNonWeakDefinition(defined);
@@ -660,11 +660,12 @@ static DenseMap<const InputSection *, size_t> buildInputSectionPriorities() {
   };
 
   // TODO: Make sure this handles weak symbols correctly.
-  for (const InputFile *file : inputFiles)
+  for (const InputFile *file : inputFiles) {
     if (isa<ObjFile>(file))
-      for (lld::macho::Symbol *sym : file->symbols)
+      for (Symbol *sym : file->symbols)
         if (auto *d = dyn_cast<Defined>(sym))
           addSym(*d);
+  }
 
   return sectionPriorities;
 }