@@ -231,6 +231,7 @@ pub fn invalid_output_for_target(sess: &Session,
231231 crate_type : config:: CrateType ) -> bool {
232232 match ( sess. target . target . options . dynamic_linking ,
233233 sess. target . target . options . executables , crate_type) {
234+ ( false , _, config:: CrateTypeCdylib ) |
234235 ( false , _, config:: CrateTypeDylib ) => true ,
235236 ( _, false , config:: CrateTypeExecutable ) => true ,
236237 _ => false
@@ -253,6 +254,7 @@ pub fn filename_for_input(sess: &Session,
253254 config:: CrateTypeRlib => {
254255 outputs. out_directory . join ( & format ! ( "lib{}.rlib" , libname) )
255256 }
257+ config:: CrateTypeCdylib |
256258 config:: CrateTypeDylib => {
257259 let ( prefix, suffix) = ( & sess. target . target . options . dll_prefix ,
258260 & sess. target . target . options . dll_suffix ) ;
@@ -281,9 +283,10 @@ pub fn each_linked_rlib(sess: &Session,
281283 f : & mut FnMut ( ast:: CrateNum , & Path ) ) {
282284 let crates = sess. cstore . used_crates ( LinkagePreference :: RequireStatic ) . into_iter ( ) ;
283285 let fmts = sess. dependency_formats . borrow ( ) ;
284- let fmts = fmts. get ( & config:: CrateTypeExecutable ) . or_else ( || {
285- fmts. get ( & config:: CrateTypeStaticlib )
286- } ) . unwrap_or_else ( || {
286+ let fmts = fmts. get ( & config:: CrateTypeExecutable )
287+ . or_else ( || fmts. get ( & config:: CrateTypeStaticlib ) )
288+ . or_else ( || fmts. get ( & config:: CrateTypeCdylib ) ) ;
289+ let fmts = fmts. unwrap_or_else ( || {
287290 bug ! ( "could not find formats for rlibs" )
288291 } ) ;
289292 for ( cnum, path) in crates {
@@ -338,13 +341,9 @@ fn link_binary_output(sess: &Session,
338341 config:: CrateTypeStaticlib => {
339342 link_staticlib ( sess, & objects, & out_filename, tmpdir. path ( ) ) ;
340343 }
341- config:: CrateTypeExecutable => {
342- link_natively ( sess, false , & objects, & out_filename, trans, outputs,
343- tmpdir. path ( ) ) ;
344- }
345- config:: CrateTypeDylib => {
346- link_natively ( sess, true , & objects, & out_filename, trans, outputs,
347- tmpdir. path ( ) ) ;
344+ _ => {
345+ link_natively ( sess, crate_type, & objects, & out_filename, trans,
346+ outputs, tmpdir. path ( ) ) ;
348347 }
349348 }
350349
@@ -612,13 +611,14 @@ fn link_staticlib(sess: &Session, objects: &[PathBuf], out_filename: &Path,
612611//
613612// This will invoke the system linker/cc to create the resulting file. This
614613// links to all upstream files as well.
615- fn link_natively ( sess : & Session , dylib : bool ,
616- objects : & [ PathBuf ] , out_filename : & Path ,
614+ fn link_natively ( sess : & Session ,
615+ crate_type : config:: CrateType ,
616+ objects : & [ PathBuf ] ,
617+ out_filename : & Path ,
617618 trans : & CrateTranslation ,
618619 outputs : & OutputFilenames ,
619620 tmpdir : & Path ) {
620- info ! ( "preparing dylib? ({}) from {:?} to {:?}" , dylib, objects,
621- out_filename) ;
621+ info ! ( "preparing {:?} from {:?} to {:?}" , crate_type, objects, out_filename) ;
622622
623623 // The invocations of cc share some flags across platforms
624624 let ( pname, mut cmd) = get_linker ( sess) ;
@@ -627,10 +627,10 @@ fn link_natively(sess: &Session, dylib: bool,
627627 let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
628628 cmd. args ( & sess. target . target . options . pre_link_args ) ;
629629
630- let pre_link_objects = if dylib {
631- & sess. target . target . options . pre_link_objects_dll
632- } else {
630+ let pre_link_objects = if crate_type == config:: CrateTypeExecutable {
633631 & sess. target . target . options . pre_link_objects_exe
632+ } else {
633+ & sess. target . target . options . pre_link_objects_dll
634634 } ;
635635 for obj in pre_link_objects {
636636 cmd. arg ( root. join ( obj) ) ;
@@ -642,7 +642,7 @@ fn link_natively(sess: &Session, dylib: bool,
642642 } else {
643643 Box :: new ( GnuLinker { cmd : & mut cmd, sess : & sess } ) as Box < Linker >
644644 } ;
645- link_args ( & mut * linker, sess, dylib , tmpdir,
645+ link_args ( & mut * linker, sess, crate_type , tmpdir,
646646 objects, out_filename, trans, outputs) ;
647647 if !sess. target . target . options . no_compiler_rt {
648648 linker. link_staticlib ( "compiler-rt" ) ;
@@ -708,7 +708,7 @@ fn link_natively(sess: &Session, dylib: bool,
708708
709709fn link_args ( cmd : & mut Linker ,
710710 sess : & Session ,
711- dylib : bool ,
711+ crate_type : config :: CrateType ,
712712 tmpdir : & Path ,
713713 objects : & [ PathBuf ] ,
714714 out_filename : & Path ,
@@ -730,26 +730,28 @@ fn link_args(cmd: &mut Linker,
730730
731731 // If we're building a dynamic library then some platforms need to make sure
732732 // that all symbols are exported correctly from the dynamic library.
733- if dylib {
734- cmd. export_symbols ( sess, trans, tmpdir) ;
733+ if crate_type != config :: CrateTypeExecutable {
734+ cmd. export_symbols ( sess, trans, tmpdir, crate_type ) ;
735735 }
736736
737737 // When linking a dynamic library, we put the metadata into a section of the
738738 // executable. This metadata is in a separate object file from the main
739739 // object file, so we link that in here.
740- if dylib {
740+ if crate_type == config :: CrateTypeDylib {
741741 cmd. add_object ( & outputs. with_extension ( "metadata.o" ) ) ;
742742 }
743743
744744 // Try to strip as much out of the generated object by removing unused
745745 // sections if possible. See more comments in linker.rs
746746 if !sess. opts . cg . link_dead_code {
747- cmd. gc_sections ( dylib) ;
747+ let keep_metadata = crate_type == config:: CrateTypeDylib ;
748+ cmd. gc_sections ( keep_metadata) ;
748749 }
749750
750751 let used_link_args = sess. cstore . used_link_args ( ) ;
751752
752- if !dylib && t. options . position_independent_executables {
753+ if crate_type == config:: CrateTypeExecutable &&
754+ t. options . position_independent_executables {
753755 let empty_vec = Vec :: new ( ) ;
754756 let empty_str = String :: new ( ) ;
755757 let args = sess. opts . cg . link_args . as_ref ( ) . unwrap_or ( & empty_vec) ;
@@ -804,12 +806,12 @@ fn link_args(cmd: &mut Linker,
804806 // in this DAG so far because they're only dylibs and dylibs can only depend
805807 // on other dylibs (e.g. other native deps).
806808 add_local_native_libraries ( cmd, sess) ;
807- add_upstream_rust_crates ( cmd, sess, dylib , tmpdir) ;
809+ add_upstream_rust_crates ( cmd, sess, crate_type , tmpdir) ;
808810 add_upstream_native_libraries ( cmd, sess) ;
809811
810812 // # Telling the linker what we're doing
811813
812- if dylib {
814+ if crate_type != config :: CrateTypeExecutable {
813815 cmd. build_dylib ( out_filename) ;
814816 }
815817
@@ -907,8 +909,10 @@ fn add_local_native_libraries(cmd: &mut Linker, sess: &Session) {
907909// Rust crates are not considered at all when creating an rlib output. All
908910// dependencies will be linked when producing the final output (instead of
909911// the intermediate rlib version)
910- fn add_upstream_rust_crates ( cmd : & mut Linker , sess : & Session ,
911- dylib : bool , tmpdir : & Path ) {
912+ fn add_upstream_rust_crates ( cmd : & mut Linker ,
913+ sess : & Session ,
914+ crate_type : config:: CrateType ,
915+ tmpdir : & Path ) {
912916 // All of the heavy lifting has previously been accomplished by the
913917 // dependency_format module of the compiler. This is just crawling the
914918 // output of that module, adding crates as necessary.
@@ -918,11 +922,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
918922 // involves just passing the right -l flag.
919923
920924 let formats = sess. dependency_formats . borrow ( ) ;
921- let data = if dylib {
922- formats. get ( & config:: CrateTypeDylib ) . unwrap ( )
923- } else {
924- formats. get ( & config:: CrateTypeExecutable ) . unwrap ( )
925- } ;
925+ let data = formats. get ( & crate_type) . unwrap ( ) ;
926926
927927 // Invoke get_used_crates to ensure that we get a topological sorting of
928928 // crates.
@@ -937,7 +937,8 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
937937 Linkage :: NotLinked |
938938 Linkage :: IncludedFromDylib => { }
939939 Linkage :: Static => {
940- add_static_crate ( cmd, sess, tmpdir, dylib, & src. rlib . unwrap ( ) . 0 )
940+ add_static_crate ( cmd, sess, tmpdir, crate_type,
941+ & src. rlib . unwrap ( ) . 0 )
941942 }
942943 Linkage :: Dynamic => {
943944 add_dynamic_crate ( cmd, sess, & src. dylib . unwrap ( ) . 0 )
@@ -982,9 +983,12 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
982983 // (aka we're making an executable), we can just pass the rlib blindly to
983984 // the linker (fast) because it's fine if it's not actually included as
984985 // we're at the end of the dependency chain.
985- fn add_static_crate ( cmd : & mut Linker , sess : & Session , tmpdir : & Path ,
986- dylib : bool , cratepath : & Path ) {
987- if !sess. lto ( ) && !dylib {
986+ fn add_static_crate ( cmd : & mut Linker ,
987+ sess : & Session ,
988+ tmpdir : & Path ,
989+ crate_type : config:: CrateType ,
990+ cratepath : & Path ) {
991+ if !sess. lto ( ) && crate_type != config:: CrateTypeDylib {
988992 cmd. link_rlib ( & fix_windows_verbatim_for_gcc ( cratepath) ) ;
989993 return
990994 }
@@ -1020,7 +1024,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
10201024
10211025 if any_objects {
10221026 archive. build ( ) ;
1023- if dylib {
1027+ if crate_type == config :: CrateTypeDylib {
10241028 cmd. link_whole_rlib ( & fix_windows_verbatim_for_gcc ( & dst) ) ;
10251029 } else {
10261030 cmd. link_rlib ( & fix_windows_verbatim_for_gcc ( & dst) ) ;
0 commit comments