From d577748c041aa6df599218f3cb31697ecf032730 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 12 Nov 2014 17:02:02 +0000 Subject: [PATCH] Fix LinkFieldsComparator. Define order for primitive types with the same sizes. Previously, the comparator would consider the fields equal so the order would depend on std::sort() implementation. Changing the STL implementation could silently change the field offsets. (And, unlike std::stable_sort(), the std::sort() doesn't even need to be deterministic.) Change-Id: I91fa562f82447606aced64643bea8c70784766b5 --- runtime/class_linker.cc | 25 +++++++++++++++---------- runtime/oat.cc | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index fb90b911b..ea48a32d7 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -5202,17 +5202,22 @@ struct LinkFieldsComparator { Primitive::Type type1 = field1->GetTypeAsPrimitiveType(); Primitive::Type type2 = field2->GetTypeAsPrimitiveType(); if (type1 != type2) { - bool is_primitive1 = type1 != Primitive::kPrimNot; - bool is_primitive2 = type2 != Primitive::kPrimNot; - if (type1 != type2) { - if (is_primitive1 && is_primitive2) { - // Larger primitive types go first. - return Primitive::ComponentSize(type1) > Primitive::ComponentSize(type2); - } else { - // Reference always goes first. - return !is_primitive1; - } + if (type1 == Primitive::kPrimNot) { + // Reference always goes first. + return true; + } + if (type2 == Primitive::kPrimNot) { + // Reference always goes first. + return false; + } + size_t size1 = Primitive::ComponentSize(type1); + size_t size2 = Primitive::ComponentSize(type2); + if (size1 != size2) { + // Larger primitive types go first. + return size1 > size2; } + // Primitive types differ but sizes match. Arbitrarily order by primitive type. + return type1 < type2; } // same basic group? then sort by string. return strcmp(field1->GetName(), field2->GetName()) < 0; diff --git a/runtime/oat.cc b/runtime/oat.cc index 0749c0655..b280e04bb 100644 --- a/runtime/oat.cc +++ b/runtime/oat.cc @@ -23,7 +23,7 @@ namespace art { const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' }; -const uint8_t OatHeader::kOatVersion[] = { '0', '4', '6', '\0' }; +const uint8_t OatHeader::kOatVersion[] = { '0', '4', '7', '\0' }; static size_t ComputeOatHeaderSize(const SafeMap* variable_data) { size_t estimate = 0U; -- 2.11.0