Skip to content

Commit a7f9aca

Browse files
authored
Rollup merge of #82534 - nikic:musl-crtend, r=nagisa
Link crtbegin/crtend on musl to terminate .eh_frame For some targets, rustc uses a "CRT fallback", where it links CRT object files it ships instead of letting the host compiler link them. On musl, rustc currently links crt1, crti and crtn (provided by libc), but does not link crtbegin and crtend (provided by libgcc). In particular, crtend is responsible for terminating the .eh_frame section. Lack of terminator may result in segfaults during unwinding, as reported in #47551 and encountered by the LLVM 12 update in #81451. This patch links crtbegin and crtend for musl as well, following the table at the top of crt_objects.rs. r? ``@nagisa``
2 parents 13ea3fa + c7091f5 commit a7f9aca

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Diff for: compiler/rustc_target/src/spec/crt_objects.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@ pub(super) fn all(obj: &str) -> CrtObjects {
6464

6565
pub(super) fn pre_musl_fallback() -> CrtObjects {
6666
new(&[
67-
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o"]),
68-
(LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o"]),
69-
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o"]),
70-
(LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o"]),
71-
(LinkOutputKind::DynamicDylib, &["crti.o"]),
72-
(LinkOutputKind::StaticDylib, &["crti.o"]),
67+
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
68+
(LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]),
69+
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
70+
(LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]),
71+
(LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]),
72+
(LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]),
7373
])
7474
}
7575

7676
pub(super) fn post_musl_fallback() -> CrtObjects {
77-
all("crtn.o")
77+
new(&[
78+
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
79+
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
80+
(LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]),
81+
(LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]),
82+
(LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]),
83+
(LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]),
84+
])
7885
}
7986

8087
pub(super) fn pre_mingw_fallback() -> CrtObjects {

Diff for: src/bootstrap/compile.rs

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ fn copy_self_contained_objects(
189189
DependencyType::TargetSelfContained,
190190
);
191191
}
192+
for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] {
193+
let src = compiler_file(builder, builder.cc(target), target, obj);
194+
let target = libdir_self_contained.join(obj);
195+
builder.copy(&src, &target);
196+
target_deps.push((target, DependencyType::TargetSelfContained));
197+
}
192198
} else if target.ends_with("-wasi") {
193199
let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
194200
for &obj in &["crt1.o", "crt1-reactor.o"] {

0 commit comments

Comments
 (0)