[lld] r306590 - Move copy function from Symbol to SymbolBody.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 12:43:02 PDT 2017


Author: ruiu
Date: Wed Jun 28 12:43:02 2017
New Revision: 306590

URL: http://llvm.org/viewvc/llvm-project?rev=306590&view=rev
Log:
Move copy function from Symbol to SymbolBody.

We could have add this function either Symbol or SymbolBody. I added it
to Symbol at first. But I noticed that if I've added it to SymbolBody,
we could've removed SymbolBody::setName(). So I'll do that in this patch.

Modified:
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=306590&r1=306589&r2=306590&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Jun 28 12:43:02 2017
@@ -195,7 +195,7 @@ template <class ELFT> void SymbolTable<E
   for (auto &KV : Config->RenamedSymbols) {
     Symbol *Dst = KV.first;
     Symbol *Src = KV.second.Target;
-    Dst->copyBody(Src);
+    Dst->body()->copy(Src->body());
     Dst->Binding = KV.second.OriginalBinding;
   }
 }

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=306590&r1=306589&r2=306590&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Jun 28 12:43:02 2017
@@ -159,6 +159,21 @@ bool SymbolBody::isPreemptible() const {
   return true;
 }
 
+// Overwrites all attributes except symbol name with Other's so that
+// this symbol becomes an alias to Other. This is useful for handling
+// some options such as --wrap.
+//
+// The reason why we want to keep the symbol name is because, if we
+// copy symbol names, we'll end up having symbol tables in resulting
+// executables or DSOs containing two or more identical symbols, which
+// is just inconvenient.
+void SymbolBody::copy(SymbolBody *Other) {
+  StringRef S = Name;
+  memcpy(symbol()->Body.buffer, Other->symbol()->Body.buffer,
+         sizeof(Symbol::Body));
+  Name = S;
+}
+
 uint64_t SymbolBody::getVA(int64_t Addend) const {
   uint64_t OutVA = getSymVA(*this, Addend);
   return OutVA + Addend;
@@ -348,20 +363,6 @@ bool Symbol::includeInDynsym() const {
          (body()->isUndefined() && Config->Shared);
 }
 
-// copyBody overwrites all attributes except symbol name with Other's
-// so that this symbol becomes an alias to Other. This is useful for
-// handling some options such as --wrap.
-//
-// The reason why we want to keep the symbol name is because, if we
-// copy symbol names, we'll end up having symbol tables in resulting
-// executables or DSOs containing two identical symbols, which is just
-// inconvenient.
-void Symbol::copyBody(Symbol *Other) {
-  StringRef S = body()->getName();
-  memcpy(this->Body.buffer, Other->Body.buffer, sizeof(Symbol::Body));
-  body()->setName(S);
-}
-
 // Print out a log message for --trace-symbol.
 void elf::printTraceSymbol(Symbol *Sym) {
   SymbolBody *B = Sym->body();

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=306590&r1=306589&r2=306590&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Jun 28 12:43:02 2017
@@ -69,9 +69,9 @@ public:
   bool isLocal() const { return IsLocal; }
   bool isPreemptible() const;
   StringRef getName() const { return Name; }
-  void setName(StringRef S) { Name = S; }
   uint8_t getVisibility() const { return StOther & 0x3; }
   void parseSymbolVersion();
+  void copy(SymbolBody *Other);
 
   bool isInGot() const { return GotIndex != -1U; }
   bool isInPlt() const { return PltIndex != -1U; }
@@ -379,8 +379,6 @@ struct Symbol {
 
   SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
   const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }
-
-  void copyBody(Symbol *Other);
 };
 
 void printTraceSymbol(Symbol *Sym);




More information about the llvm-commits mailing list