+ // R_MIPS_PCLO16
+ static inline typename This::Status
+ relpclo16(unsigned char* view, const Mips_relobj<size, big_endian>* object,
+ const Symbol_value<size>* psymval, Mips_address addend_a,
+ bool extract_addend, Mips_address address, unsigned int r_sym,
+ unsigned int rel_type, bool calculate_only,
+ Valtype* calculated_value)
+ {
+ Valtype32* wv = reinterpret_cast<Valtype32*>(view);
+ Valtype32 val = elfcpp::Swap<32, big_endian>::readval(wv);
+
+ Valtype addend = (extract_addend ? Bits<16>::sign_extend32(val & 0xffff)
+ : addend_a);
+
+ if (rel_type == elfcpp::SHT_REL)
+ {
+ // Resolve pending R_MIPS_PCHI16 relocations.
+ typename std::list<reloc_high<size, big_endian> >::iterator it =
+ pchi16_relocs.begin();
+ while (it != pchi16_relocs.end())
+ {
+ reloc_high<size, big_endian> pchi16 = *it;
+ if (pchi16.r_sym == r_sym)
+ {
+ do_relpchi16(pchi16.view, pchi16.object, pchi16.psymval,
+ pchi16.addend, pchi16.address,
+ pchi16.extract_addend, addend, calculate_only,
+ calculated_value);
+ it = pchi16_relocs.erase(it);
+ }
+ else
+ ++it;
+ }
+ }
+
+ // Resolve R_MIPS_PCLO16 relocation.
+ Valtype x = psymval->value(object, addend) - address;
+ val = Bits<32>::bit_select32(val, x, 0xffff);
+
+ if (calculate_only)
+ *calculated_value = x;
+ else
+ elfcpp::Swap<32, big_endian>::writeval(wv, val);
+
+ return This::STATUS_OKAY;
+ }
+
+ // R_MICROMIPS_PC7_S1
+ static inline typename This::Status
+ relmicromips_pc7_s1(unsigned char* view,
+ const Mips_relobj<size, big_endian>* object,
+ const Symbol_value<size>* psymval, Mips_address address,
+ Mips_address addend_a, bool extract_addend,
+ bool calculate_only, Valtype* calculated_value)
+ {
+ Valtype32* wv = reinterpret_cast<Valtype32*>(view);
+ Valtype32 val = elfcpp::Swap<32, big_endian>::readval(wv);
+
+ Valtype addend = extract_addend ? Bits<8>::sign_extend32((val & 0x7f) << 1)
+ : addend_a;
+
+ Valtype x = psymval->value(object, addend) - address;
+ val = Bits<16>::bit_select32(val, x >> 1, 0x7f);
+
+ if (calculate_only)
+ {
+ *calculated_value = x >> 1;
+ return This::STATUS_OKAY;
+ }
+ else
+ elfcpp::Swap<32, big_endian>::writeval(wv, val);
+
+ return check_overflow<8>(x);
+ }
+
+ // R_MICROMIPS_PC10_S1
+ static inline typename This::Status
+ relmicromips_pc10_s1(unsigned char* view,
+ const Mips_relobj<size, big_endian>* object,
+ const Symbol_value<size>* psymval, Mips_address address,
+ Mips_address addend_a, bool extract_addend,
+ bool calculate_only, Valtype* calculated_value)
+ {
+ Valtype32* wv = reinterpret_cast<Valtype32*>(view);
+ Valtype32 val = elfcpp::Swap<32, big_endian>::readval(wv);
+
+ Valtype addend = (extract_addend
+ ? Bits<11>::sign_extend32((val & 0x3ff) << 1)
+ : addend_a);
+
+ Valtype x = psymval->value(object, addend) - address;
+ val = Bits<16>::bit_select32(val, x >> 1, 0x3ff);
+
+ if (calculate_only)
+ {
+ *calculated_value = x >> 1;
+ return This::STATUS_OKAY;
+ }
+ else
+ elfcpp::Swap<32, big_endian>::writeval(wv, val);
+
+ return check_overflow<11>(x);
+ }
+
+ // R_MICROMIPS_PC16_S1
+ static inline typename This::Status
+ relmicromips_pc16_s1(unsigned char* view,
+ const Mips_relobj<size, big_endian>* object,
+ const Symbol_value<size>* psymval, Mips_address address,
+ Mips_address addend_a, bool extract_addend,
+ bool calculate_only, Valtype* calculated_value)
+ {
+ Valtype32* wv = reinterpret_cast<Valtype32*>(view);
+ Valtype32 val = elfcpp::Swap<32, big_endian>::readval(wv);
+
+ Valtype addend = (extract_addend
+ ? Bits<17>::sign_extend32((val & 0xffff) << 1)
+ : addend_a);
+
+ Valtype x = psymval->value(object, addend) - address;
+ val = Bits<16>::bit_select32(val, x >> 1, 0xffff);
+
+ if (calculate_only)
+ {
+ *calculated_value = x >> 1;
+ return This::STATUS_OKAY;
+ }
+ else
+ elfcpp::Swap<32, big_endian>::writeval(wv, val);
+
+ return check_overflow<17>(x);
+ }
+
+ // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
+ static inline typename This::Status
+ relhi16(unsigned char* view, const Mips_relobj<size, big_endian>* object,
+ const Symbol_value<size>* psymval, Mips_address addend,
+ Mips_address address, bool gp_disp, unsigned int r_type,
+ unsigned int r_sym, bool extract_addend)
+ {
+ // Record the relocation. It will be resolved when we find lo16 part.
+ hi16_relocs.push_back(reloc_high<size, big_endian>(view, object, psymval,
+ addend, r_type, r_sym, extract_addend, address,
+ gp_disp));
+ return This::STATUS_OKAY;
+ }
+
+ // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
+ static inline typename This::Status
+ do_relhi16(unsigned char* view, const Mips_relobj<size, big_endian>* object,
+ const Symbol_value<size>* psymval, Mips_address addend_hi,
+ Mips_address address, bool is_gp_disp, unsigned int r_type,
+ bool extract_addend, Valtype32 addend_lo,
+ Target_mips<size, big_endian>* target, bool calculate_only,
+ Valtype* calculated_value)
+ {
+ Valtype32* wv = reinterpret_cast<Valtype32*>(view);
+ Valtype32 val = elfcpp::Swap<32, big_endian>::readval(wv);
+
+ Valtype addend = (extract_addend ? ((val & 0xffff) << 16) + addend_lo
+ : addend_hi);
+
+ Valtype32 value;
+ if (!is_gp_disp)
+ value = psymval->value(object, addend);
+ else
+ {
+ // For MIPS16 ABI code we generate this sequence
+ // 0: li $v0,%hi(_gp_disp)
+ // 4: addiupc $v1,%lo(_gp_disp)
+ // 8: sll $v0,16
+ // 12: addu $v0,$v1
+ // 14: move $gp,$v0
+ // So the offsets of hi and lo relocs are the same, but the
+ // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
+ // ADDIUPC clears the low two bits of the instruction address,
+ // so the base is ($t9 + 4) & ~3.
+ Valtype32 gp_disp;
+ if (r_type == elfcpp::R_MIPS16_HI16)
+ gp_disp = (target->adjusted_gp_value(object)
+ - ((address + 4) & ~0x3));
+ // The microMIPS .cpload sequence uses the same assembly
+ // instructions as the traditional psABI version, but the
+ // incoming $t9 has the low bit set.
+ else if (r_type == elfcpp::R_MICROMIPS_HI16)
+ gp_disp = target->adjusted_gp_value(object) - address - 1;
+ else
+ gp_disp = target->adjusted_gp_value(object) - address;
+ value = gp_disp + addend;
+ }
+ Valtype x = ((value + 0x8000) >> 16) & 0xffff;
+ val = Bits<32>::bit_select32(val, x, 0xffff);
+
+ if (calculate_only)
+ {
+ *calculated_value = x;
+ return This::STATUS_OKAY;
+ }
+ else
+ elfcpp::Swap<32, big_endian>::writeval(wv, val);
+
+ return (is_gp_disp ? check_overflow<16>(x)
+ : This::STATUS_OKAY);
+ }
+
+ // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16