Update from https://crrev.com/315085

This includes the switch to libc++ on Android.

Other fixes:

*) Add (dumb) impl of OrderingBarrier() to command buffer
*) "base/debug/trace_event.h" -> "base/trace_event/trace_event.h"
*) Added a few <cmath> includes to sky

Review URL: https://codereview.chromium.org/903273002
diff --git a/third_party/binutils/Linux_ia32/binutils.tar.bz2.sha1 b/third_party/binutils/Linux_ia32/binutils.tar.bz2.sha1
index e15eeb1..94c02d2 100644
--- a/third_party/binutils/Linux_ia32/binutils.tar.bz2.sha1
+++ b/third_party/binutils/Linux_ia32/binutils.tar.bz2.sha1
@@ -1 +1 @@
-fd80d8d02666517d0781d3039499b4131e5d3e4e
\ No newline at end of file
+e73c227c9cfacfc5fecaa22ee3555b90925f96c2
\ No newline at end of file
diff --git a/third_party/binutils/Linux_x64/binutils.tar.bz2.sha1 b/third_party/binutils/Linux_x64/binutils.tar.bz2.sha1
index e2d07aa..b415234 100644
--- a/third_party/binutils/Linux_x64/binutils.tar.bz2.sha1
+++ b/third_party/binutils/Linux_x64/binutils.tar.bz2.sha1
@@ -1 +1 @@
-905e9e6eb9b0e11f0587177cfbaf9f7822736f34
\ No newline at end of file
+05497e34b29c01dd82df76d2fbdf017d4a2c4214
\ No newline at end of file
diff --git a/third_party/binutils/README.chromium b/third_party/binutils/README.chromium
index 5daa8d7..d20934b 100644
--- a/third_party/binutils/README.chromium
+++ b/third_party/binutils/README.chromium
@@ -19,5 +19,11 @@
  * ehframe-race.patch for http://crbug.com/161942 from upstream change
    https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=635aa30e3ae9735e362cfd1cda2be9f7b65b32a2
 
+ * unlock-thin.patch for http://crbug.com/453195 from upstream change
+   https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=2cfbf2fece582c29df348104b28677c38a8301f4
+
+ * plugin-dso-fix.patch for http://crbug.com/453195 from upstream change
+   https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=3c537f7fdb11f02f7082749f3f21dfdd2c2025e8
+
  * (build-all.sh|build-one.sh|upload.sh) scripts for building the binutils
    binaries and uploading them to Google storage.
diff --git a/third_party/binutils/build-all.sh b/third_party/binutils/build-all.sh
index fc00db1..a39984c 100755
--- a/third_party/binutils/build-all.sh
+++ b/third_party/binutils/build-all.sh
@@ -44,6 +44,8 @@
   (
     cd binutils-$VERSION
     patch -p1 < ../ehframe-race.patch
+    patch -p1 < ../unlock-thin.patch
+    patch -p1 < ../plugin-dso-fix.patch
   )
 fi
 
@@ -106,6 +108,10 @@
   # Copy them out of the chroot
   cp -a "$BUILDDIR/output/$ARCHNAME" "$OUTPUTDIR"
 
+  # Copy plugin header out of the chroot
+  mkdir "$OUTPUTDIR/$ARCHNAME/include"
+  cp "$BUILDDIR/binutils-$VERSION/include/plugin-api.h" "$OUTPUTDIR/$ARCHNAME/include/"
+
   # Clean up chroot
   sudo rm -rf "$BUILDDIR"
 done
diff --git a/third_party/binutils/plugin-dso-fix.patch b/third_party/binutils/plugin-dso-fix.patch
new file mode 100644
index 0000000..5589756
--- /dev/null
+++ b/third_party/binutils/plugin-dso-fix.patch
@@ -0,0 +1,97 @@
+commit 3c537f7fdb11f02f7082749f3f21dfdd2c2025e8
+Author: Peter Collingbourne <pcc@google.com>
+Date:   Wed Feb 4 09:47:28 2015 -0800
+
+    Resolve forwarding symbols in plugins.
+    
+    2015-02-04  Peter Collingbourne  <pcc@google.com>
+    
+    	* plugin.cc (Pluginobj::get_symbol_resolution_info): Resolve
+    	forwarding symbols when computing symbol resolution info for plugins.
+
+diff --git a/gold/plugin.cc b/gold/plugin.cc
+index bde8c78..68da8e3 100644
+--- a/gold/plugin.cc
++++ b/gold/plugin.cc
+@@ -914,7 +914,8 @@ is_visible_from_outside(Symbol* lsym)
+ // Get symbol resolution info.
+ 
+ ld_plugin_status
+-Pluginobj::get_symbol_resolution_info(int nsyms,
++Pluginobj::get_symbol_resolution_info(Symbol_table* symtab,
++				      int nsyms,
+ 				      ld_plugin_symbol* syms,
+ 				      int version) const
+ {
+@@ -943,6 +944,8 @@ Pluginobj::get_symbol_resolution_info(int nsyms,
+     {
+       ld_plugin_symbol* isym = &syms[i];
+       Symbol* lsym = this->symbols_[i];
++      if (lsym->is_forwarder())
++        lsym = symtab->resolve_forwards(lsym);
+       ld_plugin_symbol_resolution res = LDPR_UNKNOWN;
+ 
+       if (lsym->is_undefined())
+@@ -1511,14 +1514,16 @@ static enum ld_plugin_status
+ get_symbols(const void* handle, int nsyms, ld_plugin_symbol* syms)
+ {
+   gold_assert(parameters->options().has_plugins());
+-  Object* obj = parameters->options().plugins()->object(
++  Plugin_manager* plugins = parameters->options().plugins();
++  Object* obj = plugins->object(
+     static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
+   if (obj == NULL)
+     return LDPS_ERR;
+   Pluginobj* plugin_obj = obj->pluginobj();
+   if (plugin_obj == NULL)
+     return LDPS_ERR;
+-  return plugin_obj->get_symbol_resolution_info(nsyms, syms, 1);
++  Symbol_table* symtab = plugins->symtab();
++  return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 1);
+ }
+ 
+ // Version 2 of the above.  The only difference is that this version
+@@ -1528,14 +1533,16 @@ static enum ld_plugin_status
+ get_symbols_v2(const void* handle, int nsyms, ld_plugin_symbol* syms)
+ {
+   gold_assert(parameters->options().has_plugins());
+-  Object* obj = parameters->options().plugins()->object(
++  Plugin_manager* plugins = parameters->options().plugins();
++  Object* obj = plugins->object(
+     static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
+   if (obj == NULL)
+     return LDPS_ERR;
+   Pluginobj* plugin_obj = obj->pluginobj();
+   if (plugin_obj == NULL)
+     return LDPS_ERR;
+-  return plugin_obj->get_symbol_resolution_info(nsyms, syms, 2);
++  Symbol_table* symtab = plugins->symtab();
++  return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 2);
+ }
+ 
+ // Add a new (real) input file generated by a plugin.
+diff --git a/gold/plugin.h b/gold/plugin.h
+index ef78b84..f926879 100644
+--- a/gold/plugin.h
++++ b/gold/plugin.h
+@@ -282,6 +282,10 @@ class Plugin_manager
+   input_objects() const
+   { return this->input_objects_; }
+ 
++  Symbol_table*
++  symtab()
++  { return this->symtab_; }
++
+   Layout*
+   layout()
+   { return this->layout_; }
+@@ -396,7 +400,8 @@ class Pluginobj : public Object
+ 
+   // Fill in the symbol resolution status for the given plugin symbols.
+   ld_plugin_status
+-  get_symbol_resolution_info(int nsyms,
++  get_symbol_resolution_info(Symbol_table* symtab,
++			     int nsyms,
+ 			     ld_plugin_symbol* syms,
+ 			     int version) const;
+ 
diff --git a/third_party/binutils/unlock-thin.patch b/third_party/binutils/unlock-thin.patch
new file mode 100644
index 0000000..6a4b6a7
--- /dev/null
+++ b/third_party/binutils/unlock-thin.patch
@@ -0,0 +1,129 @@
+commit 2cfbf2fece582c29df348104b28677c38a8301f4
+Author: Cary Coutant <ccoutant@google.com>
+Date:   Tue Feb 3 19:54:57 2015 -0800
+
+    Fix a file descriptor leak in gold.
+    
+    When an LTO linker plugin claims an external member of a thin archive, gold
+    does not properly unlock the file and make its file descriptor available for
+    reuse. This patch fixes the problem by modifying Archive::include_member to
+    unlock the object file via an RAII class instance, ensuring that it will be
+    unlocked no matter what path is taken through the function.
+    
+    gold/
+    	PR gold/15660
+    	* archive.cc (Thin_archive_object_unlocker): New class.
+    	(Archive::include_member): Unlock external members of thin archives.
+    	* testsuite/Makefile.am (plugin_test_1): Rename .syms files.
+    	(plugin_test_2): Likewise.
+    	(plugin_test_3): Likewise.
+    	(plugin_test_4): Likewise.
+    	(plugin_test_5): Likewise.
+    	(plugin_test_6): Likewise.
+    	(plugin_test_7): Likewise.
+    	(plugin_test_8): Likewise.
+    	(plugin_test_9): Likewise.
+    	(plugin_test_10): Likewise.
+    	(plugin_test_11): New test case.
+    	* testsuite/Makefile.in: Regenerate.
+    	* testsuite/plugin_test.c (claim_file_hook): Check for parallel .syms
+    	file to decide whether to claim file.
+    	(all_symbols_read_hook): Likewise.
+    	* testsuite/plugin_test_1.sh: Adjust expected output.
+    	* testsuite/plugin_test_2.sh: Likewise.
+    	* testsuite/plugin_test_3.sh: Likewise.
+    	* testsuite/plugin_test_6.sh: Likewise.
+    	* testsuite/plugin_test_tls.sh: Likewise.
+    	* testsuite/plugin_test_11.sh: New testcase.
+
+diff --git a/gold/archive.cc b/gold/archive.cc
+index 69107f5..6d25980 100644
+--- a/gold/archive.cc
++++ b/gold/archive.cc
+@@ -930,6 +930,32 @@ Archive::count_members()
+   return ret;
+ }
+ 
++// RAII class to ensure we unlock the object if it's a member of a
++// thin archive. We can't use Task_lock_obj in Archive::include_member
++// because the object file is already locked when it's opened by
++// get_elf_object_for_member.
++
++class Thin_archive_object_unlocker
++{
++ public:
++  Thin_archive_object_unlocker(const Task *task, Object* obj)
++    : task_(task), obj_(obj)
++  { }
++
++  ~Thin_archive_object_unlocker()
++  {
++    if (this->obj_->offset() == 0)
++      this->obj_->unlock(this->task_);
++  }
++
++ private:
++  Thin_archive_object_unlocker(const Thin_archive_object_unlocker&);
++  Thin_archive_object_unlocker& operator=(const Thin_archive_object_unlocker&);
++
++  const Task* task_;
++  Object* obj_;
++};
++
+ // Include an archive member in the link.  OFF is the file offset of
+ // the member header.  WHY is the reason we are including this member.
+ // Return true if we added the member or if we had an error, return
+@@ -978,6 +1004,10 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
+       return unconfigured ? false : true;
+     }
+ 
++  // If the object is an external member of a thin archive,
++  // unlock it when we're done here.
++  Thin_archive_object_unlocker unlocker(this->task_, obj);
++
+   if (mapfile != NULL)
+     mapfile->report_include_archive_member(obj->name(), sym, why);
+ 
+@@ -991,31 +1021,21 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
+ 
+   if (!input_objects->add_object(obj))
+     {
+-      // If this is an external member of a thin archive, unlock the
+-      // file.
+-      if (obj->offset() == 0)
+-	obj->unlock(this->task_);
+       delete obj;
++      return true;
+     }
+-  else
+-    {
+-      {
+-	if (layout->incremental_inputs() != NULL)
+-	  layout->incremental_inputs()->report_object(obj, 0, this, NULL);
+-	Read_symbols_data sd;
+-	obj->read_symbols(&sd);
+-	obj->layout(symtab, layout, &sd);
+-	obj->add_symbols(symtab, &sd, layout);
+-      }
+-
+-      // If this is an external member of a thin archive, unlock the file
+-      // for the next task.
+-      if (obj->offset() == 0)
+-        obj->unlock(this->task_);
+ 
+-      this->included_member_ = true;
+-    }
++  if (layout->incremental_inputs() != NULL)
++    layout->incremental_inputs()->report_object(obj, 0, this, NULL);
++
++  {
++    Read_symbols_data sd;
++    obj->read_symbols(&sd);
++    obj->layout(symtab, layout, &sd);
++    obj->add_symbols(symtab, &sd, layout);
++  }
+ 
++  this->included_member_ = true;
+   return true;
+ }
+ 
diff --git a/third_party/boringssl/boringssl.gypi b/third_party/boringssl/boringssl.gypi
index 2691ef8..0750678 100644
--- a/third_party/boringssl/boringssl.gypi
+++ b/third_party/boringssl/boringssl.gypi
@@ -331,6 +331,7 @@
       'linux-arm/crypto/sha/sha256-armv4.S',
       'linux-arm/crypto/sha/sha512-armv4.S',
       'src/crypto/chacha/chacha_vec_arm.S',
+      'src/crypto/cpu-arm-asm.S',
       'src/crypto/poly1305/poly1305_arm_asm.S',
     ],
     'boringssl_linux_x86_sources': [
diff --git a/third_party/boringssl/update_gypi_and_asm.py b/third_party/boringssl/update_gypi_and_asm.py
index 476e42f..db11e64 100644
--- a/third_party/boringssl/update_gypi_and_asm.py
+++ b/third_party/boringssl/update_gypi_and_asm.py
@@ -29,6 +29,7 @@
     ('linux', 'arm'): [
         'src/crypto/poly1305/poly1305_arm_asm.S',
         'src/crypto/chacha/chacha_vec_arm.S',
+        'src/crypto/cpu-arm-asm.S',
     ],
 }
 
diff --git a/third_party/libevent/README.chromium b/third_party/libevent/README.chromium
index be4fee3..a3e5c6e 100644
--- a/third_party/libevent/README.chromium
+++ b/third_party/libevent/README.chromium
@@ -23,3 +23,4 @@
    nacl_nonsfi/event-config.h are derived from linux/ counterparts.
    nacl_nonsfi/random.c is also added to provide the random() function,
    which is missing in the newlib-based PNaCl toolchain.
+8) Apply https://github.com/libevent/libevent/commit/ea6b1df
diff --git a/third_party/libevent/evdns.c b/third_party/libevent/evdns.c
index da6ea19..6fa971c 100644
--- a/third_party/libevent/evdns.c
+++ b/third_party/libevent/evdns.c
@@ -55,7 +55,9 @@
 #endif
 
 /* #define _POSIX_C_SOURCE 200507 */
+#if !defined(_GNU_SOURCE)
 #define _GNU_SOURCE
+#endif
 
 #ifdef DNS_USE_CPU_CLOCK_FOR_ID
 #ifdef DNS_USE_OPENSSL_FOR_ID
diff --git a/third_party/libxml/libxml.gyp b/third_party/libxml/libxml.gyp
index dcc75b9..1decbe9 100644
--- a/third_party/libxml/libxml.gyp
+++ b/third_party/libxml/libxml.gyp
@@ -237,6 +237,7 @@
                 'libraries': [
                   # We need dl for dlopen() and friends.
                   '-ldl',
+                  '-lm',
                 ],
               },
             }],
diff --git a/third_party/mesa/mesa.gyp b/third_party/mesa/mesa.gyp
index bf2afcd..220bc17 100644
--- a/third_party/mesa/mesa.gyp
+++ b/third_party/mesa/mesa.gyp
@@ -46,13 +46,7 @@
       "_GLAPI_NO_EXPORTS",
     ],
     'conditions': [
-      ['OS=="android"', {
-        'defines': [
-          '__GLIBC__',
-          '_GNU_SOURCE',
-        ],
-      }],
-      ['OS=="linux"', {
+      ['OS == "linux" or OS == "android"', {
         'defines': [
           '_GNU_SOURCE',
         ],
diff --git a/third_party/protobuf/BUILD.gn b/third_party/protobuf/BUILD.gn
index 973672b..1367d8a 100644
--- a/third_party/protobuf/BUILD.gn
+++ b/third_party/protobuf/BUILD.gn
@@ -30,10 +30,13 @@
   }
 }
 
-# This condif should be applied to targets using generated code from the proto
+# This config should be applied to targets using generated code from the proto
 # compiler. It sets up the include directories properly.
 config("using_proto") {
-  include_dirs = [ "$root_gen_dir/protoc_out" ]
+  include_dirs = [
+    "src",
+    "$root_gen_dir/protoc_out",
+  ]
 }
 
 protobuf_lite_sources = [
diff --git a/third_party/protobuf/README.chromium b/third_party/protobuf/README.chromium
index 8e51806..c6bb5c2 100644
--- a/third_party/protobuf/README.chromium
+++ b/third_party/protobuf/README.chromium
@@ -38,3 +38,5 @@
 
 GetEmptyString() and GoogleOnceInit() have been uninlined, for a large savings
 in binary size.
+
+A BUILD.gn file has been added for building with GN.
diff --git a/third_party/qcms/README.chromium b/third_party/qcms/README.chromium
index fdf3394..8fb3768 100644
--- a/third_party/qcms/README.chromium
+++ b/third_party/qcms/README.chromium
@@ -51,5 +51,7 @@
    - https://code.google.com/p/chromium/issues/detail?id=401971
  - Minor variable name change: description -> description_offset
    - https://code.google.com/p/chromium/issues/detail?id=401971
+ - Avoid divisions creating sample points in the float cube LUT builder
+   - https://code.google.com/p/chromium/issues/detail?id=443863
 To regenerate google.patch:
   git diff b8456f38 src > google.patch
diff --git a/third_party/qcms/src/transform.c b/third_party/qcms/src/transform.c
index 08db142..9fd8238 100644
--- a/third_party/qcms/src/transform.c
+++ b/third_party/qcms/src/transform.c
@@ -1118,28 +1118,31 @@
 	float* src = NULL;
 	float* dest = NULL;
 	float* lut = NULL;
+	float inverse;
 
 	src = malloc(lutSize*sizeof(float));
 	dest = malloc(lutSize*sizeof(float));
 
 	if (src && dest) {
-		/* Prepare a list of points we want to sample */
+		/* Prepare a list of points we want to sample: x, y, z order */
 		l = 0;
+		inverse = 1 / (float)(samples-1);
 		for (x = 0; x < samples; x++) {
 			for (y = 0; y < samples; y++) {
 				for (z = 0; z < samples; z++) {
-					src[l++] = x / (float)(samples-1);
-					src[l++] = y / (float)(samples-1);
-					src[l++] = z / (float)(samples-1);
+					src[l++] = x * inverse; // r
+					src[l++] = y * inverse; // g
+					src[l++] = z * inverse; // b
 				}
 			}
 		}
 
 		lut = qcms_chain_transform(in, out, src, dest, lutSize);
+
 		if (lut) {
-			transform->r_clut = &lut[0];
-			transform->g_clut = &lut[1];
-			transform->b_clut = &lut[2];
+			transform->r_clut = &lut[0]; // r
+			transform->g_clut = &lut[1]; // g
+			transform->b_clut = &lut[2]; // b
 			transform->grid_size = samples;
 			if (in_type == QCMS_DATA_RGBA_8) {
 				transform->transform_fn = qcms_transform_data_tetra_clut_rgba;
@@ -1149,8 +1152,8 @@
 		}
 	}
 
-
-	//XXX: qcms_modular_transform_data may return either the src or dest buffer. If so it must not be free-ed
+	// XXX: qcms_modular_transform_data may return the lut in either the src or the
+	// dest buffer. If so, it must not be free-ed.
 	if (src && lut != src) {
 		free(src);
 	}
diff --git a/third_party/re2/patches/re2-libcxx.patch b/third_party/re2/patches/re2-libcxx.patch
index fc4dd1c..3ef6eb5 100644
--- a/third_party/re2/patches/re2-libcxx.patch
+++ b/third_party/re2/patches/re2-libcxx.patch
@@ -12,3 +12,12 @@
  
  #include <tr1/unordered_set>
  using std::tr1::unordered_set;
+@@ -54,7 +55,7 @@ using std::tr1::unordered_set;
+ #else
+
+ #include <unordered_set>
+-#if defined(WIN32) || defined(OS_ANDROID)
++#if defined(WIN32) || (defined(OS_ANDROID) && !defined(_LIBCPP_ABI_VERSION))
+ using std::tr1::unordered_set;
+ #else
+ using std::unordered_set;
diff --git a/third_party/re2/util/util.h b/third_party/re2/util/util.h
index 8350445..4f0fdb8 100644
--- a/third_party/re2/util/util.h
+++ b/third_party/re2/util/util.h
@@ -55,7 +55,7 @@
 #else
 
 #include <unordered_set>
-#if defined(WIN32) || defined(OS_ANDROID)
+#if defined(WIN32) || (defined(OS_ANDROID) && !defined(_LIBCPP_ABI_VERSION))
 using std::tr1::unordered_set;
 #else
 using std::unordered_set;