// Create a dynamic library or executable
//
// This will invoke the system linker/cc to create the resulting file. This
// links to all upstream files as well.
Create a dynamic library or executable
This will invoke the system linker/cc to create the resulting file. This
links to all upstream files as well.
Create a dynamic library or executable This will invoke the system linker / cc to create the resulting file . This links to all upstream files as well .
fn link_natively(sess: &Session, dylib: bool,
                 objects: &[PathBuf], out_filename: &Path,
                 trans: &CrateTranslation,
                 outputs: &OutputFilenames,
                 tmpdir: &Path) {
    info!("preparing dylib? ({}) from {:?} to {:?}", dylib, objects,
          out_filename);
    // The invocations of cc share some flags across platforms
    let (pname, mut cmd) = get_linker(sess);
    cmd.env("PATH", command_path(sess));
    let root = sess.target_filesearch(PathKind::Native).get_lib_path();
    cmd.args(&sess.target.target.options.pre_link_args);
    for obj in &sess.target.target.options.pre_link_objects {
        cmd.arg(root.join(obj));
    }
    {
        let mut linker = if sess.target.target.options.is_like_msvc {
            Box::new(MsvcLinker { cmd: &mut cmd, sess: &sess }) as Box<Linker>
        } else {
            Box::new(GnuLinker { cmd: &mut cmd, sess: &sess }) as Box<Linker>
        };
        link_args(&mut *linker, sess, dylib, tmpdir,
                  objects, out_filename, trans, outputs);
        if !sess.target.target.options.no_compiler_rt {
            linker.link_staticlib("compiler-rt");
        }
    }
    for obj in &sess.target.target.options.post_link_objects {
        cmd.arg(root.join(obj));
    }
    cmd.args(&sess.target.target.options.post_link_args);
    if sess.opts.debugging_opts.print_link_args {
        println!("{:?}", &cmd);
    }
    // May have not found libraries in the right formats.
    sess.abort_if_errors();
    // Invoke the system linker
    info!("{:?}", &cmd);
    let prog = time(sess.time_passes(), "running linker", || cmd.output());
    match prog {
        Ok(prog) => {
            if !prog.status.success() {
                sess.err(&format!("linking with `{}` failed: {}",
                                 pname,
                                 prog.status));
                sess.note(&format!("{:?}", &cmd));
                let mut output = prog.stderr.clone();
                output.push_all(&prog.stdout);
                sess.note(str::from_utf8(&output[..]).unwrap());
                sess.abort_if_errors();
            }
            info!("linker stderr:\n{}", String::from_utf8(prog.stderr).unwrap());
            info!("linker stdout:\n{}", String::from_utf8(prog.stdout).unwrap());
        },
        Err(e) => {
            sess.fatal(&format!("could not exec the linker `{}`: {}", pname, e));
        }
    }
    // On OSX, debuggers need this utility to get run to do some munging of
    // the symbols
    if sess.target.target.options.is_like_osx && sess.opts.debuginfo != NoDebugInfo {
        match Command::new("dsymutil").arg(out_filename).output() {
            Ok(..) => {}
            Err(e) => sess.fatal(&format!("failed to run dsymutil: {}", e)),
        }
    }
}
fn link_natively ( sess : & Session , dylib : bool , objects : & [ PathBuf ] , out_filename : & Path , trans : & CrateTranslation , outputs : & OutputFilenames , tmpdir : & Path ) { info ! ( " " dylib objects out_filename ) ; // The invocations of cc share some flags across platforms let ( pname , mut cmd ) = get_linker ( sess ) ; cmd . env ( " " , command_path ( sess ) ) ; let root = sess . target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ; cmd . args ( & sess . target . target . options . pre_link_args ) ; for obj in & sess . target . target . options . pre_link_objects { cmd . arg ( root . join ( obj ) ) ; } { let mut linker = if sess . target . target . options . is_like_msvc { Box :: new ( MsvcLinker { cmd : & mut cmd , sess : & sess } ) as Box < Linker > } else { Box :: new ( GnuLinker { cmd : & mut cmd , sess : & sess } ) as Box < Linker > } ; link_args ( & mut * linker , sess , dylib , tmpdir , objects , out_filename , trans , outputs ) ; if ! sess . target . target . options . no_compiler_rt { linker . link_staticlib ( " " ) ; } } for obj in & sess . target . target . options . post_link_objects { cmd . arg ( root . join ( obj ) ) ; } cmd . args ( & sess . target . target . options . post_link_args ) ; if sess . opts . debugging_opts . print_link_args { println ! ( " " cmd ) ; } // May have not found libraries in the right formats. sess . abort_if_errors ( ) ; // Invoke the system linker info ! ( " " cmd ) ; let prog = time ( sess . time_passes ( ) , " " , | | cmd . output ( ) ) ; match prog { Ok ( prog ) => { if ! prog . status . success ( ) { sess . err ( & format ! ( " " pname prog status ) ) ; sess . note ( & format ! ( " " cmd ) ) ; let mut output = prog . stderr . clone ( ) ; output . push_all ( & prog . stdout ) ; sess . note ( str :: from_utf8 ( & output [ .. ] ) . unwrap ( ) ) ; sess . abort_if_errors ( ) ; } info ! ( " \n " String from_utf8 ( prog stderr ) unwrap ( ) ) ; info ! ( " \n " String from_utf8 ( prog stdout ) unwrap ( ) ) ; } , Err ( e ) => { sess . fatal ( & format ! ( " " pname e ) ) ; } } // On OSX, debuggers need this utility to get run to do some munging of // the symbols if sess . target . target . options . is_like_osx && sess . opts . debuginfo != NoDebugInfo { match Command :: new ( " " ) . arg ( out_filename ) . output ( ) { Ok ( .. ) => { } Err ( e ) => sess . fatal ( & format ! ( " " e ) ) , } } }
Create a dynamic library or executable
This will invoke the system linker/cc to create the resulting file.
Create a dynamic library or executable This will invoke the system linker / cc to create the resulting file .
sess
&Session
dylib
bool
objects
&[PathBuf]
out_filename
&Path
trans
&CrateTranslation
outputs
&OutputFilenames
tmpdir
&Path