Skip to content

Commit 4dee328

Browse files
committed
handle the no descriptor case
1 parent 0505f91 commit 4dee328

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

support/trycopy/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ fn recovery_table() -> &'static [RecoveryDescriptor] {
559559
static STOP_TRY_COPY: [RecoveryDescriptor; 0];
560560
}
561561

562+
// Ensure the section exists even if there no recovery descriptors get
563+
// generated.
564+
#[cfg_attr(target_os = "linux", unsafe(link_section = "try_copy"))]
565+
#[cfg_attr(target_os = "macos", link_section = "__TEXT,__try_copy,regular")]
566+
#[used]
567+
static ENSURE_EXISTS: [RecoveryDescriptor; 0] = [];
568+
562569
// SAFETY: accessing the trycopy section as defined above.
563570
unsafe {
564571
std::slice::from_raw_parts(
@@ -623,7 +630,10 @@ fn recovery_table() -> &'static [RecoveryDescriptor] {
623630
})
624631
}
625632

626-
let (start, len) = find_section(*b".trycopy").expect("could not find .trycopy section");
633+
let Some((start, len)) = find_section(*b".trycopy") else {
634+
// No recovery descriptors.
635+
return &[]
636+
};
627637
assert_eq!(len % size_of::<RecoveryDescriptor>(), 0);
628638
// SAFETY: this section is made up solely of RecoveryDescriptor entries.
629639
unsafe {

0 commit comments

Comments
 (0)