From dfbba8f432b3e651241e00d13a5284db46692791 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 28 Sep 2007 06:00:26 +0000 Subject: [PATCH] From Andrew Chatham: add signedrel<>, rel32s and friends. --- gold/reloc.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gold/reloc.h b/gold/reloc.h index cc1149b6bc1..e69161d0a91 100644 --- a/gold/reloc.h +++ b/gold/reloc.h @@ -192,6 +192,25 @@ private: elfcpp::Swap::writeval(wv, x); } + // Like rel(), but sign-extends the value to SIZE. + template + static inline void + signedrel(unsigned char* view, + const Sized_relobj* object, + const Symbol_value* psymval) + { + typedef typename elfcpp::Swap::Valtype Valtype; + typedef typename elfcpp::Swap::Valtype Sizetype; + Valtype* wv = reinterpret_cast(view); + Valtype x = elfcpp::Swap::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::writeval(wv, x); + } + // Do a simple PC relative relocation with the addend in the section // contents. VALSIZE is the size of the value. template @@ -238,6 +257,13 @@ public: const Symbol_value* 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* object, + const Symbol_value* 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 @@ -264,6 +290,13 @@ public: const Symbol_value* 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* object, + const Symbol_value* 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 @@ -290,6 +323,13 @@ public: const Symbol_value* 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* object, + const Symbol_value* 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 -- 2.30.2