+// For x32, we need to handle PC-relative relocations using full 64-bit
+// arithmetic, so that we can detect relocation overflows properly.
+// This class overrides the pcrela32_check methods from the defaults in
+// Relocate_functions in reloc.h.
+
+template<int size>
+class X86_64_relocate_functions : public Relocate_functions<size, false>
+{
+ public:
+ typedef Relocate_functions<size, false> Base;
+
+ // Do a simple PC relative relocation with the addend in the
+ // relocation.
+ static inline typename Base::Reloc_status
+ pcrela32_check(unsigned char* view,
+ typename elfcpp::Elf_types<64>::Elf_Addr value,
+ typename elfcpp::Elf_types<64>::Elf_Swxword addend,
+ typename elfcpp::Elf_types<64>::Elf_Addr address)
+ {
+ typedef typename elfcpp::Swap<32, false>::Valtype Valtype;
+ Valtype* wv = reinterpret_cast<Valtype*>(view);
+ value = value + addend - address;
+ elfcpp::Swap<32, false>::writeval(wv, value);
+ return (Bits<32>::has_overflow(value)
+ ? Base::RELOC_OVERFLOW : Base::RELOC_OK);
+ }
+
+ // Do a simple PC relative relocation with a Symbol_value with the
+ // addend in the relocation.
+ static inline typename Base::Reloc_status
+ pcrela32_check(unsigned char* view,
+ const Sized_relobj_file<size, false>* object,
+ const Symbol_value<size>* psymval,
+ typename elfcpp::Elf_types<64>::Elf_Swxword addend,
+ typename elfcpp::Elf_types<64>::Elf_Addr address)
+ {
+ typedef typename elfcpp::Swap<32, false>::Valtype Valtype;
+ Valtype* wv = reinterpret_cast<Valtype*>(view);
+ typename elfcpp::Elf_types<64>::Elf_Addr value;
+ if (addend >= 0)
+ value = psymval->value(object, addend);
+ else
+ {
+ // For negative addends, get the symbol value without
+ // the addend, then add the addend using 64-bit arithmetic.
+ value = psymval->value(object, 0);
+ value += addend;
+ }
+ value -= address;
+ elfcpp::Swap<32, false>::writeval(wv, value);
+ return (Bits<32>::has_overflow(value)
+ ? Base::RELOC_OVERFLOW : Base::RELOC_OK);
+ }
+};
+