[ELF][Hexagon] add quickdata relocations
authorShankar Easwaran <shankare@codeaurora.org>
Thu, 28 Feb 2013 20:54:03 +0000 (20:54 +0000)
committerShankar Easwaran <shankare@codeaurora.org>
Thu, 28 Feb 2013 20:54:03 +0000 (20:54 +0000)
llvm-svn: 176298

lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp
lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h
lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h
lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h

index 97f63a2..3792475 100644 (file)
@@ -107,6 +107,20 @@ int relocHex_N_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
   return 0;
 }
 
+// GP REL relocations
+int relocHexGPRELN(uint8_t *location, uint64_t P, uint64_t S, uint64_t A,
+                   uint64_t GP, int nShiftBits) {
+  int32_t result = (int64_t)((S + A - GP) >> nShiftBits);
+  int32_t range = 1L << 16;
+  if (result <= range) {
+    result = lld::scatterBits<uint32_t>(result, FINDV4BITMASK(location));
+    *reinterpret_cast<llvm::support::ulittle32_t *>(location) =
+        result |
+        (uint32_t) * reinterpret_cast<llvm::support::ulittle32_t *>(location);
+    return 0;
+  }
+  return 1;
+}
 } // end anon namespace
 
 ErrorOr<void> HexagonTargetRelocationHandler::applyRelocation(
@@ -157,6 +171,22 @@ ErrorOr<void> HexagonTargetRelocationHandler::applyRelocation(
   case R_HEX_B7_PCREL_X:
     relocHexBNPCRELX(location, relocVAddress, targetVAddress, ref.addend(), 6);
     break;
+  case R_HEX_GPREL16_0:
+    relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(),
+                   _targetLayout.getSDataSection()->virtualAddr(), 0);
+    break;
+  case R_HEX_GPREL16_1:
+    relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(),
+                   _targetLayout.getSDataSection()->virtualAddr(), 1);
+    break;
+  case R_HEX_GPREL16_2:
+    relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(),
+                   _targetLayout.getSDataSection()->virtualAddr(), 2);
+    break;
+  case R_HEX_GPREL16_3:
+    relocHexGPRELN(location, relocVAddress, targetVAddress, ref.addend(),
+                   _targetLayout.getSDataSection()->virtualAddr(), 3);
+    break;
   case R_HEX_16_X:
   case R_HEX_12_X:
   case R_HEX_11_X:
index d1757cf..2894e5b 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_HANDLER_H
 #define LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_HANDLER_H
 
+#include "HexagonSectionChunks.h"
 #include "HexagonTargetHandler.h"
 #include "lld/ReaderWriter/RelocationHelperFunctions.h"
 
@@ -17,19 +18,23 @@ namespace elf {
 typedef llvm::object::ELFType<llvm::support::little, 4, false> HexagonELFType;
 
 class HexagonTargetInfo;
+class HexagonTargetHandler;
+template <class HexagonELFType> class HexagonTargetLayout;
 
-class HexagonTargetRelocationHandler LLVM_FINAL
-    public TargetRelocationHandler<HexagonELFType> {
+class HexagonTargetRelocationHandler LLVM_FINAL :
+    public TargetRelocationHandler<HexagonELFType> {
 public:
-  HexagonTargetRelocationHandler(const HexagonTargetInfo &ti) : _targetInfo(ti) 
-  {}
-
-  virtual ErrorOr<void> applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
-                                        const AtomLayout &,
-                                        const Reference &)const;
+  HexagonTargetRelocationHandler(
+      const HexagonTargetInfo &ti,
+      const HexagonTargetLayout<HexagonELFType> &layout)
+      : _targetInfo(ti), _targetLayout(layout) {}
 
+  virtual ErrorOr<void>
+  applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, const AtomLayout &,
+                  const Reference &) const;
 private:
   const HexagonTargetInfo &_targetInfo;
+  const HexagonTargetLayout<HexagonELFType> &_targetLayout;
 };
 } // elf
 } // lld 
index 4bbe3b6..1991148 100644 (file)
@@ -6,6 +6,8 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+#ifndef LLD_READER_WRITER_ELF_HEXAGON_SECTION_CHUNKS_H
+#define LLD_READER_WRITER_ELF_HEXAGON_SECTION_CHUNKS_H
 
 #include "HexagonTargetHandler.h"
 
@@ -75,3 +77,4 @@ void SDataSection<HexagonELFType>::doPreFlight() {
 } // elf
 } // lld
 
+#endif // LLD_READER_WRITER_ELF_HEXAGON_SECTION_CHUNKS_H
index c998a34..d7ea9cb 100644 (file)
@@ -16,6 +16,6 @@ using namespace elf;
 using namespace llvm::ELF;
 
 HexagonTargetHandler::HexagonTargetHandler(HexagonTargetInfo &targetInfo)
-    : DefaultTargetHandler(targetInfo), _relocationHandler(targetInfo),
-      _targetLayout(targetInfo), _hexagonRuntimeFile(targetInfo) {
-}
+    : DefaultTargetHandler(targetInfo), _targetLayout(targetInfo),
+      _relocationHandler(targetInfo, _targetLayout),
+      _hexagonRuntimeFile(targetInfo) {}
index 03726df..ff8278d 100644 (file)
@@ -156,11 +156,11 @@ public:
     header->e_flags(0x3);
   }
 
-  virtual TargetLayout<HexagonELFType> &targetLayout() {
+  virtual HexagonTargetLayout<HexagonELFType> &targetLayout() {
     return _targetLayout;
   }
 
-  virtual TargetAtomHandler<HexagonELFType> &targetAtomHandler() {
+  virtual HexagonTargetAtomHandler<HexagonELFType> &targetAtomHandler() {
     return _targetAtomHandler;
   }
 
@@ -184,10 +184,10 @@ public:
   }
 
 private:
-  HexagonTargetRelocationHandler _relocationHandler;
   HexagonTargetLayout<HexagonELFType> _targetLayout;
+  HexagonTargetRelocationHandler _relocationHandler;
   HexagonTargetAtomHandler<HexagonELFType> _targetAtomHandler;
-  HexagonRuntimeFile<HexagonELFType> _hexagonRuntimeFile; 
+  HexagonRuntimeFile<HexagonELFType> _hexagonRuntimeFile;
 };
 } // end namespace elf
 } // end namespace lld
index e5a84ff..bf25b50 100644 (file)
@@ -20,6 +20,7 @@
 
 namespace lld {
 namespace elf {
+
 class HexagonTargetInfo LLVM_FINAL : public ELFTargetInfo {
 public:
   HexagonTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {