gas/
[deliverable/binutils-gdb.git] / gold / reloc.h
index 1aa0d896717f0f363c3ca72630f36e9add70e923..e69161d0a91bc6357e56b59631cce51fb5c45b09 100644 (file)
@@ -1,5 +1,25 @@
 // reloc.h -- relocate input files for gold   -*- C++ -*-
 
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
 #ifndef GOLD_RELOC_H
 #define GOLD_RELOC_H
 
@@ -172,6 +192,25 @@ private:
     elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
   }
 
+  // Like rel(), but sign-extends the value to SIZE.
+  template<int valsize>
+  static inline void
+  signedrel(unsigned char* view,
+            const Sized_relobj<size, big_endian>* object,
+            const Symbol_value<size>* psymval)
+  {
+    typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
+    typedef typename elfcpp::Swap<size, big_endian>::Valtype Sizetype;
+    Valtype* wv = reinterpret_cast<Valtype*>(view);
+    Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
+    // Fancy formula to sign-extend x to size.
+    const Sizetype mask = 1U << (sizeof(valsize) * 8 - 1);
+    Sizetype sign_extended_x = x;
+    sign_extended_x = (sign_extended_x ^ mask) - mask;
+    x = psymval->value(object, sign_extended_x);
+    elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
+  }
+
   // Do a simple PC relative relocation with the addend in the section
   // contents.  VALSIZE is the size of the value.
   template<int valsize>
@@ -218,6 +257,13 @@ public:
        const Symbol_value<size>* psymval)
   { This::template rel<8>(view, object, psymval); }
 
+  // Do an 8-bit REL relocation, sign extending the addend to SIZE.
+  static inline void
+  rel8s(unsigned char* view,
+         const Sized_relobj<size, big_endian>* object,
+         const Symbol_value<size>* psymval)
+  { This::template signedrel<8>(view, object, psymval); }
+
   // Do a simple 8-bit PC relative relocation with the addend in the
   // section contents.
   static inline void
@@ -244,6 +290,13 @@ public:
        const Symbol_value<size>* psymval)
   { This::template rel<16>(view, object, psymval); }
 
+  // Do a 16-bit REL relocation, sign extending the addend to SIZE.
+  static inline void
+  rel16s(unsigned char* view,
+         const Sized_relobj<size, big_endian>* object,
+         const Symbol_value<size>* psymval)
+  { This::template signedrel<16>(view, object, psymval); }
+
   // Do a simple 32-bit PC relative REL relocation with the addend in
   // the section contents.
   static inline void
@@ -270,6 +323,13 @@ public:
        const Symbol_value<size>* psymval)
   { This::template rel<32>(view, object, psymval); }
 
+  // Do a 32-bit REL relocation, sign extending the addend to SIZE.
+  static inline void
+  rel32s(unsigned char* view,
+         const Sized_relobj<size, big_endian>* object,
+         const Symbol_value<size>* psymval)
+  { This::template signedrel<32>(view, object, psymval); }
+
   // Do a simple 32-bit PC relative REL relocation with the addend in
   // the section contents.
   static inline void
This page took 0.024215 seconds and 4 git commands to generate.