- // TODO(Vladimir)
- // Check if the next relocation is for the same instruction.
- calculate_only = i == 2 ? false
- : r_types[i+1] != elfcpp::R_MIPS_NONE;
+ // If we didn't apply previous relocation, use its result as addend
+ // for current.
+ if (this->calculate_only_)
+ {
+ r_addend = this->calculated_value_;
+ extract_addend = false;
+ }
+
+ // In the N32 and 64-bit ABIs there may be multiple consecutive
+ // relocations for the same offset. In that case we are
+ // supposed to treat the output of each relocation as the addend
+ // for the next. For N64 ABI, we are checking offsets only in a
+ // third operation in a record (r_type3).
+ this->calculate_only_ =
+ (object->is_n64() && i < 2
+ ? r_types[i+1] != elfcpp::R_MIPS_NONE
+ : (r_offset == next_r_offset) && (next_r_type != elfcpp::R_MIPS_NONE));