Add tests for Thumb2RelativePatcher.
Also make the thumb2/arm64 thunk allocation precise instead
of eagerly allocating thunk space. This allows the calls to
use the maximum positive offset.
Change-Id: Ifa95b0bb00bd73eeab0c2905d21e2f3078f4b0a8
diff --git a/compiler/linker/relative_patcher_test.h b/compiler/linker/relative_patcher_test.h
index 515355b..9efcf60 100644
--- a/compiler/linker/relative_patcher_test.h
+++ b/compiler/linker/relative_patcher_test.h
@@ -63,6 +63,7 @@
}
MethodReference MethodRef(uint32_t method_idx) {
+ CHECK_NE(method_idx, 0u);
return MethodReference(nullptr, method_idx);
}
@@ -83,7 +84,7 @@
uint32_t offset = kTrampolineSize;
size_t idx = 0u;
for (auto& compiled_method : compiled_methods_) {
- offset = patcher_->ReserveSpace(offset, compiled_method.get());
+ offset = patcher_->ReserveSpace(offset, compiled_method.get(), compiled_method_refs_[idx]);
uint32_t aligned_offset = compiled_method->AlignCode(offset);
uint32_t aligned_code_delta = aligned_offset - offset;
@@ -97,7 +98,7 @@
method_offset_map_.map.Put(compiled_method_refs_[idx], quick_code_offset);
++idx;
}
- offset = patcher_->ReserveSpace(offset, nullptr);
+ offset = patcher_->ReserveSpace(offset, nullptr, MethodReference(nullptr, 0u));
uint32_t output_size = offset;
output_.reserve(output_size);
@@ -166,7 +167,7 @@
auto result = method_offset_map_.FindMethodOffset(method_ref);
CHECK(result.first); // Must have been linked.
- size_t offset = result.second;
+ size_t offset = result.second - compiled_methods_[idx]->CodeDelta();
CHECK_LT(offset, output_.size());
CHECK_LE(offset + expected_code.size(), output_.size());
ArrayRef<const uint8_t> linked_code(&output_[offset], expected_code.size());
@@ -174,6 +175,12 @@
return true;
}
// Log failure info.
+ DumpDiff(expected_code, linked_code);
+ return false;
+ }
+
+ void DumpDiff(const ArrayRef<const uint8_t>& expected_code,
+ const ArrayRef<const uint8_t>& linked_code) {
std::ostringstream expected_hex;
std::ostringstream linked_hex;
std::ostringstream diff_indicator;
@@ -193,7 +200,6 @@
LOG(ERROR) << "<" << expected_hex.str();
LOG(ERROR) << ">" << linked_hex.str();
LOG(ERROR) << " " << diff_indicator.str();
- return false;
}
// Map method reference to assinged offset.