@@ -1085,6 +1085,23 @@ fn link_args(sess: Session,
1085
1085
~"-o", out_filename. as_str ( ) . unwrap ( ) . to_owned ( ) ,
1086
1086
obj_filename. as_str ( ) . unwrap ( ) . to_owned ( ) ] ) ;
1087
1087
1088
+ // Stack growth requires statically linking a __morestack function. Note
1089
+ // that this is listed *before* all other libraries, even though it may be
1090
+ // used to resolve symbols in other libraries. The only case that this
1091
+ // wouldn't be pulled in by the object file is if the object file had no
1092
+ // functions.
1093
+ //
1094
+ // If we're building an executable, there must be at least one function (the
1095
+ // main function), and if we're building a dylib then we don't need it for
1096
+ // later libraries because they're all dylibs (not rlibs).
1097
+ //
1098
+ // I'm honestly not entirely sure why this needs to come first. Apparently
1099
+ // the --as-needed flag above sometimes strips out libstd from the command
1100
+ // line, but inserting this farther to the left makes the
1101
+ // "rust_stack_exhausted" symbol an outstanding undefined symbol, which
1102
+ // flags libstd as a required library (or whatever provides the symbol).
1103
+ args. push ( ~"-lmorestack") ;
1104
+
1088
1105
// When linking a dynamic library, we put the metadata into a section of the
1089
1106
// executable. This metadata is in a separate object file from the main
1090
1107
// object file, so we link that in here.
@@ -1200,11 +1217,13 @@ fn link_args(sess: Session,
1200
1217
args. push_all ( rpath:: get_rpath_flags ( sess, out_filename) . as_slice ( ) ) ;
1201
1218
}
1202
1219
1203
- // Stack growth requires statically linking a __morestack function
1204
- args. push ( ~"-lmorestack") ;
1205
- // compiler-rt contains implementations of low-level LLVM helpers
1206
- // It should go before platform and user libraries, so it has first dibs
1207
- // at resolving symbols that also appear in libgcc.
1220
+ // compiler-rt contains implementations of low-level LLVM helpers. This is
1221
+ // used to resolve symbols from the object file we just created, as well as
1222
+ // any system static libraries that may be expecting gcc instead. Most
1223
+ // symbols in libgcc also appear in compiler-rt.
1224
+ //
1225
+ // This is the end of the command line, so this library is used to resolve
1226
+ // *all* undefined symbols in all other libraries, and this is intentional.
1208
1227
args. push ( ~"-lcompiler-rt") ;
1209
1228
1210
1229
// Finally add all the linker arguments provided on the command line along
0 commit comments