rustc: Work around a segmentation fault

On Linux/Mac, I got a segmentation fault:

  (gdb) bt
  #0  0x00000000007519af in glue_take584 ()
  #1  0x00000000006d4bec in
    back::rpath::get_rpath_flags::_3899df2ca513c603 ()
  #2  0x00000000006c7655 in back:🔗:link_binary::_7afde00a9791031c ()
  #3  0x00000000007d3ff5 in driver::rustc::compile_input::thunk9212 ()
  #4  0x0000000000710f24 in driver::rustc::time::_3e691b2a4ba58aee ()
  #5  0x000000000071a79d in
    driver::rustc::compile_input::_7b4a41b87c18e034 ()
  #6  0x000000000072f0a9 in driver::rustc::main::_cd8b8c8185af3dee ()
  #7  0x000000000072f1ed in _rust_main ()
  #8  0x00007ffff7e6e146 in task_start_wrapper (a=<optimized out>) at
    ../src/rt/rust_task.cpp:176

The variable `output` or `out_filename` becomes (null) after the definition
of `fn unlib`. Move the function defintion to the beginning seems
prevent the crash on Linux.
This commit is contained in:
Haitao Li 2011-12-12 21:40:03 +08:00 committed by Graydon Hoare
parent 6c6f83f693
commit 76f13c95a0
1 changed files with 24 additions and 24 deletions

View File

@ -561,6 +561,29 @@ fn link_binary(sess: session::session,
obj_filename: str,
out_filename: str,
lm: link_meta) {
// Converts a library file name into a gcc -l argument
fn unlib(config: @session::config, filename: str) -> str {
let rmlib =
bind fn (config: @session::config, filename: str) -> str {
if config.os == session::os_macos ||
config.os == session::os_linux &&
str::find(filename, "lib") == 0 {
ret str::slice(filename, 3u,
str::byte_len(filename));
} else { ret filename; }
}(config, _);
fn rmext(filename: str) -> str {
let parts = str::split(filename, '.' as u8);
vec::pop(parts);
ret str::connect(parts, ".");
}
ret alt config.os {
session::os_macos. { rmext(rmlib(filename)) }
session::os_linux. { rmext(rmlib(filename)) }
_ { rmext(filename) }
};
}
let output = if sess.building_library() {
let long_libname =
std::os::dylib_filename(#fmt("%s-%s-%s",
@ -585,29 +608,6 @@ fn link_binary(sess: session::session,
lib_cmd = "-dynamiclib";
} else { lib_cmd = "-shared"; }
// Converts a library file name into a gcc -l argument
fn unlib(config: @session::config, filename: str) -> str {
let rmlib =
bind fn (config: @session::config, filename: str) -> str {
if config.os == session::os_macos ||
config.os == session::os_linux &&
str::find(filename, "lib") == 0 {
ret str::slice(filename, 3u,
str::byte_len(filename));
} else { ret filename; }
}(config, _);
fn rmext(filename: str) -> str {
let parts = str::split(filename, '.' as u8);
vec::pop(parts);
ret str::connect(parts, ".");
}
ret alt config.os {
session::os_macos. { rmext(rmlib(filename)) }
session::os_linux. { rmext(rmlib(filename)) }
_ { rmext(filename) }
};
}
let cstore = sess.get_cstore();
for cratepath: str in cstore::get_used_crate_files(cstore) {
if str::ends_with(cratepath, ".rlib") {
@ -655,7 +655,7 @@ fn link_binary(sess: session::session,
gcc_args += ["-lmorestack"];
}
gcc_args += rpath::get_rpath_flags(sess, out_filename);
gcc_args += rpath::get_rpath_flags(sess, output);
log #fmt("gcc link args: %s", str::connect(gcc_args, " "));
// We run 'gcc' here