Skip to content

Commit 76f13c9

Browse files
lhtgraydon
authored andcommitted
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::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.
1 parent 6c6f83f commit 76f13c9

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/comp/back/link.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,29 @@ fn link_binary(sess: session::session,
561561
obj_filename: str,
562562
out_filename: str,
563563
lm: link_meta) {
564+
// Converts a library file name into a gcc -l argument
565+
fn unlib(config: @session::config, filename: str) -> str {
566+
let rmlib =
567+
bind fn (config: @session::config, filename: str) -> str {
568+
if config.os == session::os_macos ||
569+
config.os == session::os_linux &&
570+
str::find(filename, "lib") == 0 {
571+
ret str::slice(filename, 3u,
572+
str::byte_len(filename));
573+
} else { ret filename; }
574+
}(config, _);
575+
fn rmext(filename: str) -> str {
576+
let parts = str::split(filename, '.' as u8);
577+
vec::pop(parts);
578+
ret str::connect(parts, ".");
579+
}
580+
ret alt config.os {
581+
session::os_macos. { rmext(rmlib(filename)) }
582+
session::os_linux. { rmext(rmlib(filename)) }
583+
_ { rmext(filename) }
584+
};
585+
}
586+
564587
let output = if sess.building_library() {
565588
let long_libname =
566589
std::os::dylib_filename(#fmt("%s-%s-%s",
@@ -585,29 +608,6 @@ fn link_binary(sess: session::session,
585608
lib_cmd = "-dynamiclib";
586609
} else { lib_cmd = "-shared"; }
587610

588-
// Converts a library file name into a gcc -l argument
589-
fn unlib(config: @session::config, filename: str) -> str {
590-
let rmlib =
591-
bind fn (config: @session::config, filename: str) -> str {
592-
if config.os == session::os_macos ||
593-
config.os == session::os_linux &&
594-
str::find(filename, "lib") == 0 {
595-
ret str::slice(filename, 3u,
596-
str::byte_len(filename));
597-
} else { ret filename; }
598-
}(config, _);
599-
fn rmext(filename: str) -> str {
600-
let parts = str::split(filename, '.' as u8);
601-
vec::pop(parts);
602-
ret str::connect(parts, ".");
603-
}
604-
ret alt config.os {
605-
session::os_macos. { rmext(rmlib(filename)) }
606-
session::os_linux. { rmext(rmlib(filename)) }
607-
_ { rmext(filename) }
608-
};
609-
}
610-
611611
let cstore = sess.get_cstore();
612612
for cratepath: str in cstore::get_used_crate_files(cstore) {
613613
if str::ends_with(cratepath, ".rlib") {
@@ -655,7 +655,7 @@ fn link_binary(sess: session::session,
655655
gcc_args += ["-lmorestack"];
656656
}
657657

658-
gcc_args += rpath::get_rpath_flags(sess, out_filename);
658+
gcc_args += rpath::get_rpath_flags(sess, output);
659659

660660
log #fmt("gcc link args: %s", str::connect(gcc_args, " "));
661661
// We run 'gcc' here

0 commit comments

Comments
 (0)