Open
Description
While working on #123974, I had a failure when running doctests of the unstable book. Rustdoc generates this code:
#![allow(unused_extern_crates)]
#![allow(internal_features)]
#![feature(test)]
#![feature(rustc_attrs)]
#![feature(coverage_attribute)]
#![feature(link_arg_attribute)]
#![allow(unused)]
extern crate test;
mod __doctest_0 {
fn main() {
#[link(kind = "link-arg", name = "--start-group")]
#[link(kind = "static", name = "c")] // Causing the segfault
#[link(kind = "static", name = "gcc")]
#[link(kind = "link-arg", name = "--end-group")]
extern "C" {}
}
#[rustc_test_marker = "/home/imperio/rust/rust/src/doc/unstable-book/src/language-features/link-arg-attribute.md - The_tracking_issue_for_this_feature_is__ (line 11)"]
pub const TEST: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("/home/imperio/rust/rust/src/doc/unstable-book/src/language-features/link-arg-attribute.md - The_tracking_issue_for_this_feature_is__ (line 11)"),
ignore: false,
ignore_message: None,
source_file: "_home_imperio_rust_rust_src_doc_unstable_book_src_language_features_link_arg_attribute_md",
start_line: 11,
start_col: 0,
end_line: 0,
end_col: 0,
compile_fail: false,
no_run: true,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::UnitTest,
},
testfn: test::StaticTestFn(
#[coverage(off)]
|| test::assert_test_result(Ok::<(), String>(())),
)
};
}
#[rustc_main]
#[coverage(off)]
fn main() {
test::test_main(&["rustdoctest".to_string(),], vec![__doctest_0::TEST], None);
}
If you compile and run this program (on linux x86_64), it'll segfault. Commenting #[link(kind = "static", name = "c")]
will make it run without problem.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Noratrieb commentedon Apr 17, 2024
I'd just like to interject for a moment. What you're refering to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux.
No but if you're on GNU/Linux then I do expect that to end badly, because glibc is not supposed to be linked statically.
I also don't know how rustc deals with having several linkages to "c" (as the standard library also links to it) but probably not very well either.
it would be interesting to know where it segfaults, but this certainly isn't supposed to work :D.
bjorn3 commentedon Apr 17, 2024
You have to use
-Ctarget-feature=+crt-static
to statically link libc. Otherwise you will still be producing a dynamically linked executable.