Upgrade rust/crates/libfuzzer-sys to 0.4.2 am: 577945a102 am: 6d1535b6bc

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/libfuzzer-sys/+/1742518

Change-Id: Ice6643a6b9a9ced4f1ac88075405c74218ca650c
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 99e3306..4d6cfd1 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "062f36b424c6dcdbd403c3a5d4384d731c8a3f84"
+    "sha1": "a89115ac1105fa0c7c7d9cb5cdb479af36031aff"
   }
 }
diff --git a/Android.bp b/Android.bp
index 806370f..1448d8e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -43,6 +43,7 @@
     features: ["arbitrary-derive"],
     rustlibs: [
         "libarbitrary",
+        "libonce_cell",
     ],
 }
 
@@ -50,7 +51,8 @@
 //   arbitrary-1.0.1 "derive,derive_arbitrary"
 //   cc-1.0.68
 //   derive_arbitrary-1.0.1
+//   once_cell-1.8.0 "alloc,default,race,std"
 //   proc-macro2-1.0.27 "default,proc-macro"
 //   quote-1.0.9 "default,proc-macro"
-//   syn-1.0.72 "clone-impls,default,derive,parsing,printing,proc-macro,quote"
+//   syn-1.0.73 "clone-impls,default,derive,parsing,printing,proc-macro,quote"
 //   unicode-xid-0.2.2 "default"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f0e6039..77be1fd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,19 @@
 
 --------------------------------------------------------------------------------
 
+## 0.4.2
+
+Released 2020-05-26.
+
+### Changed
+
+* Improved performance of checking for whether `cargo fuzz` is requesting the
+  `std::fmt::Debug` output of an input or not. This is always false during
+  regular fuzzing, so making this check faster should give slightly better
+  fuzzing throughput.
+
+--------------------------------------------------------------------------------
+
 ## 0.4.1
 
 Released 2020-05-13.
diff --git a/Cargo.toml b/Cargo.toml
index 6476065..4be2136 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 [package]
 edition = "2018"
 name = "libfuzzer-sys"
-version = "0.4.1"
+version = "0.4.2"
 authors = ["The rust-fuzz Project Developers"]
 description = "A wrapper around LLVM's libFuzzer runtime."
 readme = "./README.md"
@@ -21,6 +21,9 @@
 repository = "https://github.com/rust-fuzz/libfuzzer"
 [dependencies.arbitrary]
 version = "1"
+
+[dependencies.once_cell]
+version = "1"
 [dev-dependencies.flate2]
 version = "1.0.20"
 
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index adfe66d..72285b9 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -6,10 +6,11 @@
 name = "libfuzzer-sys"
 readme = "./README.md"
 repository = "https://github.com/rust-fuzz/libfuzzer"
-version = "0.4.1"
+version = "0.4.2"
 
 [dependencies]
 arbitrary = "1"
+once_cell = "1"
 
 [build-dependencies]
 cc = "1.0"
diff --git a/METADATA b/METADATA
index fb5ab95..abca0eb 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/libfuzzer-sys/libfuzzer-sys-0.4.1.crate"
+    value: "https://static.crates.io/crates/libfuzzer-sys/libfuzzer-sys-0.4.2.crate"
   }
-  version: "0.4.1"
+  version: "0.4.2"
   license_type: NOTICE
   last_upgrade_date {
     year: 2021
-    month: 5
-    day: 19
+    month: 6
+    day: 21
   }
 }
diff --git a/ci/script.sh b/ci/script.sh
index b94de7b..91fad80 100755
--- a/ci/script.sh
+++ b/ci/script.sh
@@ -56,3 +56,5 @@
       -Zsanitizer=address
 (! $CARGO_TARGET_DIR/release/example_mutator -runs=10000000)
 popd
+
+echo "All good!"
diff --git a/src/lib.rs b/src/lib.rs
index 9262eca..6badc39 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,6 +12,7 @@
 #![deny(missing_docs, missing_debug_implementations)]
 
 pub use arbitrary;
+use once_cell::sync::OnceCell;
 
 extern "C" {
     // We do not actually cross the FFI bound here.
@@ -37,6 +38,9 @@
 }
 
 #[doc(hidden)]
+pub static RUST_LIBFUZZER_DEBUG_PATH: OnceCell<String> = OnceCell::new();
+
+#[doc(hidden)]
 #[export_name = "LLVMFuzzerInitialize"]
 pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize {
     // Registers a panic hook that aborts the process before unwinding.
@@ -52,6 +56,14 @@
         default_hook(panic_info);
         ::std::process::abort();
     }));
+
+    // Initialize the `RUST_LIBFUZZER_DEBUG_PATH` cell with the path so it can be
+    // reused with little overhead.
+    if let Ok(path) = std::env::var("RUST_LIBFUZZER_DEBUG_PATH") {
+        RUST_LIBFUZZER_DEBUG_PATH
+            .set(path)
+            .expect("Since this is initialize it is only called once so can never fail");
+    }
     0
 }
 
@@ -130,7 +142,9 @@
             // When `RUST_LIBFUZZER_DEBUG_PATH` is set, write the debug
             // formatting of the input to that file. This is only intended for
             // `cargo fuzz`'s use!
-            if let Ok(path) = std::env::var("RUST_LIBFUZZER_DEBUG_PATH") {
+
+            // `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
+            if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() {
                 use std::io::Write;
                 let mut file = std::fs::File::create(path)
                     .expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file");
@@ -151,7 +165,7 @@
         /// Auto-generated function
         #[no_mangle]
         pub extern "C" fn rust_fuzzer_test_input(bytes: &[u8]) {
-            use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured};
+            use $crate::arbitrary::{Arbitrary, Unstructured};
 
             // Early exit if we don't have enough bytes for the `Arbitrary`
             // implementation. This helps the fuzzer avoid exploring all the
@@ -169,7 +183,9 @@
             // When `RUST_LIBFUZZER_DEBUG_PATH` is set, write the debug
             // formatting of the input to that file. This is only intended for
             // `cargo fuzz`'s use!
-            if let Ok(path) = std::env::var("RUST_LIBFUZZER_DEBUG_PATH") {
+
+            // `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
+            if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() {
                 use std::io::Write;
                 let mut file = std::fs::File::create(path)
                     .expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file");