@@ -747,71 +747,6 @@ pub fn link_binary(sess: Session,
747
747
obj_filename: &Path,
748
748
out_filename: &Path,
749
749
lm: LinkMeta) {
750
- // In the future, FreeBSD will use clang as default compiler.
751
- // It would be flexible to use cc (system's default C compiler)
752
- // instead of hard-coded gcc.
753
- // For win32, there is no cc command,
754
- // so we add a condition to make it use gcc.
755
- let cc_prog: ~str = if sess.targ_cfg.os == session::os_android {
756
- match &sess.opts.android_cross_path {
757
- &Some(copy path) => {
758
- fmt!(" %s/bin/arm-linux-androideabi-gcc", path)
759
- }
760
- &None => {
761
- sess.fatal(~" need Android NDK path for linking \
762
- ( --android-cross-path) ")
763
- }
764
- }
765
- } else if sess.targ_cfg.os == session::os_win32 { ~" gcc" }
766
- else { ~" cc" };
767
- // The invocations of cc share some flags across platforms
768
-
769
-
770
- let output = if *sess.building_library {
771
- let long_libname = output_dll_filename(sess.targ_cfg.os, lm);
772
- debug!(" link_meta. name: %s", lm.name);
773
- debug!(" long_libname: %s", long_libname);
774
- debug!(" out_filename: %s", out_filename.to_str());
775
- debug!(" dirname( out_filename) : %s", out_filename.dir_path().to_str());
776
-
777
- out_filename.dir_path().push(long_libname)
778
- } else {
779
- /*bad*/copy *out_filename
780
- };
781
-
782
- debug!(" output: %s", output.to_str());
783
- let mut cc_args = link_args(sess, obj_filename, out_filename, lm);
784
- debug!(" %s link args: %s", cc_prog, str::connect(cc_args, ~" "));
785
- // We run 'cc' here
786
- let prog = run::program_output(cc_prog, cc_args);
787
- if 0 != prog.status {
788
- sess.err(fmt!(" linking with `%s` failed with code %d",
789
- cc_prog, prog.status));
790
- sess.note(fmt!(" %s arguments: %s",
791
- cc_prog, str::connect(cc_args, ~" ")));
792
- sess.note(prog.err + prog.out);
793
- sess.abort_if_errors();
794
- }
795
-
796
- // Clean up on Darwin
797
- if sess.targ_cfg.os == session::os_macos {
798
- run::run_program(~" dsymutil", ~[output.to_str()]);
799
- }
800
-
801
- // Remove the temporary object file if we aren't saving temps
802
- if !sess.opts.save_temps {
803
- if ! os::remove_file(obj_filename) {
804
- sess.warn(fmt!(" failed to delete object file `%s`",
805
- obj_filename. to_str( ) ) ) ;
806
- }
807
- }
808
- }
809
-
810
- pub fn link_args( sess: Session ,
811
- obj_filename: & Path ,
812
- out_filename: & Path ,
813
- lm: LinkMeta ) -> ~[ ~str ] {
814
-
815
750
// Converts a library file-stem into a cc -l argument
816
751
fn unlib(config: @session::config, stem: ~str) -> ~str {
817
752
if stem.starts_with(" lib") &&
@@ -822,23 +757,48 @@ pub fn link_args(sess: Session,
822
757
}
823
758
}
824
759
825
-
826
760
let output = if *sess.building_library {
827
761
let long_libname = output_dll_filename(sess.targ_cfg.os, lm);
762
+ debug!(" link_meta. name: %s", lm.name);
763
+ debug!(" long_libname: %s", long_libname);
764
+ debug!(" out_filename: %s", out_filename.to_str());
765
+ debug!(" dirname( out_filename) : %s", out_filename.dir_path().to_str());
766
+
828
767
out_filename.dir_path().push(long_libname)
829
768
} else {
830
769
/*bad*/copy *out_filename
831
770
};
832
771
772
+ debug!(" output: %s", output.to_str());
773
+
833
774
// The default library location, we need this to find the runtime.
834
775
// The location of crates will be determined as needed.
835
776
let stage: ~str = ~" -L " + sess.filesearch.get_target_lib_path().to_str();
836
777
837
- let mut args = vec:: append( ~[ stage] , sess. targ_cfg. target_strs. cc_args) ;
778
+ // In the future, FreeBSD will use clang as default compiler.
779
+ // It would be flexible to use cc (system's default C compiler)
780
+ // instead of hard-coded gcc.
781
+ // For win32, there is no cc command,
782
+ // so we add a condition to make it use gcc.
783
+ let cc_prog: ~str = if sess.targ_cfg.os == session::os_android {
784
+ match &sess.opts.android_cross_path {
785
+ &Some(copy path) => {
786
+ fmt!(" %s/bin/arm-linux-androideabi-gcc", path)
787
+ }
788
+ &None => {
789
+ sess.fatal(~" need Android NDK path for linking \
790
+ ( --android-cross-path) ")
791
+ }
792
+ }
793
+ } else if sess.targ_cfg.os == session::os_win32 { ~" gcc" }
794
+ else { ~" cc" };
795
+ // The invocations of cc share some flags across platforms
838
796
839
- args. push( ~"-o") ;
840
- args. push( output. to_str( ) ) ;
841
- args. push( obj_filename. to_str( ) ) ;
797
+ let mut cc_args =
798
+ vec::append(~[stage], sess.targ_cfg.target_strs.cc_args);
799
+ cc_args.push(~" -o");
800
+ cc_args.push(output.to_str());
801
+ cc_args.push(obj_filename.to_str());
842
802
843
803
let lib_cmd;
844
804
let os = sess.targ_cfg.os;
@@ -853,23 +813,23 @@ pub fn link_args(sess: Session,
853
813
let cstore = sess.cstore;
854
814
for cstore::get_used_crate_files(cstore).each |cratepath| {
855
815
if cratepath.filetype() == Some(~" . rlib") {
856
- args . push( cratepath. to_str( ) ) ;
816
+ cc_args .push(cratepath.to_str());
857
817
loop;
858
818
}
859
819
let dir = cratepath.dirname();
860
- if dir != ~"" { args . push( ~"-L " + dir) ; }
820
+ if dir != ~" " { cc_args .push(~" -L " + dir); }
861
821
let libarg = unlib(sess.targ_cfg, cratepath.filestem().get());
862
- args . push( ~"-l" + libarg) ;
822
+ cc_args .push(~" -l" + libarg);
863
823
}
864
824
865
825
let ula = cstore::get_used_link_args(cstore);
866
- for ula. each |arg| { args . push( /*bad*/ copy * arg) ; }
826
+ for ula.each |arg| { cc_args .push(/*bad*/copy *arg); }
867
827
868
828
// Add all the link args for external crates.
869
829
do cstore::iter_crate_data(cstore) |crate_num, _| {
870
830
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
871
831
do vec::consume(link_args) |_, link_arg| {
872
- args . push( link_arg) ;
832
+ cc_args .push(link_arg);
873
833
}
874
834
}
875
835
@@ -882,74 +842,93 @@ pub fn link_args(sess: Session,
882
842
// forces to make sure that library can be found at runtime.
883
843
884
844
for sess.opts.addl_lib_search_paths.each |path| {
885
- args . push( ~"-L " + path. to_str( ) ) ;
845
+ cc_args .push(~" -L " + path.to_str());
886
846
}
887
847
888
848
// The names of the extern libraries
889
849
let used_libs = cstore::get_used_libraries(cstore);
890
- for used_libs. each |l| { args . push( ~"-l" + * l) ; }
850
+ for used_libs.each |l| { cc_args .push(~" -l" + *l); }
891
851
892
852
if *sess.building_library {
893
- args . push( lib_cmd) ;
853
+ cc_args .push(lib_cmd);
894
854
895
855
// On mac we need to tell the linker to let this library
896
856
// be rpathed
897
857
if sess.targ_cfg.os == session::os_macos {
898
- args . push( ~"-Wl , -install_name, @rpath/"
858
+ cc_args .push(~" -Wl , -install_name, @rpath/"
899
859
+ output.filename().get());
900
860
}
901
861
}
902
862
903
863
// On linux librt and libdl are an indirect dependencies via rustrt,
904
864
// and binutils 2.22+ won't add them automatically
905
865
if sess.targ_cfg.os == session::os_linux {
906
- args . push_all( ~[ ~"-lrt", ~"-ldl"] ) ;
866
+ cc_args .push_all(~[~" -lrt", ~" -ldl"]);
907
867
908
868
// LLVM implements the `frem` instruction as a call to `fmod`,
909
869
// which lives in libm. Similar to above, on some linuxes we
910
870
// have to be explicit about linking to it. See #2510
911
- args . push( ~"-lm") ;
871
+ cc_args .push(~" -lm");
912
872
}
913
873
else if sess.targ_cfg.os == session::os_android {
914
- args . push_all( ~[ ~"-ldl", ~"-llog", ~"-lsupc++",
874
+ cc_args .push_all(~[~" -ldl", ~" -llog", ~" -lsupc++",
915
875
~" -lgnustl_shared"]);
916
- args . push( ~"-lm") ;
876
+ cc_args .push(~" -lm");
917
877
}
918
878
919
879
if sess.targ_cfg.os == session::os_freebsd {
920
- args . push_all( ~[ ~"-pthread", ~"-lrt",
921
- ~"-L /usr/local/lib", ~"-lexecinfo",
922
- ~"-L /usr/local/lib/gcc46",
923
- ~"-L /usr/local/lib/gcc44", ~"-lstdc++",
924
- ~"-Wl , -z, origin",
925
- ~"-Wl , -rpath, /usr/local/lib/gcc46",
926
- ~"-Wl , -rpath, /usr/local/lib/gcc44"] ) ;
880
+ cc_args .push_all(~[~" -pthread", ~" -lrt",
881
+ ~" -L /usr/local/lib", ~" -lexecinfo",
882
+ ~" -L /usr/local/lib/gcc46",
883
+ ~" -L /usr/local/lib/gcc44", ~" -lstdc++",
884
+ ~" -Wl , -z, origin",
885
+ ~" -Wl , -rpath, /usr/local/lib/gcc46",
886
+ ~" -Wl , -rpath, /usr/local/lib/gcc44"]);
927
887
}
928
888
929
889
// OS X 10.6 introduced 'compact unwind info', which is produced by the
930
890
// linker from the dwarf unwind info. Unfortunately, it does not seem to
931
891
// understand how to unwind our __morestack frame, so we have to turn it
932
892
// off. This has impacted some other projects like GHC.
933
893
if sess.targ_cfg.os == session::os_macos {
934
- args . push( ~"-Wl , -no_compact_unwind") ;
894
+ cc_args .push(~" -Wl , -no_compact_unwind");
935
895
}
936
896
937
897
// Stack growth requires statically linking a __morestack function
938
- args . push( ~"-lmorestack") ;
898
+ cc_args .push(~" -lmorestack");
939
899
940
900
// Always want the runtime linked in
941
- args . push( ~"-lrustrt") ;
901
+ cc_args .push(~" -lrustrt");
942
902
943
903
// FIXME (#2397): At some point we want to rpath our guesses as to where
944
904
// extern libraries might live, based on the addl_lib_search_paths
945
- args . push_all( rpath:: get_rpath_flags( sess, & output) ) ;
905
+ cc_args .push_all(rpath::get_rpath_flags(sess, &output));
946
906
947
- // Finally add all the linker arguments provided on the command line
948
- args. push_all( sess. opts. linker_args) ;
907
+ debug!(" %s link args: %s", cc_prog, str::connect(cc_args, ~" "));
908
+ // We run 'cc' here
909
+ let prog = run::program_output(cc_prog, cc_args);
910
+ if 0 != prog.status {
911
+ sess.err(fmt!(" linking with `%s` failed with code %d",
912
+ cc_prog, prog.status));
913
+ sess.note(fmt!(" %s arguments: %s",
914
+ cc_prog, str::connect(cc_args, ~" ")));
915
+ sess.note(prog.err + prog.out);
916
+ sess.abort_if_errors();
917
+ }
949
918
950
- return args;
951
- }
919
+ // Clean up on Darwin
920
+ if sess.targ_cfg.os == session::os_macos {
921
+ run::run_program(~" dsymutil", ~[output.to_str()]);
922
+ }
952
923
924
+ // Remove the temporary object file if we aren't saving temps
925
+ if !sess.opts.save_temps {
926
+ if ! os::remove_file(obj_filename) {
927
+ sess.warn(fmt!(" failed to delete object file `%s`",
928
+ obj_filename. to_str( ) ) ) ;
929
+ }
930
+ }
931
+ }
953
932
//
954
933
// Local Variables:
955
934
// mode: rust
0 commit comments