- let mut copy_and_stamp = |sourcedir: &Path, name: &str| {
- let target = libdir.join(name);
- builder.copy(&sourcedir.join(name), &target);
- target_deps.push(target);
+ // Copies libunwind.a compiled to be linked with x86_64-fortanix-unknown-sgx.
+ //
+ // This target needs to be linked to Fortanix's port of llvm's libunwind.
+ // libunwind requires support for rwlock and printing to stderr,
+ // which is provided by std for this target.
+ if target == "x86_64-fortanix-unknown-sgx" {
+ let src_path_env = "X86_FORTANIX_SGX_LIBS";
+ let src =
+ env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env));
+ copy_and_stamp(
+ builder,
+ &*libdir,
+ Path::new(&src),
+ "libunwind.a",
+ &mut target_deps,
+ DependencyType::Target,
+ );
+ }
+
+ if builder.config.sanitizers && compiler.stage != 0 {
+ // The sanitizers are only copied in stage1 or above,
+ // to avoid creating dependency on LLVM.
+ target_deps.extend(
+ copy_sanitizers(builder, &compiler, target)
+ .into_iter()
+ .map(|d| (d, DependencyType::Target)),
+ );
+ }
+
+ target_deps
+}
+
+/// Copies third party objects needed by various targets for self-contained linkage.
+fn copy_self_contained_objects(
+ builder: &Builder<'_>,
+ compiler: &Compiler,
+ target: Interned<String>,
+) -> Vec<(PathBuf, DependencyType)> {
+ // cfg(bootstrap)
+ // Remove when upgrading bootstrap compiler.
+ let libdir_self_contained = if compiler.stage == 0 {
+ builder.sysroot_libdir(*compiler, target).to_path_buf()
+ } else {
+ builder.sysroot_libdir(*compiler, target).join("self-contained")