Merge "Try new host toolchain" into idea133
diff --git a/android-configure.sh b/android-configure.sh
index 1c1ab0a..e7abc38 100755
--- a/android-configure.sh
+++ b/android-configure.sh
@@ -528,7 +528,7 @@
 esac
 
 # Strip executables and shared libraries unless --debug is used.
-if [ "$OPTION_DEBUG" != "yes" ]; then
+if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_NO_STRIP" != "yes" ]; then
     case $HOST_OS in
         darwin)
             LDFLAGS="$LDFLAGS -Wl,-S"
diff --git a/android/avd/info.c b/android/avd/info.c
index 405fd04..56f46e1 100644
--- a/android/avd/info.c
+++ b/android/avd/info.c
@@ -978,6 +978,16 @@
             suffix = "-armv7";
         }
 
+        if (!strcmp(i->targetAbi, "x86_64")) {
+            suffix = "-x86_64";
+        }
+
+        p = bufprint(temp, end, "%s/kernel", i->androidOut);
+        if (p < end && path_exists(temp)) {
+            kernelPath = ASTRDUP(temp);
+            break;
+        }
+
         p = bufprint(temp, end, "%s/prebuilts/qemu-kernel/%s/kernel-qemu%s",
                      i->androidBuildRoot, i->targetArch, suffix);
         if (p >= end || !path_exists(temp)) {
diff --git a/distrib/mini-glib/src/glib-mini.c b/distrib/mini-glib/src/glib-mini.c
index 9a954be..65b5802 100644
--- a/distrib/mini-glib/src/glib-mini.c
+++ b/distrib/mini-glib/src/glib-mini.c
@@ -15,6 +15,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 
 // Print a panic message then exit the program immediately.
@@ -397,17 +398,25 @@
 #define HASH_MIN_SHIFT  3
 #define HASH_MIN_CAPACITY  (1 << HASH_MIN_SHIFT)
 
+#define HASH_LOAD_SCALE 1024
+#define HASH_MIN_LOAD   256
+#define HASH_MAX_LOAD   768
+
 struct _GHashTable {
   int ref_count;
   int num_items;
   int num_used;  // count of items + tombstones
-  int shift;
   int capacity;
   GHashEntry* entries;
   GHashFunc hash_func;
   GEqualFunc key_equal_func;
 };
 
+// Default hash function for pointers.
+static guint _gpointer_hash(gconstpointer key) {
+    return (guint)(uintptr_t)key;
+}
+
 // Compute the hash value of a given key.
 static inline size_t
 _g_hash_table_hash(GHashTable* table, gconstpointer key) {
@@ -424,7 +433,7 @@
   hash_table->num_items = 0;
   hash_table->capacity = HASH_MIN_CAPACITY;
   hash_table->entries = g_new0(GHashEntry, hash_table->capacity);
-  hash_table->hash_func = hash_func;
+  hash_table->hash_func = hash_func ? hash_func : &_gpointer_hash;
   hash_table->key_equal_func = key_equal_func;
 
   return hash_table;
@@ -552,7 +561,7 @@
 static void _g_hash_table_resize(GHashTable* hash_table) {
   guint old_capacity = hash_table->capacity;
 
-  // Compute new shift from new size
+  // Compute new capacity from new size
   guint new_size = hash_table->num_items * 2;
   guint new_capacity = HASH_MIN_CAPACITY;
   while (new_capacity < new_size)
@@ -587,11 +596,22 @@
 
 // Resize the hash table if needed.
 static void _g_hash_table_maybe_resize(GHashTable* hash_table) {
-  guint used = hash_table->num_used;
   guint count = hash_table->num_items;
   guint capacity = hash_table->capacity;
-  if ((capacity > count * 4 && capacity > HASH_MIN_CAPACITY) ||
-      capacity < used + (used / 16)) {
+  // Computations explained.
+  //
+  // load < min_load i.e.
+  // => used / capacity < min_load
+  // => used < min_load * capacity
+  // => used * HASH_SCALE < HASH_MIN_LOAD * capacity
+  //
+  // load > max_load
+  // => used / capacity > max_load
+  // => used * HASH_SCALER > HASH_MAX_LOAD * capacity
+  uint64_t load = (uint64_t)count * HASH_LOAD_SCALE;
+  uint64_t min_load = (uint64_t)capacity * HASH_MIN_LOAD;
+  uint64_t max_load = (uint64_t)capacity * HASH_MAX_LOAD;
+  if (load < min_load || load > max_load) {
     _g_hash_table_resize(hash_table);
   }
 }
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index 2543eb7..d980a05 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -3420,9 +3420,14 @@
 
 static inline CPU86_LDouble helper_fdiv(CPU86_LDouble a, CPU86_LDouble b)
 {
-    if (b == 0.0)
+    // NOTE: work-around to prevent a mysterious crash
+    // This code will be replaced by better one in a future patch.
+    if (float64_is_zero(b)) {
         fpu_set_exception(FPUS_ZE);
-    return a / b;
+        return float64_div(a, b, &env->fp_status);
+    } else {
+        return a / b;
+    }
 }
 
 static void fpu_raise_exception(void)
diff --git a/vl-android.c b/vl-android.c
index 4493597..87cb06b 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -3587,9 +3587,6 @@
 
         snprintf(tmp,sizeof(tmp),"cache,size=0x%" PRIx64, partSize);
 
-        // NOTE: Assume the /cache and /data partitions have the same format
-        cacheImageIsExt4 = dataImageIsExt4;
-
         if (partPath && *partPath && strcmp(partPath, "<temp>") != 0) {
             if (filelock_create(partPath) == NULL) {
                 fprintf(stderr, "WARNING: Cache partition already in use. Changes will not persist!\n");
@@ -3607,6 +3604,14 @@
                 pstrcat(tmp, sizeof(tmp), partPath);
             }
         }
+        // NOTE: The following line is commented to avoid problems with the
+        // current state of the emulator and AOSP/master. In a nutshell,
+        // take it out of the comment once proper support for generating
+        // EXT4 partitions on demand is added to the emulator, and
+        //  /etc/fstab.goldfish is modified to mount an EXT4, not YAFFS2,
+        // partition for /cache.
+        //
+        // cacheImageIsExt4 = partPath && android_pathIsExt4PartitionImage(partPath);
         if (cacheImageIsExt4) {
             /* Using a nand device to approximate a block device until full
              * support is added */