fn link_unsigned(&mut self, unsigned_enclave: &Path) -> Result<(), Error> {
        let lds = if let Some(lds) = &self.lds {
            rerun_if_changed!(lds.as_os_str().to_str().expect("Invalid UTF-8 in LDS path"));
            lds.clone()
        } else {
            let mut lds = self.out_dir.to_owned();
            lds.push(&self.name);
            lds.set_extension("lds");
            lds
        };

        if !lds.exists() {
            fs::write(
                &lds,
                "{
    global:
        g_global_data_sim;
        g_global_data;
        enclave_entry;
        g_peak_heap_used;
        g_peak_rsrv_mem_committed;
    local:
        *;
};
",
            )?;
        }

        let sim_postfix = match self.sgx_mode {
            SgxMode::Hardware => "",
            SgxMode::Simulation => "_sim",
        };

        // "target/foo_enclave"
        let staticlib_target_dir = self.target_dir.join(&self.name);

        // e.g. "foo_enclave_trusted"
        let staticlib_crate_name = self.staticlib.workspace_members[0]
            .repr
            .split_whitespace()
            .next()
            .ok_or(Error::TrustedCrateName)?;

        // "target/name/<profile>/libfoo_enclave_trusted.a" -- not xplatform, but neither is our
        // use of SGX, so meh.
        let mut static_archive_name = "lib".to_owned();
        static_archive_name.push_str(staticlib_crate_name);
        let mut static_archive = staticlib_target_dir.join(&self.profile);
        static_archive.push(static_archive_name);
        static_archive.set_extension("a");
        self.build_enclave()?;

        if Command::new(&self.linker)
            .args(&[
                "-o",
                unsigned_enclave
                    .to_str()
                    .expect("Invalid UTF-8 in unsigned enclave path"),
            ])
            .args(&["--no-undefined", "-nostdlib"])
            .arg(format!("-L{}", self.libdir.display()))
            .args(&[
                "--whole-archive",
                &format!("-lsgx_trts{}", sim_postfix),
                "--no-whole-archive",
            ])
            .args(&[
                "--start-group",
                "-lsgx_tstdc",
                "-lsgx_tcxx",
                "-lsgx_tcrypto",
                &format!("-lsgx_tservice{}", sim_postfix),
                static_archive
                    .to_str()
                    .expect("Invalid UTF-8 in enclave staticlib filename"),
                "--end-group",
            ])
            .args(&["-Bstatic", "-Bsymbolic", "--no-undefined"])
            .args(&["-pie", "-eenclave_entry", "--export-dynamic"])
            .args(&["--defsym", "__ImageBase=0"])
            .arg("--gc-sections")
            .arg(format!(
                "--version-script={}",
                lds.to_str()
                    .expect("Invalid UTF-8 in linker version-script filename")
            ))
            .status()?
            .success()
        {
            let unsigned_artifact = self.profile_target_dir.join(
                unsigned_enclave
                    .file_name()
                    .expect("Could not figure out filename from unsigned archive path"),
            );
            fs::copy(unsigned_enclave, unsigned_artifact)?;
            Ok(())
        } else {
            Err(Error::TrustedLink)
        }
    }
/// Using the static archive generated from the staticlib crate, link an unsigned dynamic
/// object.
Using the static archive generated from the staticlib crate, link an unsigned dynamic
object.
Using the static archive generated from the staticlib crate link an unsigned dynamic object .
fn link_unsigned(&mut self, unsigned_enclave: &Path) -> Result<(), Error> {
        let lds = if let Some(lds) = &self.lds {
            rerun_if_changed!(lds.as_os_str().to_str().expect("Invalid UTF-8 in LDS path"));
            lds.clone()
        } else {
            let mut lds = self.out_dir.to_owned();
            lds.push(&self.name);
            lds.set_extension("lds");
            lds
        };
        if !lds.exists() {
            fs::write(
                &lds,
                "{
    global:
        g_global_data_sim;
        g_global_data;
        enclave_entry;
        g_peak_heap_used;
        g_peak_rsrv_mem_committed;
    local:
        *;
};
",
            )?;
        }
        let sim_postfix = match self.sgx_mode {
            SgxMode::Hardware => "",
            SgxMode::Simulation => "_sim",
        };
        // "target/foo_enclave"
        let staticlib_target_dir = self.target_dir.join(&self.name);
        // e.g. "foo_enclave_trusted"
        let staticlib_crate_name = self.staticlib.workspace_members[0]
            .repr
            .split_whitespace()
            .next()
            .ok_or(Error::TrustedCrateName)?;
        // "target/name/<profile>/libfoo_enclave_trusted.a" -- not xplatform, but neither is our
        // use of SGX, so meh.
        let mut static_archive_name = "lib".to_owned();
        static_archive_name.push_str(staticlib_crate_name);
        let mut static_archive = staticlib_target_dir.join(&self.profile);
        static_archive.push(static_archive_name);
        static_archive.set_extension("a");
        self.build_enclave()?;
        if Command::new(&self.linker)
            .args(&[
                "-o",
                unsigned_enclave
                    .to_str()
                    .expect("Invalid UTF-8 in unsigned enclave path"),
            ])
            .args(&["--no-undefined", "-nostdlib"])
            .arg(format!("-L{}", self.libdir.display()))
            .args(&[
                "--whole-archive",
                &format!("-lsgx_trts{}", sim_postfix),
                "--no-whole-archive",
            ])
            .args(&[
                "--start-group",
                "-lsgx_tstdc",
                "-lsgx_tcxx",
                "-lsgx_tcrypto",
                &format!("-lsgx_tservice{}", sim_postfix),
                static_archive
                    .to_str()
                    .expect("Invalid UTF-8 in enclave staticlib filename"),
                "--end-group",
            ])
            .args(&["-Bstatic", "-Bsymbolic", "--no-undefined"])
            .args(&["-pie", "-eenclave_entry", "--export-dynamic"])
            .args(&["--defsym", "__ImageBase=0"])
            .arg("--gc-sections")
            .arg(format!(
                "--version-script={}",
                lds.to_str()
                    .expect("Invalid UTF-8 in linker version-script filename")
            ))
            .status()?
            .success()
        {
            let unsigned_artifact = self.profile_target_dir.join(
                unsigned_enclave
                    .file_name()
                    .expect("Could not figure out filename from unsigned archive path"),
            );
            fs::copy(unsigned_enclave, unsigned_artifact)?;
            Ok(())
        } else {
            Err(Error::TrustedLink)
        }
    }
fn link_unsigned ( & mut self , unsigned_enclave : & Path ) -> Result < ( ) , Error > { let lds = if let Some ( lds ) = & self . lds { rerun_if_changed ! ( lds as_os_str ( ) to_str ( ) expect ( " " ) ) ; lds . clone ( ) } else { let mut lds = self . out_dir . to_owned ( ) ; lds . push ( & self . name ) ; lds . set_extension ( " " ) ; lds } ; if ! lds . exists ( ) { fs :: write ( & lds , " " , ) ? ; } let sim_postfix = match self . sgx_mode { SgxMode :: Hardware => " " , SgxMode :: Simulation => " " , } ; // "target/foo_enclave" let staticlib_target_dir = self . target_dir . join ( & self . name ) ; // e.g. "foo_enclave_trusted" let staticlib_crate_name = self . staticlib . workspace_members [ 0 ] . repr . split_whitespace ( ) . next ( ) . ok_or ( Error :: TrustedCrateName ) ? ; // "target/name/<profile>/libfoo_enclave_trusted.a" -- not xplatform, but neither is our // use of SGX, so meh. let mut static_archive_name = " " . to_owned ( ) ; static_archive_name . push_str ( staticlib_crate_name ) ; let mut static_archive = staticlib_target_dir . join ( & self . profile ) ; static_archive . push ( static_archive_name ) ; static_archive . set_extension ( " " ) ; self . build_enclave ( ) ? ; if Command :: new ( & self . linker ) . args ( & [ " " , unsigned_enclave . to_str ( ) . expect ( " " ) , ] ) . args ( & [ " " , " " ] ) . arg ( format ! ( " " self libdir display ( ) ) ) . args ( & [ " " , & format ! ( " " sim_postfix ) , " " , ] ) . args ( & [ " " , " " , " " , " " , & format ! ( " " sim_postfix ) , static_archive . to_str ( ) . expect ( " " ) , " " , ] ) . args ( & [ " " , " " , " " ] ) . args ( & [ " " , " " , " " ] ) . args ( & [ " " , " " ] ) . arg ( " " ) . arg ( format ! ( " " lds to_str ( ) expect ( " " ) ) ) . status ( ) ? . success ( ) { let unsigned_artifact = self . profile_target_dir . join ( unsigned_enclave . file_name ( ) . expect ( " " ) , ) ; fs :: copy ( unsigned_enclave , unsigned_artifact ) ? ; Ok ( ( ) ) } else { Err ( Error :: TrustedLink ) } }
Using the static archive generated from the staticlib crate, link an unsigned dynamic
object.
Using the static archive generated from the staticlib crate link an unsigned dynamic object .
&mut self
unsigned_enclave
&Path
&mut self
unsigned_enclave
&Path