[lld] r365003 - Avoid identifiers that are different only in case. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 23:11:50 PDT 2019


Author: ruiu
Date: Tue Jul  2 23:11:50 2019
New Revision: 365003

URL: http://llvm.org/viewvc/llvm-project?rev=365003&view=rev
Log:
Avoid identifiers that are different only in case. NFC.

Some variables in lld have the same name as functions ignoring case.
This patch gives them different names, so that my next patch is easier
to read.

Modified:
    lld/trunk/ELF/DWARF.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/ELF/Symbols.cpp

Modified: lld/trunk/ELF/DWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DWARF.cpp?rev=365003&r1=365002&r2=365003&view=diff
==============================================================================
--- lld/trunk/ELF/DWARF.cpp (original)
+++ lld/trunk/ELF/DWARF.cpp Tue Jul  2 23:11:50 2019
@@ -58,7 +58,7 @@ namespace {
 template <class RelTy> struct LLDRelocationResolver {
   // In the ELF ABIs, S sepresents the value of the symbol in the relocation
   // entry. For Rela, the addend is stored as part of the relocation entry.
-  static uint64_t Resolve(object::RelocationRef Ref, uint64_t S,
+  static uint64_t resolve(object::RelocationRef Ref, uint64_t S,
                           uint64_t /* A */) {
     return S + Ref.getRawDataRefImpl().p;
   }
@@ -66,7 +66,7 @@ template <class RelTy> struct LLDRelocat
 
 template <class ELFT> struct LLDRelocationResolver<Elf_Rel_Impl<ELFT, false>> {
   // For Rel, the addend A is supplied by the caller.
-  static uint64_t Resolve(object::RelocationRef /*Ref*/, uint64_t S,
+  static uint64_t resolve(object::RelocationRef /*Ref*/, uint64_t S,
                           uint64_t A) {
     return S + A;
   }
@@ -110,7 +110,7 @@ LLDDwarfObj<ELFT>::findAux(const InputSe
   DataRefImpl D;
   D.p = getAddend<ELFT>(Rel);
   return RelocAddrEntry{SecIndex, RelocationRef(D, nullptr),
-                        LLDRelocationResolver<RelTy>::Resolve, Val};
+                        LLDRelocationResolver<RelTy>::resolve, Val};
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=365003&r1=365002&r2=365003&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Jul  2 23:11:50 2019
@@ -55,7 +55,7 @@ static ELFKind getELFKind(MemoryBufferRe
   unsigned char Endian;
   std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
 
-  auto Fatal = [&](StringRef Msg) {
+  auto Report = [&](StringRef Msg) {
     StringRef Filename = MB.getBufferIdentifier();
     if (ArchiveName.empty())
       fatal(Filename + ": " + Msg);
@@ -64,16 +64,16 @@ static ELFKind getELFKind(MemoryBufferRe
   };
 
   if (!MB.getBuffer().startswith(ElfMagic))
-    Fatal("not an ELF file");
+    Report("not an ELF file");
   if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
-    Fatal("corrupted ELF file: invalid data encoding");
+    Report("corrupted ELF file: invalid data encoding");
   if (Size != ELFCLASS32 && Size != ELFCLASS64)
-    Fatal("corrupted ELF file: invalid file class");
+    Report("corrupted ELF file: invalid file class");
 
   size_t BufSize = MB.getBuffer().size();
   if ((Size == ELFCLASS32 && BufSize < sizeof(Elf32_Ehdr)) ||
       (Size == ELFCLASS64 && BufSize < sizeof(Elf64_Ehdr)))
-    Fatal("corrupted ELF file: file is too short");
+    Report("corrupted ELF file: file is too short");
 
   if (Size == ELFCLASS32)
     return (Endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=365003&r1=365002&r2=365003&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Jul  2 23:11:50 2019
@@ -566,10 +566,10 @@ template <class ELFT> static void addCop
 
   // See if this symbol is in a read-only segment. If so, preserve the symbol's
   // memory protection by reserving space in the .bss.rel.ro section.
-  bool IsReadOnly = isReadOnly<ELFT>(SS);
-  BssSection *Sec = make<BssSection>(IsReadOnly ? ".bss.rel.ro" : ".bss",
-                                     SymSize, SS.Alignment);
-  if (IsReadOnly)
+  bool IsRO = isReadOnly<ELFT>(SS);
+  BssSection *Sec =
+      make<BssSection>(IsRO ? ".bss.rel.ro" : ".bss", SymSize, SS.Alignment);
+  if (IsRO)
     In.BssRelRo->getParent()->addSection(Sec);
   else
     In.Bss->getParent()->addSection(Sec);

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=365003&r1=365002&r2=365003&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Tue Jul  2 23:11:50 2019
@@ -40,14 +40,21 @@ using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::elf;
 
-static bool isUnderSysroot(StringRef Path);
-
 namespace {
 class ScriptParser final : ScriptLexer {
 public:
-  ScriptParser(MemoryBufferRef MB)
-      : ScriptLexer(MB),
-        IsUnderSysroot(isUnderSysroot(MB.getBufferIdentifier())) {}
+  ScriptParser(MemoryBufferRef MB) : ScriptLexer(MB) {
+    // Initialize IsUnderSysroot
+    if (Config->Sysroot == "")
+      return;
+    StringRef Path = MB.getBufferIdentifier();
+    for (; !Path.empty(); Path = sys::path::parent_path(Path)) {
+      if (!sys::fs::equivalent(Config->Sysroot, Path))
+        continue;
+      IsUnderSysroot = true;
+      return;
+    }
+  }
 
   void readLinkerScript();
   void readVersionScript();
@@ -118,7 +125,7 @@ private:
   readSymbols();
 
   // True if a script being read is in a subdirectory specified by -sysroot.
-  bool IsUnderSysroot;
+  bool IsUnderSysroot = false;
 
   // A set to detect an INCLUDE() cycle.
   StringSet<> Seen;
@@ -131,15 +138,6 @@ static StringRef unquote(StringRef S) {
   return S;
 }
 
-static bool isUnderSysroot(StringRef Path) {
-  if (Config->Sysroot == "")
-    return false;
-  for (; !Path.empty(); Path = sys::path::parent_path(Path))
-    if (sys::fs::equivalent(Config->Sysroot, Path))
-      return true;
-  return false;
-}
-
 // Some operations only support one non absolute value. Move the
 // absolute one to the right hand side for convenience.
 static void moveAbsRight(ExprValue &A, ExprValue &B) {
@@ -1449,8 +1447,8 @@ std::vector<SymbolVersion> ScriptParser:
   std::vector<SymbolVersion> Ret;
   while (!errorCount() && peek() != "}") {
     StringRef Tok = next();
-    bool HasWildcard = !Tok.startswith("\"") && hasWildcard(Tok);
-    Ret.push_back({unquote(Tok), IsCXX, HasWildcard});
+    Ret.push_back(
+        {unquote(Tok), IsCXX, !Tok.startswith("\"") && hasWildcard(Tok)});
     if (consume("}"))
       return Ret;
     expect(";");

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=365003&r1=365002&r2=365003&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Jul  2 23:11:50 2019
@@ -317,18 +317,18 @@ void elf::maybeWarnUnorderableSymbol(con
   const InputFile *File = Sym->File;
   auto *D = dyn_cast<Defined>(Sym);
 
-  auto Warn = [&](StringRef S) { warn(toString(File) + S + Sym->getName()); };
+  auto Report = [&](StringRef S) { warn(toString(File) + S + Sym->getName()); };
 
   if (Sym->isUndefined())
-    Warn(": unable to order undefined symbol: ");
+    Report(": unable to order undefined symbol: ");
   else if (Sym->isShared())
-    Warn(": unable to order shared symbol: ");
+    Report(": unable to order shared symbol: ");
   else if (D && !D->Section)
-    Warn(": unable to order absolute symbol: ");
+    Report(": unable to order absolute symbol: ");
   else if (D && isa<OutputSection>(D->Section))
-    Warn(": unable to order synthetic symbol: ");
+    Report(": unable to order synthetic symbol: ");
   else if (D && !D->Section->Repl->isLive())
-    Warn(": unable to order discarded symbol: ");
+    Report(": unable to order discarded symbol: ");
 }
 
 // Returns a symbol for an error message.




More information about the llvm-commits mailing list