[lld] r176370 - move dynamic linking atoms to Atoms.h

Shankar Easwaran shankare at codeaurora.org
Fri Mar 1 11:33:42 PST 2013


Author: shankare
Date: Fri Mar  1 13:33:42 2013
New Revision: 176370

URL: http://llvm.org/viewvc/llvm-project?rev=176370&view=rev
Log:
move dynamic linking atoms to Atoms.h

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Atoms.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
    lld/trunk/test/elf/x86-64-dynamic.test

Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=176370&r1=176369&r2=176370&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Fri Mar  1 13:33:42 2013
@@ -13,6 +13,7 @@
 #include "TargetHandler.h"
 
 #include "lld/Core/LLVM.h"
+#include "lld/ReaderWriter/Simple.h"
 
 #include "llvm/ADT/ArrayRef.h"
 
@@ -621,6 +622,141 @@ private:
   StringRef _loadName;
   const Elf_Sym *_symbol;
 };
+
+class GOTAtom : public SimpleDefinedAtom {
+  StringRef _section;
+
+public:
+  GOTAtom(const File &f, StringRef secName)
+      : SimpleDefinedAtom(f), _section(secName) {
+  }
+
+  virtual Scope scope() const { return scopeTranslationUnit; }
+
+  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
+
+  virtual StringRef customSectionName() const { return _section; }
+
+  virtual ContentType contentType() const { return typeGOT; }
+
+  virtual uint64_t size() const { return rawContent().size(); }
+
+  virtual ContentPermissions permissions() const { return permRW_; }
+
+  virtual ArrayRef<uint8_t> rawContent() const = 0;
+
+  virtual Alignment alignment() const {
+    // The alignment should be 8 byte aligned
+    return Alignment(3);
+  }
+
+#ifndef NDEBUG
+  virtual StringRef name() const { return _name; }
+
+  std::string _name;
+#else
+  virtual StringRef name() const { return ""; }
+#endif
+};
+
+class PLTAtom : public SimpleDefinedAtom {
+  StringRef _section;
+
+public:
+  PLTAtom(const File &f, StringRef secName)
+      : SimpleDefinedAtom(f), _section(secName) {
+  }
+
+  virtual Scope scope() const { return scopeTranslationUnit; }
+
+  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
+
+  virtual StringRef customSectionName() const { return _section; }
+
+  virtual ContentType contentType() const { return typeStub; }
+
+  virtual uint64_t size() const { return rawContent().size(); }
+
+  virtual ContentPermissions permissions() const { return permR_X; }
+
+  virtual ArrayRef<uint8_t> rawContent() const = 0;
+
+  virtual Alignment alignment() const {
+    return Alignment(4); // 16
+  }
+
+#ifndef NDEBUG
+  virtual StringRef name() const { return _name; }
+
+  std::string _name;
+#else
+  virtual StringRef name() const { return ""; }
+#endif
+};
+
+class PLT0Atom : public PLTAtom {
+
+public:
+  PLT0Atom(const File &f) : PLTAtom(f, ".plt") {
+#ifndef NDEBUG
+    _name = ".PLT0";
+#endif
+  }
+};
+
+class GLOBAL_OFFSET_TABLEAtom : public SimpleDefinedAtom {
+public:
+  GLOBAL_OFFSET_TABLEAtom(const File &f) : SimpleDefinedAtom(f) {}
+
+  virtual StringRef name() const { return "_GLOBAL_OFFSET_TABLE_"; }
+
+  virtual Scope scope() const { return scopeGlobal; }
+
+  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
+
+  virtual StringRef customSectionName() const { return ".got.plt"; }
+
+  virtual ContentType contentType() const { return typeGOT; }
+
+  virtual uint64_t size() const { return 0; }
+
+  virtual ContentPermissions permissions() const { return permRW_; }
+
+  virtual Alignment alignment() const {
+    // Needs 8 byte alignment
+    return Alignment(3);
+  }
+
+  virtual ArrayRef<uint8_t> rawContent() const {
+    return ArrayRef<uint8_t>();
+  }
+};
+
+class TLSGETADDRAtom : public SimpleDefinedAtom {
+public:
+  TLSGETADDRAtom(const File &f) : SimpleDefinedAtom(f) {}
+
+  virtual StringRef name() const { return "__tls_get_addr"; }
+
+  virtual Scope scope() const { return scopeGlobal; }
+
+  virtual Merge merge() const { return mergeAsWeak; }
+
+  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
+
+  virtual StringRef customSectionName() const { return ".text"; }
+
+  virtual ContentType contentType() const { return typeCode; }
+
+  virtual uint64_t size() const { return 0; }
+
+  virtual ContentPermissions permissions() const { return permR_X; }
+
+  virtual Alignment alignment() const { return Alignment(0); }
+
+  virtual ArrayRef<uint8_t> rawContent() const { return ArrayRef<uint8_t>(); }
+};
+
 } // end namespace elf
 } // end namespace lld
 

Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp?rev=176370&r1=176369&r2=176370&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp Fri Mar  1 13:33:42 2013
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "Atoms.h"
 #include "X86_64TargetHandler.h"
-
 #include "X86_64TargetInfo.h"
 
 using namespace lld;
@@ -148,61 +148,6 @@ ErrorOr<void> X86_64TargetRelocationHand
   return error_code::success();
 }
 
-namespace {
-class GLOBAL_OFFSET_TABLEAtom : public SimpleDefinedAtom {
-public:
-  GLOBAL_OFFSET_TABLEAtom(const File &f) : SimpleDefinedAtom(f) {}
-
-  virtual StringRef name() const { return "_GLOBAL_OFFSET_TABLE_"; }
-
-  virtual Scope scope() const { return scopeGlobal; }
-
-  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
-
-  virtual StringRef customSectionName() const { return ".got.plt"; }
-
-  virtual ContentType contentType() const { return typeGOT; }
-
-  virtual uint64_t size() const { return 0; }
-
-  virtual ContentPermissions permissions() const { return permRW_; }
-
-  virtual Alignment alignment() const {
-    // Needs 8 byte alignment
-    return Alignment(3);
-  }
-
-  virtual ArrayRef<uint8_t> rawContent() const {
-    return ArrayRef<uint8_t>();
-  }
-};
-
-class TLSGETADDRAtom : public SimpleDefinedAtom {
-public:
-  TLSGETADDRAtom(const File &f) : SimpleDefinedAtom(f) {}
-
-  virtual StringRef name() const { return "__tls_get_addr"; }
-
-  virtual Scope scope() const { return scopeGlobal; }
-
-  virtual Merge merge() const { return mergeAsWeak; }
-
-  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
-
-  virtual StringRef customSectionName() const { return ".text"; }
-
-  virtual ContentType contentType() const { return typeCode; }
-
-  virtual uint64_t size() const { return 0; }
-
-  virtual ContentPermissions permissions() const { return permR_X; }
-
-  virtual Alignment alignment() const { return Alignment(0); }
-
-  virtual ArrayRef<uint8_t> rawContent() const { return ArrayRef<uint8_t>(); }
-};
-} // end anon namespace
-
 void X86_64TargetHandler::addFiles(InputFiles &f) {
   _gotFile.addAtom(*new (_gotFile._alloc) GLOBAL_OFFSET_TABLEAtom(_gotFile));
   _gotFile.addAtom(*new (_gotFile._alloc) TLSGETADDRAtom(_gotFile));

Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp?rev=176370&r1=176369&r2=176370&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp Fri Mar  1 13:33:42 2013
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "Atoms.h"
 #include "X86_64TargetInfo.h"
 
 #include "lld/Core/File.h"
@@ -24,96 +25,45 @@ using namespace lld::elf;
 namespace {
 using namespace llvm::ELF;
 
-class GOTAtom : public SimpleDefinedAtom {
+class X86_64GOTAtom : public GOTAtom {
   static const uint8_t _defaultContent[8];
-  StringRef _section;
 
 public:
-  GOTAtom(const File &f, StringRef secName)
-      : SimpleDefinedAtom(f), _section(secName) {
+  X86_64GOTAtom(const File &f, StringRef secName)
+      : GOTAtom(f, secName) {
   }
 
-  virtual Scope scope() const { return scopeTranslationUnit; }
-
-  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
-
-  virtual StringRef customSectionName() const { return _section; }
-
-  virtual ContentType contentType() const { return typeGOT; }
-
-  virtual uint64_t size() const { return rawContent().size(); }
-
-  virtual ContentPermissions permissions() const { return permRW_; }
-
   virtual ArrayRef<uint8_t> rawContent() const {
     return ArrayRef<uint8_t>(_defaultContent, 8);
   }
-
-  virtual Alignment alignment() const {
-    // The alignment should be 8 byte aligned
-    return Alignment(3);
-  }
-
-#ifndef NDEBUG
-  virtual StringRef name() const { return _name; }
-
-  std::string _name;
-#else
-  virtual StringRef name() const { return ""; }
-#endif
 };
 
-const uint8_t GOTAtom::_defaultContent[8] = { 0 };
+const uint8_t X86_64GOTAtom::_defaultContent[8] = { 0 };
 
-class PLTAtom : public SimpleDefinedAtom {
+class X86_64PLTAtom : public PLTAtom {
   static const uint8_t _defaultContent[16];
-  StringRef _section;
 
 public:
-  PLTAtom(const File &f, StringRef secName)
-      : SimpleDefinedAtom(f), _section(secName) {
+  X86_64PLTAtom(const File &f, StringRef secName)
+      : PLTAtom(f, secName) {
   }
 
-  virtual Scope scope() const { return scopeTranslationUnit; }
-
-  virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
-
-  virtual StringRef customSectionName() const { return _section; }
-
-  virtual ContentType contentType() const { return typeStub; }
-
-  virtual uint64_t size() const { return rawContent().size(); }
-
-  virtual ContentPermissions permissions() const { return permR_X; }
-
   virtual ArrayRef<uint8_t> rawContent() const {
     return ArrayRef<uint8_t>(_defaultContent, 16);
   }
-
-  virtual Alignment alignment() const {
-    return Alignment(4); // 16
-  }
-
-#ifndef NDEBUG
-  virtual StringRef name() const { return _name; }
-
-  std::string _name;
-#else
-  virtual StringRef name() const { return ""; }
-#endif
 };
 
-const uint8_t PLTAtom::_defaultContent[16] = {
+const uint8_t X86_64PLTAtom::_defaultContent[16] = {
   0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmpq *gotatom(%rip)
   0x68, 0x00, 0x00, 0x00, 0x00,       // pushq reloc-index
   0xe9, 0x00, 0x00, 0x00, 0x00        // jmpq plt[-1]
 };
 
-class PLT0Atom : public PLTAtom {
+class X86_64PLT0Atom : public PLT0Atom {
   static const uint8_t _plt0Content[16];
 
 public:
-  PLT0Atom(const File &f) : PLTAtom(f, ".plt") {
+  X86_64PLT0Atom(const File &f) : PLT0Atom(f) {
 #ifndef NDEBUG
     _name = ".PLT0";
 #endif
@@ -124,7 +74,7 @@ public:
   }
 };
 
-const uint8_t PLT0Atom::_plt0Content[16] = {
+const uint8_t X86_64PLT0Atom::_plt0Content[16] = {
   0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip)
   0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip)
   0x90, 0x90, 0x90, 0x90        // nopnopnop
@@ -166,9 +116,9 @@ protected:
     auto plt = _pltMap.find(da);
     if (plt != _pltMap.end())
       return plt->second;
-    auto ga = new (_file._alloc) GOTAtom(_file, ".got.plt");
+    auto ga = new (_file._alloc) X86_64GOTAtom(_file, ".got.plt");
     ga->addReference(R_X86_64_IRELATIVE, 0, da, 0);
-    auto pa = new (_file._alloc) PLTAtom(_file, ".plt");
+    auto pa = new (_file._alloc) X86_64PLTAtom(_file, ".plt");
     pa->addReference(R_X86_64_PC32, 2, ga, -4);
 #ifndef NDEBUG
     ga->_name = "__got_ifunc_";
@@ -196,7 +146,7 @@ protected:
   const GOTAtom *getGOTTPOFF(const DefinedAtom *atom) {
     auto got = _gotMap.find(atom);
     if (got == _gotMap.end()) {
-      auto g = new (_file._alloc) GOTAtom(_file, ".got");
+      auto g = new (_file._alloc) X86_64GOTAtom(_file, ".got");
       g->addReference(R_X86_64_TPOFF64, 0, atom, 0);
 #ifndef NDEBUG
       g->_name = "__got_tls_";
@@ -219,7 +169,7 @@ protected:
   /// \brief Create a GOT entry containing 0.
   const GOTAtom *getNullGOT() {
     if (!_null) {
-      _null = new (_file._alloc) GOTAtom(_file, ".got.plt");
+      _null = new (_file._alloc) X86_64GOTAtom(_file, ".got.plt");
 #ifndef NDEBUG
       _null->_name = "__got_null";
 #endif
@@ -230,7 +180,7 @@ protected:
   const GOTAtom *getGOT(const DefinedAtom *da) {
     auto got = _gotMap.find(da);
     if (got == _gotMap.end()) {
-      auto g = new (_file._alloc) GOTAtom(_file, ".got");
+      auto g = new (_file._alloc) X86_64GOTAtom(_file, ".got");
       g->addReference(R_X86_64_64, 0, da, 0);
 #ifndef NDEBUG
       g->_name = "__got_";
@@ -356,9 +306,9 @@ public:
       return _PLT0;
     // Fill in the null entry.
     getNullGOT();
-    _PLT0 = new (_file._alloc) PLT0Atom(_file);
-    _got0 = new (_file._alloc) GOTAtom(_file, ".got.plt");
-    _got1 = new (_file._alloc) GOTAtom(_file, ".got.plt");
+    _PLT0 = new (_file._alloc) X86_64PLT0Atom(_file);
+    _got0 = new (_file._alloc) X86_64GOTAtom(_file, ".got.plt");
+    _got1 = new (_file._alloc) X86_64GOTAtom(_file, ".got.plt");
     _PLT0->addReference(R_X86_64_PC32, 2, _got0, -4);
     _PLT0->addReference(R_X86_64_PC32, 8, _got1, -4);
 #ifndef NDEBUG
@@ -372,9 +322,9 @@ public:
     auto plt = _pltMap.find(a);
     if (plt != _pltMap.end())
       return plt->second;
-    auto ga = new (_file._alloc) GOTAtom(_file, ".got.plt");
+    auto ga = new (_file._alloc) X86_64GOTAtom(_file, ".got.plt");
     ga->addReference(R_X86_64_JUMP_SLOT, 0, a, 0);
-    auto pa = new (_file._alloc) PLTAtom(_file, ".plt");
+    auto pa = new (_file._alloc) X86_64PLTAtom(_file, ".plt");
     pa->addReference(R_X86_64_PC32, 2, ga, -4);
     pa->addReference(LLD_R_X86_64_GOTRELINDEX, 7, ga, 0);
     pa->addReference(R_X86_64_PC32, 12, getPLT0(), -4);
@@ -413,7 +363,7 @@ public:
   const GOTAtom *getSharedGOT(const SharedLibraryAtom *sla) {
     auto got = _gotMap.find(sla);
     if (got == _gotMap.end()) {
-      auto g = new (_file._alloc) GOTAtom(_file, ".got.dyn");
+      auto g = new (_file._alloc) X86_64GOTAtom(_file, ".got.dyn");
       g->addReference(R_X86_64_GLOB_DAT, 0, sla, 0);
 #ifndef NDEBUG
       g->_name = "__got_";

Modified: lld/trunk/test/elf/x86-64-dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/x86-64-dynamic.test?rev=176370&r1=176369&r2=176370&view=diff
==============================================================================
--- lld/trunk/test/elf/x86-64-dynamic.test (original)
+++ lld/trunk/test/elf/x86-64-dynamic.test Fri Mar  1 13:33:42 2013
@@ -1,6 +1,7 @@
 RUN: lld -core -target x86_64-linux %p/Inputs/use-shared.x86-64 \
-RUN:   %p/Inputs/shared.so-x86-64 -emit-yaml -output=- -noinhibit-exec \
-RUN:   -output-type=dynamic | FileCheck %s
+RUN:   %p/Inputs/shared.so-x86-64 -emit-yaml -output=%t1 -noinhibit-exec \
+RUN:   -output-type=dynamic
+RUN: FileCheck %s < %t1
 
 // Don't check the GOT and PLT names as they are only present in assert builds.
 





More information about the llvm-commits mailing list