Auto merge of #56092 - alexcrichton:no-more-std-subodules, r=Mark-Simulacrum

std: Depend directly on crates.io crates

Ever since we added a Cargo-based build system for the compiler the
standard library has always been a little special, it's never been able
to depend on crates.io crates for runtime dependencies. This has been a
result of various limitations, namely that Cargo doesn't understand that
crates from crates.io depend on libcore, so Cargo tries to build crates
before libcore is finished.

I had an idea this afternoon, however, which lifts the strategy
from #52919 to directly depend on crates.io crates from the standard
library. After all is said and done this removes a whopping three
submodules that we need to manage!

The basic idea here is that for any crate `std` depends on it adds an
*optional* dependency on an empty crate on crates.io, in this case named
`rustc-std-workspace-core`. This crate is overridden via `[patch]` in
this repository to point to a local crate we write, and *that* has a
`path` dependency on libcore.

Note that all `no_std` crates also depend on `compiler_builtins`, but if
we're not using submodules we can publish `compiler_builtins` to
crates.io and all crates can depend on it anyway! The basic strategy
then looks like:

* The standard library (or some transitive dep) decides to depend on a
  crate `foo`.
* The standard library adds

  ```toml
  [dependencies]
  foo = { version = "0.1", features = ['rustc-dep-of-std'] }
  ```
* The crate `foo` has an optional dependency on `rustc-std-workspace-core`
* The crate `foo` has an optional dependency on `compiler_builtins`
* The crate `foo` has a feature `rustc-dep-of-std` which activates these
  crates and any other necessary infrastructure in the crate.

A sample commit for `dlmalloc` [turns out to be quite simple][commit].
After that all `no_std` crates should largely build "as is" and still be
publishable on crates.io! Notably they should be able to continue to use
stable Rust if necessary, since the `rename-dependency` feature of Cargo
is soon stabilizing.

As a proof of concept, this commit removes the `dlmalloc`,
`libcompiler_builtins`, and `libc` submodules from this repository. Long
thorns in our side these are now gone for good and we can directly
depend on crates.io! It's hoped that in the long term we can bring in
other crates as necessary, but for now this is largely intended to
simply make it easier to manage these crates and remove submodules.

This should be a transparent non-breaking change for all users, but one
possible stickler is that this almost for sure breaks out-of-tree
`std`-building tools like `xargo` and `cargo-xbuild`. I think it should
be relatively easy to get them working, however, as all that's needed is
an entry in the `[patch]` section used to build the standard library.
Hopefully we can work with these tools to solve this problem!

[commit]: https://github.com/alexcrichton/dlmalloc-rs/commit/28ee12db813a3b650a7c25d1c36d2c17dcb88ae3
diff --git a/.gitmodules b/.gitmodules
index 3fc6e45..70164d4 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -5,9 +5,6 @@
 [submodule "src/rust-installer"]
 	path = src/tools/rust-installer
 	url = https://github.com/rust-lang/rust-installer.git
-[submodule "src/liblibc"]
-	path = src/liblibc
-	url = https://github.com/rust-lang/libc.git
 [submodule "src/doc/nomicon"]
 	path = src/doc/nomicon
 	url = https://github.com/rust-lang-nursery/nomicon.git
@@ -23,9 +20,6 @@
 [submodule "src/tools/rls"]
 	path = src/tools/rls
 	url = https://github.com/rust-lang-nursery/rls.git
-[submodule "src/libcompiler_builtins"]
-	path = src/libcompiler_builtins
-	url = https://github.com/rust-lang-nursery/compiler-builtins.git
 [submodule "src/tools/clippy"]
 	path = src/tools/clippy
 	url = https://github.com/rust-lang-nursery/rust-clippy.git
@@ -35,9 +29,6 @@
 [submodule "src/tools/miri"]
 	path = src/tools/miri
 	url = https://github.com/solson/miri.git
-[submodule "src/dlmalloc"]
-	path = src/dlmalloc
-	url = https://github.com/alexcrichton/dlmalloc-rs.git
 [submodule "src/doc/rust-by-example"]
 	path = src/doc/rust-by-example
 	url = https://github.com/rust-lang/rust-by-example.git
@@ -67,6 +58,3 @@
 [submodule "src/doc/edition-guide"]
 	path = src/doc/edition-guide
 	url = https://github.com/rust-lang-nursery/edition-guide
-[submodule "src/rust-sgx"]
-	path = src/rust-sgx
-	url = https://github.com/fortanix/rust-sgx
diff --git a/Cargo.lock b/Cargo.lock
index c3c8812..d22a910 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -15,9 +15,9 @@
 name = "alloc"
 version = "0.0.0"
 dependencies = [
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
- "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -407,10 +407,11 @@
 
 [[package]]
 name = "compiler_builtins"
-version = "0.0.0"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
- "core 0.0.0",
+ "rustc-std-workspace-core 1.0.0",
 ]
 
 [[package]]
@@ -456,7 +457,7 @@
 name = "core"
 version = "0.0.0"
 dependencies = [
- "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -658,10 +659,12 @@
 
 [[package]]
 name = "dlmalloc"
-version = "0.0.0"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "compiler_builtins 0.0.0",
- "core 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-std-workspace-core 1.0.0",
 ]
 
 [[package]]
@@ -814,10 +817,11 @@
 
 [[package]]
 name = "fortanix-sgx-abi"
-version = "0.0.0"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "compiler_builtins 0.0.0",
- "core 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-std-workspace-core 1.0.0",
 ]
 
 [[package]]
@@ -1140,16 +1144,11 @@
 
 [[package]]
 name = "libc"
-version = "0.0.0"
-dependencies = [
- "compiler_builtins 0.0.0",
- "core 0.0.0",
-]
-
-[[package]]
-name = "libc"
 version = "0.2.45"
 source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-std-workspace-core 1.0.0",
+]
 
 [[package]]
 name = "libgit2-sys"
@@ -1520,9 +1519,9 @@
 name = "panic_abort"
 version = "0.0.0"
 dependencies = [
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
- "libc 0.0.0",
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1530,9 +1529,9 @@
 version = "0.0.0"
 dependencies = [
  "alloc 0.0.0",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
- "libc 0.0.0",
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
  "unwind 0.0.0",
 ]
 
@@ -1683,7 +1682,7 @@
 version = "0.0.0"
 dependencies = [
  "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
 ]
 
@@ -1814,7 +1813,7 @@
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -1836,7 +1835,7 @@
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1861,7 +1860,7 @@
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -2243,6 +2242,13 @@
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
+name = "rustc-std-workspace-core"
+version = "1.0.0"
+dependencies = [
+ "core 0.0.0",
+]
+
+[[package]]
 name = "rustc-workspace-hack"
 version = "1.0.0"
 dependencies = [
@@ -2284,7 +2290,7 @@
  "alloc 0.0.0",
  "build_helper 0.1.0",
  "cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
 ]
 
@@ -2479,7 +2485,7 @@
  "alloc 0.0.0",
  "build_helper 0.1.0",
  "cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
 ]
 
@@ -2531,7 +2537,7 @@
  "alloc 0.0.0",
  "build_helper 0.1.0",
  "cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
 ]
 
@@ -2644,7 +2650,7 @@
  "alloc 0.0.0",
  "build_helper 0.1.0",
  "cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
 ]
 
@@ -2877,15 +2883,15 @@
  "alloc 0.0.0",
  "build_helper 0.1.0",
  "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
- "dlmalloc 0.0.0",
- "fortanix-sgx-abi 0.0.0",
- "libc 0.0.0",
+ "dlmalloc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fortanix-sgx-abi 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
  "panic_abort 0.0.0",
  "panic_unwind 0.0.0",
  "profiler_builtins 0.0.0",
- "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc_asan 0.0.0",
  "rustc_lsan 0.0.0",
  "rustc_msan 0.0.0",
@@ -3217,9 +3223,9 @@
 name = "unwind"
 version = "0.0.0"
 dependencies = [
- "compiler_builtins 0.0.0",
+ "compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
- "libc 0.0.0",
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -3397,6 +3403,7 @@
 "checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc"
 "checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
 "checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
+"checksum compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ad611263b9f31bdb66e66227d3b781600fd1e68d5deee29b23f5e2ac9cb4892"
 "checksum compiletest_rs 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "89747fe073b7838343bd2c2445e7a7c2e0d415598f8925f0fa9205b9cdfc48cb"
 "checksum core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2640d6d0bf22e82bed1b73c6aef8d5dd31e5abe6666c57e6d45e2649f4f887"
 "checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b"
@@ -3418,6 +3425,7 @@
 "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
 "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
 "checksum directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72d337a64190607d4fcca2cb78982c5dd57f4916e19696b48a575fa746b6cb0f"
+"checksum dlmalloc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c46c65de42b063004b31c67a98abe071089b289ff0919c660ed7ff4f59317f8"
 "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
 "checksum elasticlunr-rs 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a99a310cd1f9770e7bf8e48810c7bcbb0e078c8fb23a8c7bcf0da4c2bf61a455"
 "checksum ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f56c93cc076508c549d9bb747f79aa9b4eb098be7b8cad8830c3137ef52d1e00"
@@ -3434,6 +3442,7 @@
 "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
 "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
 "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+"checksum fortanix-sgx-abi 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26105e20b4c3f7a319db1376b54ac9a46e5761e949405553375095d05a0cee4d"
 "checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
 "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
 "checksum fst 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d94485a00b1827b861dd9d1a2cc9764f9044d4c535514c0760a5a2012ef3399f"
diff --git a/Cargo.toml b/Cargo.toml
index b763caa..667c557 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,6 +65,10 @@
 # here
 rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
 
+# See comments in `tools/rustc-std-workspace-core/README.md` for what's going on
+# here
+rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
+
 [patch."https://github.com/rust-lang/rust-clippy"]
 clippy_lints = { path = "src/tools/clippy/clippy_lints" }
 rustc_tools_util = { path = "src/tools/clippy/rustc_tools_util" }
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 2e792b6..c84abe42 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -152,11 +152,10 @@
 
     if builder.no_std(target) == Some(true) {
         // for no-std targets we only compile a few no_std crates
-        cargo.arg("--features").arg("c mem")
+        cargo
             .args(&["-p", "alloc"])
-            .args(&["-p", "compiler_builtins"])
             .arg("--manifest-path")
-            .arg(builder.src.join("src/rustc/compiler_builtins_shim/Cargo.toml"));
+            .arg(builder.src.join("src/liballoc/Cargo.toml"));
     } else {
         let features = builder.std_features();
 
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 1ae494b..f03eefb 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -857,12 +857,9 @@
         // (essentially libstd and all of its path dependencies)
         let std_src_dirs = [
             "src/build_helper",
-            "src/dlmalloc",
             "src/liballoc",
             "src/libbacktrace",
-            "src/libcompiler_builtins",
             "src/libcore",
-            "src/liblibc",
             "src/libpanic_abort",
             "src/libpanic_unwind",
             "src/librustc_asan",
@@ -871,21 +868,15 @@
             "src/librustc_tsan",
             "src/libstd",
             "src/libunwind",
-            "src/rustc/compiler_builtins_shim",
-            "src/rustc/libc_shim",
-            "src/rustc/dlmalloc_shim",
-            "src/rustc/fortanix-sgx-abi_shim",
             "src/libtest",
             "src/libterm",
             "src/libprofiler_builtins",
             "src/stdsimd",
             "src/libproc_macro",
-        ];
-        let std_src_dirs_exclude = [
-            "src/libcompiler_builtins/compiler-rt/test",
+            "src/tools/rustc-std-workspace-core",
         ];
 
-        copy_src_dirs(builder, &std_src_dirs[..], &std_src_dirs_exclude[..], &dst_src);
+        copy_src_dirs(builder, &std_src_dirs[..], &[], &dst_src);
         for file in src_files.iter() {
             builder.copy(&builder.src.join(file), &dst_src.join(file));
         }
@@ -909,7 +900,7 @@
     }
 }
 
-const CARGO_VENDOR_VERSION: &str = "0.1.19";
+const CARGO_VENDOR_VERSION: &str = "0.1.22";
 
 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
 pub struct PlainSourceTarball;
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index c31db48..c879291 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -1134,10 +1134,10 @@
             let krate = &self.crates[&krate];
             if krate.is_local(self) {
                 ret.push(krate);
-                for dep in &krate.deps {
-                    if visited.insert(dep) && dep != "build_helper" {
-                        list.push(*dep);
-                    }
+            }
+            for dep in &krate.deps {
+                if visited.insert(dep) && dep != "build_helper" {
+                    list.push(*dep);
                 }
             }
         }
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index ca9894f..dc061fe 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -1558,10 +1558,7 @@
         let builder = run.builder;
         run = run.krate("test");
         for krate in run.builder.in_tree_crates("std") {
-            if krate.is_local(&run.builder)
-                && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
-                && krate.name != "dlmalloc"
-            {
+            if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
                 run = run.path(krate.local_path(&builder).to_str().unwrap());
             }
         }
diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs
index 0cbb080..a580a87 100644
--- a/src/build_helper/lib.rs
+++ b/src/build_helper/lib.rs
@@ -224,14 +224,12 @@
 // Timestamps are created automatically when the result of `native_lib_boilerplate` goes out
 // of scope, so all the build actions should be completed until then.
 pub fn native_lib_boilerplate(
-    src_name: &str,
+    src_dir: &Path,
     out_name: &str,
     link_name: &str,
     search_subdir: &str,
 ) -> Result<NativeLibBoilerplate, ()> {
-    let current_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
-    let src_dir = current_dir.join("..").join(src_name);
-    rerun_if_changed_anything_in_dir(&src_dir);
+    rerun_if_changed_anything_in_dir(src_dir);
 
     let out_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or_else(||
         env::var_os("OUT_DIR").unwrap());
@@ -248,9 +246,9 @@
     );
 
     let timestamp = out_dir.join("rustbuild.timestamp");
-    if !up_to_date(Path::new("build.rs"), &timestamp) || !up_to_date(&src_dir, &timestamp) {
+    if !up_to_date(Path::new("build.rs"), &timestamp) || !up_to_date(src_dir, &timestamp) {
         Ok(NativeLibBoilerplate {
-            src_dir: src_dir,
+            src_dir: src_dir.to_path_buf(),
             out_dir: out_dir,
         })
     } else {
@@ -279,8 +277,11 @@
     } else {
         format!("static={}", link_name)
     };
+    // The source for `compiler-rt` comes from the `compiler-builtins` crate, so
+    // load our env var set by cargo to find the source code.
+    let dir = env::var_os("DEP_COMPILER_RT_COMPILER_RT").unwrap();
     let lib = native_lib_boilerplate(
-        "libcompiler_builtins/compiler-rt",
+        dir.as_ref(),
         sanitizer_name,
         &to_link,
         search_path,
diff --git a/src/dlmalloc b/src/dlmalloc
deleted file mode 160000
index de99f4b..0000000
--- a/src/dlmalloc
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit de99f4b0c886f5916cd1a146464276d65bef61b8
diff --git a/src/liballoc/Cargo.toml b/src/liballoc/Cargo.toml
index 642a43d..b7faee1 100644
--- a/src/liballoc/Cargo.toml
+++ b/src/liballoc/Cargo.toml
@@ -11,10 +11,10 @@
 
 [dependencies]
 core = { path = "../libcore" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = { version = "0.1.0", features = ['rustc-dep-of-std'] }
 
 [dev-dependencies]
-rand = "0.5"
+rand = "0.6"
 
 [[test]]
 name = "collectionstests"
diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs
index b0d8fa6..536291d 100644
--- a/src/liballoc/tests/binary_heap.rs
+++ b/src/liballoc/tests/binary_heap.rs
@@ -14,7 +14,7 @@
 use std::panic::{self, AssertUnwindSafe};
 use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
 
-use rand::{thread_rng, Rng};
+use rand::{thread_rng, seq::SliceRandom};
 
 #[test]
 fn test_iterator() {
@@ -332,7 +332,7 @@
             let panic_item = PanicOrd(i, true);
 
             // heapify the sane items
-            rng.shuffle(&mut panic_ords);
+            panic_ords.shuffle(&mut rng);
             let mut heap = BinaryHeap::from(panic_ords);
             let inner_data;
 
diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs
index 787e495..6f31e6c 100644
--- a/src/liballoc/tests/slice.rs
+++ b/src/liballoc/tests/slice.rs
@@ -18,7 +18,7 @@
 use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize};
 use std::thread;
 
-use rand::{Rng, RngCore, thread_rng};
+use rand::{Rng, RngCore, thread_rng, seq::SliceRandom};
 use rand::distributions::Standard;
 
 fn square(n: usize) -> usize {
@@ -459,7 +459,7 @@
     for i in 0..v.len() {
         v[i] = i as i32;
     }
-    v.sort_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
+    v.sort_by(|_, _| *[Less, Equal, Greater].choose(&mut rng).unwrap());
     v.sort();
     for i in 0..v.len() {
         assert_eq!(v[i], i as i32);
diff --git a/src/libcompiler_builtins b/src/libcompiler_builtins
deleted file mode 160000
index 10f4f35..0000000
--- a/src/libcompiler_builtins
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 10f4f35f9670bb29715a8c1ec01284852d47ed35
diff --git a/src/libcore/Cargo.toml b/src/libcore/Cargo.toml
index 7fd61f0..fa2ab11 100644
--- a/src/libcore/Cargo.toml
+++ b/src/libcore/Cargo.toml
@@ -20,7 +20,7 @@
 path = "../libcore/benches/lib.rs"
 
 [dev-dependencies]
-rand = "0.5"
+rand = "0.6"
 
 [features]
 # Make panics and failed asserts immediately abort without formatting any message
diff --git a/src/libcore/tests/num/flt2dec/random.rs b/src/libcore/tests/num/flt2dec/random.rs
index 95dfcb5..21a7c9f 100644
--- a/src/libcore/tests/num/flt2dec/random.rs
+++ b/src/libcore/tests/num/flt2dec/random.rs
@@ -18,7 +18,8 @@
 use core::num::flt2dec::strategy::grisu::format_shortest_opt;
 use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
 
-use rand::{FromEntropy, XorShiftRng};
+use rand::FromEntropy;
+use rand::rngs::SmallRng;
 use rand::distributions::{Distribution, Uniform};
 
 pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
@@ -71,7 +72,10 @@
 pub fn f32_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
         where F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
               G: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
-    let mut rng = XorShiftRng::from_entropy();
+    if cfg!(target_os = "emscripten") {
+        return // using rng pulls in i128 support, which doesn't work
+    }
+    let mut rng = SmallRng::from_entropy();
     let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
     iterate("f32_random_equivalence_test", k, n, f, g, |_| {
         let x = f32::from_bits(f32_range.sample(&mut rng));
@@ -82,7 +86,10 @@
 pub fn f64_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
         where F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
               G: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
-    let mut rng = XorShiftRng::from_entropy();
+    if cfg!(target_os = "emscripten") {
+        return // using rng pulls in i128 support, which doesn't work
+    }
+    let mut rng = SmallRng::from_entropy();
     let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
     iterate("f64_random_equivalence_test", k, n, f, g, |_| {
         let x = f64::from_bits(f64_range.sample(&mut rng));
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index dba5a43..4f00ebe 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -1024,11 +1024,11 @@
 fn sort_unstable() {
     use core::cmp::Ordering::{Equal, Greater, Less};
     use core::slice::heapsort;
-    use rand::{FromEntropy, Rng, XorShiftRng};
+    use rand::{FromEntropy, Rng, rngs::SmallRng, seq::SliceRandom};
 
     let mut v = [0; 600];
     let mut tmp = [0; 600];
-    let mut rng = XorShiftRng::from_entropy();
+    let mut rng = SmallRng::from_entropy();
 
     for len in (2..25).chain(500..510) {
         let v = &mut v[0..len];
@@ -1073,7 +1073,7 @@
     for i in 0..v.len() {
         v[i] = i as i32;
     }
-    v.sort_unstable_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
+    v.sort_unstable_by(|_, _| *[Less, Equal, Greater].choose(&mut rng).unwrap());
     v.sort_unstable();
     for i in 0..v.len() {
         assert_eq!(v[i], i as i32);
diff --git a/src/liblibc b/src/liblibc
deleted file mode 160000
index 5b40375..0000000
--- a/src/liblibc
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 5b403753da9ec8ff501adf34cb6d63b319b4a3ae
diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml
index 633d273..e304e61 100644
--- a/src/libpanic_abort/Cargo.toml
+++ b/src/libpanic_abort/Cargo.toml
@@ -11,5 +11,5 @@
 
 [dependencies]
 core = { path = "../libcore" }
-libc = { path = "../rustc/libc_shim" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+libc = { version = "0.2", default-features = false }
+compiler_builtins = "0.1.0"
diff --git a/src/libpanic_unwind/Cargo.toml b/src/libpanic_unwind/Cargo.toml
index 74aaa4d..c9fce62 100644
--- a/src/libpanic_unwind/Cargo.toml
+++ b/src/libpanic_unwind/Cargo.toml
@@ -12,6 +12,6 @@
 [dependencies]
 alloc = { path = "../liballoc" }
 core = { path = "../libcore" }
-libc = { path = "../rustc/libc_shim" }
+libc = { version = "0.2", default-features = false }
 unwind = { path = "../libunwind" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = "0.1.0"
diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml
index 79192fb..7c95cf0 100644
--- a/src/libprofiler_builtins/Cargo.toml
+++ b/src/libprofiler_builtins/Cargo.toml
@@ -13,7 +13,7 @@
 
 [dependencies]
 core = { path = "../libcore" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = { version = "0.1.0", features = ['rustc-dep-of-std'] }
 
 [build-dependencies]
 cc = "1.0.1"
diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs
index 8d6c7d6..db72ce7 100644
--- a/src/libprofiler_builtins/build.rs
+++ b/src/libprofiler_builtins/build.rs
@@ -56,9 +56,15 @@
         cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
     }
 
+    // The source for `compiler-rt` comes from the `compiler-builtins` crate, so
+    // load our env var set by cargo to find the source code.
+    let root = env::var_os("DEP_COMPILER_RT_COMPILER_RT").unwrap();
+    let root = Path::new(&root);
+
     for src in profile_sources {
-        cfg.file(Path::new("../libcompiler_builtins/compiler-rt/lib/profile").join(src));
+        cfg.file(root.join("lib").join("profile").join(src));
     }
 
+    cfg.warnings(false);
     cfg.compile("profiler-rt");
 }
diff --git a/src/librustc_asan/Cargo.toml b/src/librustc_asan/Cargo.toml
index 734564c..836caf2 100644
--- a/src/librustc_asan/Cargo.toml
+++ b/src/librustc_asan/Cargo.toml
@@ -16,4 +16,4 @@
 [dependencies]
 alloc = { path = "../liballoc" }
 core = { path = "../libcore" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = "0.1.0"
diff --git a/src/librustc_lsan/Cargo.toml b/src/librustc_lsan/Cargo.toml
index 2573825..a8e11df 100644
--- a/src/librustc_lsan/Cargo.toml
+++ b/src/librustc_lsan/Cargo.toml
@@ -16,4 +16,4 @@
 [dependencies]
 alloc = { path = "../liballoc" }
 core = { path = "../libcore" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = "0.1.0"
diff --git a/src/librustc_msan/Cargo.toml b/src/librustc_msan/Cargo.toml
index 2916567..78c39d0 100644
--- a/src/librustc_msan/Cargo.toml
+++ b/src/librustc_msan/Cargo.toml
@@ -16,4 +16,4 @@
 [dependencies]
 alloc = { path = "../liballoc" }
 core = { path = "../libcore" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = "0.1.0"
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index 2681295..7730239 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -295,9 +295,8 @@
 Erroneous code example:
 
 ```compile_fail,E0259
-# #![feature(libc)]
 extern crate core;
-extern crate libc as core;
+extern crate std as core;
 
 fn main() {}
 ```
@@ -308,9 +307,8 @@
 Correct example:
 
 ```
-# #![feature(libc)]
 extern crate core;
-extern crate libc as other_name;
+extern crate std as other_name;
 
 fn main() {}
 ```
diff --git a/src/librustc_tsan/Cargo.toml b/src/librustc_tsan/Cargo.toml
index baadb64..f061827 100644
--- a/src/librustc_tsan/Cargo.toml
+++ b/src/librustc_tsan/Cargo.toml
@@ -16,4 +16,4 @@
 [dependencies]
 alloc = { path = "../liballoc" }
 core = { path = "../libcore" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+compiler_builtins = "0.1.0"
diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml
index 274d5be..41e778b 100644
--- a/src/libstd/Cargo.toml
+++ b/src/libstd/Cargo.toml
@@ -17,13 +17,13 @@
 panic_unwind = { path = "../libpanic_unwind", optional = true }
 panic_abort = { path = "../libpanic_abort" }
 core = { path = "../libcore" }
-libc = { path = "../rustc/libc_shim" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+libc = { version = "0.2.44", default-features = false, features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "0.1.1" }
 profiler_builtins = { path = "../libprofiler_builtins", optional = true }
 unwind = { path = "../libunwind" }
 
 [dev-dependencies]
-rand = "0.5"
+rand = "0.6.1"
 
 [target.x86_64-apple-darwin.dependencies]
 rustc_asan = { path = "../librustc_asan" }
@@ -36,10 +36,10 @@
 rustc_tsan = { path = "../librustc_tsan" }
 
 [target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), target_env = "sgx"))'.dependencies]
-dlmalloc = { path = '../rustc/dlmalloc_shim' }
+dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] }
 
 [target.x86_64-fortanix-unknown-sgx.dependencies]
-fortanix-sgx-abi = { path = "../rustc/fortanix-sgx-abi_shim" }
+fortanix-sgx-abi = { version = "0.3.1", features = ['rustc-dep-of-std'] }
 
 [build-dependencies]
 cc = "1.0"
diff --git a/src/libstd/build.rs b/src/libstd/build.rs
index 9d6e8c4..2386f13 100644
--- a/src/libstd/build.rs
+++ b/src/libstd/build.rs
@@ -82,7 +82,12 @@
 }
 
 fn build_libbacktrace(target: &str) -> Result<(), ()> {
-    let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", "")?;
+    let native = native_lib_boilerplate(
+        "../libbacktrace".as_ref(),
+        "libbacktrace",
+        "backtrace",
+        "",
+    )?;
 
     let mut build = cc::Build::new();
     build
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index b6a0ce6..d581ba1 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -2089,7 +2089,7 @@
     use fs::{self, File, OpenOptions};
     use io::{ErrorKind, SeekFrom};
     use path::Path;
-    use rand::{StdRng, FromEntropy, RngCore};
+    use rand::{rngs::StdRng, FromEntropy, RngCore};
     use str;
     use sys_common::io::test::{TempDir, tmpdir};
     use thread;
diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs
index 3b2366a..7c1654f 100644
--- a/src/libstd/primitive_docs.rs
+++ b/src/libstd/primitive_docs.rs
@@ -426,7 +426,7 @@
 /// ## 3. Get it from C.
 ///
 /// ```
-/// # #![feature(libc)]
+/// # #![feature(rustc_private)]
 /// extern crate libc;
 ///
 /// use std::mem;
diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs
index 7e65bbd..af2f199 100644
--- a/src/libstd/sys/unix/ext/fs.rs
+++ b/src/libstd/sys/unix/ext/fs.rs
@@ -348,7 +348,7 @@
     /// # Examples
     ///
     /// ```no_run
-    /// # #![feature(libc)]
+    /// # #![feature(rustc_private)]
     /// extern crate libc;
     /// use std::fs::OpenOptions;
     /// use std::os::unix::fs::OpenOptionsExt;
diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml
index 4760461..2577d6d 100644
--- a/src/libunwind/Cargo.toml
+++ b/src/libunwind/Cargo.toml
@@ -13,5 +13,5 @@
 
 [dependencies]
 core = { path = "../libcore" }
-libc = { path = "../rustc/libc_shim" }
-compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
+libc = { version = "0.2.43", features = ['rustc-dep-of-std'], default-features = false }
+compiler_builtins = "0.1.0"
diff --git a/src/rust-sgx b/src/rust-sgx
deleted file mode 160000
index 9656260..0000000
--- a/src/rust-sgx
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 9656260888095f44830641ca7bb3da609a793451
diff --git a/src/rustc/compiler_builtins_shim/Cargo.toml b/src/rustc/compiler_builtins_shim/Cargo.toml
deleted file mode 100644
index 9804177..0000000
--- a/src/rustc/compiler_builtins_shim/Cargo.toml
+++ /dev/null
@@ -1,40 +0,0 @@
-[package]
-name = "compiler_builtins"
-authors = ["The Rust Project Developers"]
-version = "0.0.0"
-build = "../../libcompiler_builtins/build.rs"
-
-[lib]
-path = "../../libcompiler_builtins/src/lib.rs"
-test = false
-doctest = false
-
-[dependencies]
-# Specify the path to libcore; at the time of writing, removing this shim in
-# favor of using compiler-builtins from git results in a compilation failure:
-#
-# Building stage0 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
-#    Compiling compiler_builtins v0.1.0 (https://github.com/rust-lang-nursery/compiler-builtins.git#23f14d3f)
-# error[E0463]: can't find crate for `core`
-#
-# error: aborting due to previous error
-#
-# error: Could not compile `compiler_builtins`.
-#
-# Caused by:
-#   process didn't exit successfully: `/Users/tamird/src/rust/build/bootstrap/debug/rustc --crate-name compiler_builtins /Users/tamird/.cargo/git/checkouts/compiler-builtins-ec094dc45a0179c8/23f14d3/src/lib.rs --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 --cfg feature="c" --cfg feature="compiler-builtins" --cfg feature="default" --cfg feature="gcc" -C metadata=876d429e8d7eae1f -C extra-filename=-876d429e8d7eae1f --out-dir /Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps --target x86_64-apple-darwin -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/release/deps --cap-lints allow -L native=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/build/compiler_builtins-f18fab55928102ad/out -l static=compiler-rt` (exit code: 101)
-# thread 'main' panicked at 'command did not execute successfully: "/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0/bin/cargo" "build" "-j" "4" "--target" "x86_64-apple-darwin" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/Users/tamird/src/rust/src/libstd/Cargo.toml" "--message-format" "json"
-# expected success, got: exit code: 101', src/bootstrap/compile.rs:883:8
-#
-# See https://github.com/rust-lang/rfcs/pull/1133.
-core = { path = "../../libcore" }
-
-[build-dependencies]
-cc = "1.0.1"
-
-[features]
-c = []
-default = ["rustbuild", "compiler-builtins"]
-mem = []
-rustbuild = []
-compiler-builtins = []
diff --git a/src/rustc/compiler_builtins_shim/build.rs b/src/rustc/compiler_builtins_shim/build.rs
deleted file mode 100644
index b37543e..0000000
--- a/src/rustc/compiler_builtins_shim/build.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// This file is left intentionally empty (and not removed) to avoid an issue
-// where this crate is always considered dirty due to compiler-builtins'
-// `cargo:rerun-if-changed=build.rs` directive; since the path is relative, it
-// refers to this file when this shim crate is being built, and the absence of
-// this file is considered by cargo to be equivalent to it having changed.
diff --git a/src/rustc/dlmalloc_shim/Cargo.toml b/src/rustc/dlmalloc_shim/Cargo.toml
deleted file mode 100644
index b6f8550..0000000
--- a/src/rustc/dlmalloc_shim/Cargo.toml
+++ /dev/null
@@ -1,14 +0,0 @@
-[package]
-name = "dlmalloc"
-version = "0.0.0"
-authors = ["The Rust Project Developers"]
-
-[lib]
-path = "../../dlmalloc/src/lib.rs"
-test = false
-bench = false
-doc = false
-
-[dependencies]
-core = { path = "../../libcore" }
-compiler_builtins = { path = "../../rustc/compiler_builtins_shim" }
diff --git a/src/rustc/fortanix-sgx-abi_shim/Cargo.toml b/src/rustc/fortanix-sgx-abi_shim/Cargo.toml
deleted file mode 100644
index fd81d3d..0000000
--- a/src/rustc/fortanix-sgx-abi_shim/Cargo.toml
+++ /dev/null
@@ -1,14 +0,0 @@
-[package]
-name = "fortanix-sgx-abi"
-version = "0.0.0"
-authors = ["The Rust Project Developers"]
-
-[lib]
-path = "../../rust-sgx/fortanix-sgx-abi/src/lib.rs"
-test = false
-bench = false
-doc = false
-
-[dependencies]
-core = { path = "../../libcore" }
-compiler_builtins = { path = "../../rustc/compiler_builtins_shim" }
diff --git a/src/rustc/libc_shim/Cargo.toml b/src/rustc/libc_shim/Cargo.toml
deleted file mode 100644
index ee037ac..0000000
--- a/src/rustc/libc_shim/Cargo.toml
+++ /dev/null
@@ -1,40 +0,0 @@
-[package]
-name = "libc"
-version = "0.0.0"
-authors = ["The Rust Project Developers"]
-
-[lib]
-name = "libc"
-path = "../../liblibc/src/lib.rs"
-test = false
-bench = false
-doc = false
-
-[dependencies]
-# Specify the path to libcore; at the time of writing, removing this shim in
-# favor of using libc from git results in a compilation failure:
-#
-# Building stage0 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
-#    Compiling libc v0.0.0 (file:///Users/tamird/src/rust/src/rustc/libc_shim)
-# error[E0463]: can't find crate for `core`
-#
-# error: aborting due to previous error
-#
-# error: Could not compile `libc`.
-#
-# Caused by:
-#   process didn't exit successfully: `/Users/tamird/src/rust/build/bootstrap/debug/rustc --crate-name libc src/rustc/libc_shim/../../liblibc/src/lib.rs --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 --cfg feature="default" --cfg feature="no_std" --cfg feature="stdbuild" -C metadata=d758f87058112d7d -C extra-filename=-d758f87058112d7d --out-dir /Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps --target x86_64-apple-darwin -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/release/deps` (exit code: 101)
-# thread 'main' panicked at 'command did not execute successfully: "/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0/bin/cargo" "build" "-j" "4" "--target" "x86_64-apple-darwin" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/Users/tamird/src/rust/src/libstd/Cargo.toml" "--message-format" "json"
-# expected success, got: exit code: 101', src/bootstrap/compile.rs:883:8
-#
-# See https://github.com/rust-lang/rfcs/pull/1133.
-core = { path = "../../libcore" }
-compiler_builtins = { path = "../compiler_builtins_shim" }
-
-
-[features]
-# Certain parts of libc are conditionally compiled differently than when used
-# outside rustc. See https://github.com/rust-lang/libc/search?l=Rust&q=stdbuild&type=&utf8=%E2%9C%93.
-stdbuild = []
-default = ["stdbuild", "align"]
-align = []
diff --git a/src/stage0.txt b/src/stage0.txt
index 9326e22..8369413 100644
--- a/src/stage0.txt
+++ b/src/stage0.txt
@@ -12,7 +12,7 @@
 # source tarball for a stable release you'll likely see `1.x.0` for rustc and
 # `0.x.0` for Cargo where they were released on `date`.
 
-date: 2018-10-30
+date: 2018-11-21
 rustc: beta
 cargo: beta
 
diff --git a/src/test/incremental/foreign.rs b/src/test/incremental/foreign.rs
index dbdebef..648e89b 100644
--- a/src/test/incremental/foreign.rs
+++ b/src/test/incremental/foreign.rs
@@ -13,7 +13,7 @@
 
 // revisions: rpass1
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs
index 90ad601..0254c7c 100644
--- a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs
+++ b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs
@@ -10,7 +10,7 @@
 
 #![crate_type = "staticlib"]
 #![feature(c_variadic)]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-make-fulldeps/issue-25581/test.rs b/src/test/run-make-fulldeps/issue-25581/test.rs
index 6717d16..b084092 100644
--- a/src/test/run-make-fulldeps/issue-25581/test.rs
+++ b/src/test/run-make-fulldeps/issue-25581/test.rs
@@ -8,14 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(libc)]
-
-extern crate libc;
-
 #[link(name = "test", kind = "static")]
 extern {
-    fn slice_len(s: &[u8]) -> libc::size_t;
-    fn slice_elem(s: &[u8], idx: libc::size_t) -> u8;
+    fn slice_len(s: &[u8]) -> usize;
+    fn slice_elem(s: &[u8], idx: usize) -> u8;
 }
 
 fn main() {
diff --git a/src/test/run-make-fulldeps/issue-26006/in/time/lib.rs b/src/test/run-make-fulldeps/issue-26006/in/time/lib.rs
index b1d07d5..1427250 100644
--- a/src/test/run-make-fulldeps/issue-26006/in/time/lib.rs
+++ b/src/test/run-make-fulldeps/issue-26006/in/time/lib.rs
@@ -7,7 +7,7 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
-#![feature(libc)]
+#![feature(rustc_private)]
 extern crate libc;
 
 fn main(){}
diff --git a/src/test/run-make-fulldeps/link-path-order/main.rs b/src/test/run-make-fulldeps/link-path-order/main.rs
index f3502e8..4d38dc8 100644
--- a/src/test/run-make-fulldeps/link-path-order/main.rs
+++ b/src/test/run-make-fulldeps/link-path-order/main.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass-valgrind/osx-frameworks.rs b/src/test/run-pass-valgrind/osx-frameworks.rs
index 468a20d..afa9374 100644
--- a/src/test/run-pass-valgrind/osx-frameworks.rs
+++ b/src/test/run-pass-valgrind/osx-frameworks.rs
@@ -11,7 +11,7 @@
 // no-prefer-dynamic
 // pretty-expanded FIXME #23616
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/anon-extern-mod.rs b/src/test/run-pass/anon-extern-mod.rs
index 16ca7bc..daa2bd6 100644
--- a/src/test/run-pass/anon-extern-mod.rs
+++ b/src/test/run-pass/anon-extern-mod.rs
@@ -11,7 +11,7 @@
 // pretty-expanded FIXME #23616
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/array-slice-vec/vec-macro-no-std.rs b/src/test/run-pass/array-slice-vec/vec-macro-no-std.rs
index 5091674..7a90a02 100644
--- a/src/test/run-pass/array-slice-vec/vec-macro-no-std.rs
+++ b/src/test/run-pass/array-slice-vec/vec-macro-no-std.rs
@@ -12,7 +12,7 @@
 
 // ignore-emscripten no no_std executables
 
-#![feature(lang_items, start, libc, alloc)]
+#![feature(lang_items, start, rustc_private, alloc)]
 #![no_std]
 
 extern crate std as other;
diff --git a/src/test/run-pass/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/auxiliary/anon-extern-mod-cross-crate-1.rs
index 741ce35..6b464c5 100644
--- a/src/test/run-pass/auxiliary/anon-extern-mod-cross-crate-1.rs
+++ b/src/test/run-pass/auxiliary/anon-extern-mod-cross-crate-1.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #![crate_name="anonexternmod"]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/auxiliary/check_static_recursion_foreign_helper.rs b/src/test/run-pass/auxiliary/check_static_recursion_foreign_helper.rs
index cd36a8e..4d1acf3 100644
--- a/src/test/run-pass/auxiliary/check_static_recursion_foreign_helper.rs
+++ b/src/test/run-pass/auxiliary/check_static_recursion_foreign_helper.rs
@@ -10,7 +10,7 @@
 
 // Helper definition for test/run-pass/check-static-recursion-foreign.rs.
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 #![crate_name = "check_static_recursion_foreign_helper"]
 #![crate_type = "lib"]
diff --git a/src/test/run-pass/auxiliary/foreign_lib.rs b/src/test/run-pass/auxiliary/foreign_lib.rs
index cef3627..465feb8 100644
--- a/src/test/run-pass/auxiliary/foreign_lib.rs
+++ b/src/test/run-pass/auxiliary/foreign_lib.rs
@@ -10,7 +10,7 @@
 
 #![crate_name="foreign_lib"]
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 pub mod rustrt {
     extern crate libc;
diff --git a/src/test/run-pass/c-stack-as-value.rs b/src/test/run-pass/c-stack-as-value.rs
index df4989d..1f29a52 100644
--- a/src/test/run-pass/c-stack-as-value.rs
+++ b/src/test/run-pass/c-stack-as-value.rs
@@ -11,7 +11,7 @@
 // pretty-expanded FIXME #23616
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 mod rustrt {
     extern crate libc;
diff --git a/src/test/run-pass/c-stack-returning-int64.rs b/src/test/run-pass/c-stack-returning-int64.rs
index 56a0437..7dd3b9a 100644
--- a/src/test/run-pass/c-stack-returning-int64.rs
+++ b/src/test/run-pass/c-stack-returning-int64.rs
@@ -10,7 +10,7 @@
 
 // ignore-wasm32-bare no libc to test with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/check-static-recursion-foreign.rs b/src/test/run-pass/check-static-recursion-foreign.rs
index a95870c..15f509a 100644
--- a/src/test/run-pass/check-static-recursion-foreign.rs
+++ b/src/test/run-pass/check-static-recursion-foreign.rs
@@ -16,7 +16,7 @@
 
 // pretty-expanded FIXME #23616
 
-#![feature(custom_attribute, libc)]
+#![feature(custom_attribute, rustc_private)]
 
 extern crate check_static_recursion_foreign_helper;
 extern crate libc;
diff --git a/src/test/run-pass/command-before-exec.rs b/src/test/run-pass/command-before-exec.rs
index 5d8bc31..b78fa84 100644
--- a/src/test/run-pass/command-before-exec.rs
+++ b/src/test/run-pass/command-before-exec.rs
@@ -13,7 +13,7 @@
 // ignore-cloudabi no processes
 // ignore-emscripten no processes
 
-#![feature(process_exec, libc)]
+#![feature(process_exec, rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/consts/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/consts/auxiliary/anon-extern-mod-cross-crate-1.rs
index 741ce35..6b464c5 100644
--- a/src/test/run-pass/consts/auxiliary/anon-extern-mod-cross-crate-1.rs
+++ b/src/test/run-pass/consts/auxiliary/anon-extern-mod-cross-crate-1.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #![crate_name="anonexternmod"]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/core-run-destroy.rs b/src/test/run-pass/core-run-destroy.rs
index 51e26ff..9023326 100644
--- a/src/test/run-pass/core-run-destroy.rs
+++ b/src/test/run-pass/core-run-destroy.rs
@@ -20,7 +20,7 @@
 // memory, which makes for some *confusing* logs. That's why these are here
 // instead of in std.
 
-#![feature(libc, duration)]
+#![feature(rustc_private, duration)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/run-pass/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs
index 741ce35..6b464c5 100644
--- a/src/test/run-pass/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs
+++ b/src/test/run-pass/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #![crate_name="anonexternmod"]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/env-funky-keys.rs b/src/test/run-pass/env-funky-keys.rs
index 12e1cbe..7e7899c 100644
--- a/src/test/run-pass/env-funky-keys.rs
+++ b/src/test/run-pass/env-funky-keys.rs
@@ -16,7 +16,7 @@
 // ignore-emscripten no execve
 // no-prefer-dynamic
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/env-null-vars.rs b/src/test/run-pass/env-null-vars.rs
index 9a46199..cdbecf1 100644
--- a/src/test/run-pass/env-null-vars.rs
+++ b/src/test/run-pass/env-null-vars.rs
@@ -15,7 +15,7 @@
 
 // issue-53200
 
-#![feature(libc)]
+#![feature(rustc_private)]
 extern crate libc;
 
 use std::env;
diff --git a/src/test/run-pass/extern/auxiliary/extern-crosscrate-source.rs b/src/test/run-pass/extern/auxiliary/extern-crosscrate-source.rs
index 150dffe..d20d9db 100644
--- a/src/test/run-pass/extern/auxiliary/extern-crosscrate-source.rs
+++ b/src/test/run-pass/extern/auxiliary/extern-crosscrate-source.rs
@@ -10,7 +10,7 @@
 
 #![crate_name="externcallback"]
 #![crate_type = "lib"]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/extern/extern-call-deep.rs b/src/test/run-pass/extern/extern-call-deep.rs
index 6e8d94b..f6eff60 100644
--- a/src/test/run-pass/extern/extern-call-deep.rs
+++ b/src/test/run-pass/extern/extern-call-deep.rs
@@ -11,7 +11,7 @@
 // run-pass
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/extern/extern-call-deep2.rs b/src/test/run-pass/extern/extern-call-deep2.rs
index 28157c5..8cb0477 100644
--- a/src/test/run-pass/extern/extern-call-deep2.rs
+++ b/src/test/run-pass/extern/extern-call-deep2.rs
@@ -12,7 +12,7 @@
 #![allow(unused_must_use)]
 // ignore-emscripten no threads support
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 use std::thread;
diff --git a/src/test/run-pass/extern/extern-call-indirect.rs b/src/test/run-pass/extern/extern-call-indirect.rs
index 1badb10..d20721f 100644
--- a/src/test/run-pass/extern/extern-call-indirect.rs
+++ b/src/test/run-pass/extern/extern-call-indirect.rs
@@ -11,7 +11,7 @@
 // run-pass
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/extern/extern-call-scrub.rs b/src/test/run-pass/extern/extern-call-scrub.rs
index ea18069..5e158c2 100644
--- a/src/test/run-pass/extern/extern-call-scrub.rs
+++ b/src/test/run-pass/extern/extern-call-scrub.rs
@@ -16,7 +16,7 @@
 
 // ignore-emscripten no threads support
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 use std::thread;
diff --git a/src/test/run-pass/extern/extern-crosscrate.rs b/src/test/run-pass/extern/extern-crosscrate.rs
index c6fccbe..b99e27a 100644
--- a/src/test/run-pass/extern/extern-crosscrate.rs
+++ b/src/test/run-pass/extern/extern-crosscrate.rs
@@ -12,7 +12,7 @@
 // aux-build:extern-crosscrate-source.rs
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate externcallback;
 extern crate libc;
diff --git a/src/test/run-pass/fds-are-cloexec.rs b/src/test/run-pass/fds-are-cloexec.rs
index a5ae0ae..33e64d8 100644
--- a/src/test/run-pass/fds-are-cloexec.rs
+++ b/src/test/run-pass/fds-are-cloexec.rs
@@ -14,7 +14,7 @@
 // ignore-emscripten no processes
 // ignore-haiku
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/foreign/auxiliary/foreign_lib.rs b/src/test/run-pass/foreign/auxiliary/foreign_lib.rs
index cef3627..465feb8 100644
--- a/src/test/run-pass/foreign/auxiliary/foreign_lib.rs
+++ b/src/test/run-pass/foreign/auxiliary/foreign_lib.rs
@@ -10,7 +10,7 @@
 
 #![crate_name="foreign_lib"]
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 pub mod rustrt {
     extern crate libc;
diff --git a/src/test/run-pass/foreign/foreign-call-no-runtime.rs b/src/test/run-pass/foreign/foreign-call-no-runtime.rs
index 4837f78..e35ec88 100644
--- a/src/test/run-pass/foreign/foreign-call-no-runtime.rs
+++ b/src/test/run-pass/foreign/foreign-call-no-runtime.rs
@@ -11,7 +11,7 @@
 // run-pass
 // ignore-emscripten no threads support
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/foreign/foreign-fn-linkname.rs b/src/test/run-pass/foreign/foreign-fn-linkname.rs
index 7587660..8fe90b7 100644
--- a/src/test/run-pass/foreign/foreign-fn-linkname.rs
+++ b/src/test/run-pass/foreign/foreign-fn-linkname.rs
@@ -11,7 +11,7 @@
 // run-pass
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 use std::ffi::CString;
diff --git a/src/test/run-pass/foreign/foreign-no-abi.rs b/src/test/run-pass/foreign/foreign-no-abi.rs
index 1d35f08..49ddd09 100644
--- a/src/test/run-pass/foreign/foreign-no-abi.rs
+++ b/src/test/run-pass/foreign/foreign-no-abi.rs
@@ -14,7 +14,7 @@
 // ignore-wasm32-bare no libc to test ffi with
 // pretty-expanded FIXME #23616
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 mod rustrt {
     extern crate libc;
diff --git a/src/test/run-pass/foreign/foreign2.rs b/src/test/run-pass/foreign/foreign2.rs
index bd6c8e6..f8942bc 100644
--- a/src/test/run-pass/foreign/foreign2.rs
+++ b/src/test/run-pass/foreign/foreign2.rs
@@ -13,7 +13,7 @@
 // ignore-wasm32-bare no libc to test ffi with
 // pretty-expanded FIXME #23616
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/invalid_const_promotion.rs b/src/test/run-pass/invalid_const_promotion.rs
index 0f354e1..3b8a265 100644
--- a/src/test/run-pass/invalid_const_promotion.rs
+++ b/src/test/run-pass/invalid_const_promotion.rs
@@ -15,7 +15,7 @@
 // compile-flags: -C debug_assertions=yes
 
 #![stable(feature = "rustc", since = "1.0.0")]
-#![feature(const_fn, libc, staged_api, rustc_attrs)]
+#![feature(const_fn, rustc_private, staged_api, rustc_attrs)]
 #![allow(const_err)]
 
 extern crate libc;
diff --git a/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs b/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs
index de18e09..9c983ea 100644
--- a/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs
+++ b/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // run-pass
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/issues/issue-2214.rs b/src/test/run-pass/issues/issue-2214.rs
index 8329847..f3795c2 100644
--- a/src/test/run-pass/issues/issue-2214.rs
+++ b/src/test/run-pass/issues/issue-2214.rs
@@ -11,7 +11,7 @@
 // run-pass
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/issues/issue-30490.rs b/src/test/run-pass/issues/issue-30490.rs
index 500999c..47f60fb 100644
--- a/src/test/run-pass/issues/issue-30490.rs
+++ b/src/test/run-pass/issues/issue-30490.rs
@@ -18,7 +18,7 @@
 // where the descriptors to inherit were already stdio descriptors.
 // This test checks to avoid that regression.
 
-#![cfg_attr(unix, feature(libc))]
+#![cfg_attr(unix, feature(rustc_private))]
 #![cfg_attr(windows, allow(unused_imports))]
 
 #[cfg(unix)]
diff --git a/src/test/run-pass/issues/issue-3656.rs b/src/test/run-pass/issues/issue-3656.rs
index 63b2740..99a7244 100644
--- a/src/test/run-pass/issues/issue-3656.rs
+++ b/src/test/run-pass/issues/issue-3656.rs
@@ -19,7 +19,7 @@
 // pretty-expanded FIXME #23616
 // ignore-wasm32-bare no libc to test with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 use libc::{c_uint, uint32_t, c_void};
diff --git a/src/test/run-pass/no-stdio.rs b/src/test/run-pass/no-stdio.rs
index d342417..2f5bfbb 100644
--- a/src/test/run-pass/no-stdio.rs
+++ b/src/test/run-pass/no-stdio.rs
@@ -12,7 +12,7 @@
 // ignore-cloudabi no processes
 // ignore-emscripten no processes
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/out-of-stack.rs b/src/test/run-pass/out-of-stack.rs
index cd0f7cd..1c714e7 100644
--- a/src/test/run-pass/out-of-stack.rs
+++ b/src/test/run-pass/out-of-stack.rs
@@ -16,7 +16,7 @@
 // ignore-emscripten no processes
 
 #![feature(asm)]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 #[cfg(unix)]
 extern crate libc;
diff --git a/src/test/run-pass/rfcs/rfc-1014-2.rs b/src/test/run-pass/rfcs/rfc-1014-2.rs
index 7fbc0d1..257c7f5 100644
--- a/src/test/run-pass/rfcs/rfc-1014-2.rs
+++ b/src/test/run-pass/rfcs/rfc-1014-2.rs
@@ -11,7 +11,7 @@
 // run-pass
 #![allow(dead_code)]
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/rfcs/rfc-1014.rs b/src/test/run-pass/rfcs/rfc-1014.rs
index d101c3c..578a7f4 100644
--- a/src/test/run-pass/rfcs/rfc-1014.rs
+++ b/src/test/run-pass/rfcs/rfc-1014.rs
@@ -13,7 +13,7 @@
 // ignore-cloudabi stdout does not map to file descriptor 1 by default
 // ignore-wasm32-bare no libc
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/segfault-no-out-of-stack.rs b/src/test/run-pass/segfault-no-out-of-stack.rs
index a85fe67..961b802 100644
--- a/src/test/run-pass/segfault-no-out-of-stack.rs
+++ b/src/test/run-pass/segfault-no-out-of-stack.rs
@@ -12,7 +12,7 @@
 // ignore-cloudabi can't run commands
 // ignore-emscripten can't run commands
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/signal-alternate-stack-cleanup.rs b/src/test/run-pass/signal-alternate-stack-cleanup.rs
index ad099f8..a79ab20 100644
--- a/src/test/run-pass/signal-alternate-stack-cleanup.rs
+++ b/src/test/run-pass/signal-alternate-stack-cleanup.rs
@@ -16,7 +16,7 @@
 // ignore-wasm32-bare no libc
 // ignore-windows
 
-#![feature(libc)]
+#![feature(rustc_private)]
 extern crate libc;
 
 use libc::*;
diff --git a/src/test/run-pass/statics/static-mut-foreign.rs b/src/test/run-pass/statics/static-mut-foreign.rs
index d9e43dd..460d66a 100644
--- a/src/test/run-pass/statics/static-mut-foreign.rs
+++ b/src/test/run-pass/statics/static-mut-foreign.rs
@@ -15,7 +15,7 @@
 
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/run-pass/wait-forked-but-failed-child.rs b/src/test/run-pass/wait-forked-but-failed-child.rs
index dc47108..d822b67 100644
--- a/src/test/run-pass/wait-forked-but-failed-child.rs
+++ b/src/test/run-pass/wait-forked-but-failed-child.rs
@@ -11,7 +11,7 @@
 // ignore-cloudabi no processes
 // ignore-emscripten no processes
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/ui/error-codes/E0259.rs b/src/test/ui/error-codes/E0259.rs
index 5a47541..b3e633a 100644
--- a/src/test/ui/error-codes/E0259.rs
+++ b/src/test/ui/error-codes/E0259.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(alloc, libc)]
+#![feature(alloc, rustc_private)]
 #![allow(unused_extern_crates)]
 
 extern crate alloc;
diff --git a/src/test/ui/extern/extern-const.fixed b/src/test/ui/extern/extern-const.fixed
index dca5698..fb17934 100644
--- a/src/test/ui/extern/extern-const.fixed
+++ b/src/test/ui/extern/extern-const.fixed
@@ -7,7 +7,7 @@
 // run-rustfix
 // ignore-wasm32 no external library to link to.
 // compile-flags: -g -Z continue-parse-after-error
-#![feature(libc)]
+#![feature(rustc_private)]
 extern crate libc;
 
 #[link(name = "rust_test_helpers", kind = "static")]
diff --git a/src/test/ui/extern/extern-const.rs b/src/test/ui/extern/extern-const.rs
index 07dbe54..f2585f5 100644
--- a/src/test/ui/extern/extern-const.rs
+++ b/src/test/ui/extern/extern-const.rs
@@ -7,7 +7,7 @@
 // run-rustfix
 // ignore-wasm32 no external library to link to.
 // compile-flags: -g -Z continue-parse-after-error
-#![feature(libc)]
+#![feature(rustc_private)]
 extern crate libc;
 
 #[link(name = "rust_test_helpers", kind = "static")]
diff --git a/src/test/ui/issues/issue-1251.rs b/src/test/ui/issues/issue-1251.rs
index b42404c..125f6e1 100644
--- a/src/test/ui/issues/issue-1251.rs
+++ b/src/test/ui/issues/issue-1251.rs
@@ -14,7 +14,7 @@
 // pretty-expanded FIXME #23616
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 #![crate_id="rust_get_test_int"]
 
diff --git a/src/test/ui/issues/issue-22034.rs b/src/test/ui/issues/issue-22034.rs
index 2708de2..bee324f 100644
--- a/src/test/ui/issues/issue-22034.rs
+++ b/src/test/ui/issues/issue-22034.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/ui/issues/issue-37887.stderr b/src/test/ui/issues/issue-37887.stderr
index 48fb6c2..7a5a5cd 100644
--- a/src/test/ui/issues/issue-37887.stderr
+++ b/src/test/ui/issues/issue-37887.stderr
@@ -4,13 +4,13 @@
 LL |     use libc::*; //~ ERROR unresolved import
    |         ^^^^ maybe a missing `extern crate libc;`?
 
-error[E0658]: use of unstable library feature 'libc': use `libc` from crates.io (see issue #27783)
+error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
   --> $DIR/issue-37887.rs:12:5
    |
 LL |     extern crate libc; //~ ERROR use of unstable
    |     ^^^^^^^^^^^^^^^^^^
    |
-   = help: add #![feature(libc)] to the crate attributes to enable
+   = help: add #![feature(rustc_private)] to the crate attributes to enable
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/lint/lint-ctypes.rs b/src/test/ui/lint/lint-ctypes.rs
index e09aaba..4c9f1f9 100644
--- a/src/test/ui/lint/lint-ctypes.rs
+++ b/src/test/ui/lint/lint-ctypes.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #![deny(improper_ctypes)]
-#![feature(libc)]
+#![feature(rustc_private)]
 
 #![allow(private_in_public)]
 
diff --git a/src/test/ui/non-copyable-void.rs b/src/test/ui/non-copyable-void.rs
index 63e5f96..3599190 100644
--- a/src/test/ui/non-copyable-void.rs
+++ b/src/test/ui/non-copyable-void.rs
@@ -10,7 +10,7 @@
 
 // ignore-wasm32-bare no libc to test ffi with
 
-#![feature(libc)]
+#![feature(rustc_private)]
 
 extern crate libc;
 
diff --git a/src/test/ui/unnecessary-extern-crate.rs b/src/test/ui/unnecessary-extern-crate.rs
index 110cfef..4eb3c3d 100644
--- a/src/test/ui/unnecessary-extern-crate.rs
+++ b/src/test/ui/unnecessary-extern-crate.rs
@@ -11,7 +11,7 @@
 // edition:2018
 
 #![deny(unused_extern_crates)]
-#![feature(alloc, test, libc, crate_visibility_modifier)]
+#![feature(alloc, test, rustc_private, crate_visibility_modifier)]
 
 extern crate libc;
 //~^ ERROR unused extern crate
diff --git a/src/tools/rustc-std-workspace-core/Cargo.toml b/src/tools/rustc-std-workspace-core/Cargo.toml
new file mode 100644
index 0000000..f000d63
--- /dev/null
+++ b/src/tools/rustc-std-workspace-core/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "rustc-std-workspace-core"
+version = "1.0.0"
+authors = ["Alex Crichton <alex@alexcrichton.com>"]
+license = 'MIT/Apache-2.0'
+description = """
+Hack for the compiler's own build system
+"""
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+core = { path = "../../libcore" }
diff --git a/src/tools/rustc-std-workspace-core/README.md b/src/tools/rustc-std-workspace-core/README.md
new file mode 100644
index 0000000..9c2b1fa
--- /dev/null
+++ b/src/tools/rustc-std-workspace-core/README.md
@@ -0,0 +1,29 @@
+# The `rustc-std-workspace-core` crate
+
+This crate is a shim and empty crate which simply depends on `libcore` and
+reexports all of its contents. The crate is the crux of empowering the standard
+library to depend on crates from crates.io
+
+Crates on crates.io that the standard library depend on the
+`rustc-std-workspace-core` crate from crates.io. On crates.io, however, this
+crate is empty. We use `[patch]` to override it to this crate in this
+repository. As a result, crates on crates.io will draw a dependency edge to
+`libcore`, the version defined in this repository. That should draw all the
+dependency edges to ensure Cargo builds crates successfully!
+
+Note that crates on crates.io need to depend on this crate with the name `core`
+for everything to work correctly. To do that they can use:
+
+```toml
+core = { version = "1.0.0", optional = true, package = 'rustc-std-workspace-core' }
+```
+
+Through the use of the `package` key the crate is renamed to `core`, meaning
+it'll look like
+
+```
+--extern core=.../librustc_std_workspace_core-XXXXXXX.rlib
+```
+
+when Cargo invokes the compiler, satisfying the implicit `extern crate core`
+directive injected by the compiler.
diff --git a/src/tools/rustc-std-workspace-core/lib.rs b/src/tools/rustc-std-workspace-core/lib.rs
new file mode 100644
index 0000000..e2946fe
--- /dev/null
+++ b/src/tools/rustc-std-workspace-core/lib.rs
@@ -0,0 +1,6 @@
+#![feature(no_core)]
+#![no_core]
+
+extern crate core;
+
+pub use core::*;
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs
index e275892..2b5cff6 100644
--- a/src/tools/tidy/src/deps.rs
+++ b/src/tools/tidy/src/deps.rs
@@ -53,6 +53,7 @@
     "bytesize",           // Apache-2.0, cargo
     "im-rc",              // MPL-2.0+, cargo
     "adler32",            // BSD-3-Clause AND Zlib, cargo dep that isn't used
+    "fortanix-sgx-abi",   // MPL-2.0+, libstd but only for sgx target
 ];
 
 /// Which crates to check against the whitelist?
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs
index 53db589..614d205 100644
--- a/src/tools/tidy/src/lib.rs
+++ b/src/tools/tidy/src/lib.rs
@@ -56,15 +56,11 @@
 
 fn filter_dirs(path: &Path) -> bool {
     let skip = [
-        "src/dlmalloc",
         "src/llvm",
         "src/llvm-emscripten",
         "src/libbacktrace",
-        "src/libcompiler_builtins",
         "src/librustc_data_structures/owning_ref",
-        "src/compiler-rt",
-        "src/liblibc",
-        "src/rt/hoedown",
+        "src/vendor",
         "src/tools/cargo",
         "src/tools/clang",
         "src/tools/rls",
diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs
index 822db25..acf7202 100644
--- a/src/tools/tidy/src/pal.rs
+++ b/src/tools/tidy/src/pal.rs
@@ -26,7 +26,6 @@
 //! exceptions:
 //!
 //! - core may not have platform-specific code
-//! - libcompiler_builtins may have platform-specific code
 //! - libpanic_abort may have platform-specific code
 //! - libpanic_unwind may have platform-specific code
 //! - libunwind may have platform-specific code
@@ -50,8 +49,6 @@
 // Paths that may contain platform-specific code
 const EXCEPTION_PATHS: &[&str] = &[
     // std crates
-    "src/libcompiler_builtins",
-    "src/liblibc",
     "src/libpanic_abort",
     "src/libpanic_unwind",
     "src/libunwind",