Skip to content

Commit fb25ef8

Browse files
committed
fix build with stack protector
1 parent a6033f1 commit fb25ef8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/support.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
6666
extern "C" fn __stack_chk_fail() -> ! {
6767
explode("stack smashing detected");
6868
}
69+
70+
// Stack canary value for stack protection. In a production system, this would
71+
// be randomized at startup, but for nix-ld's minimal environment, a constant
72+
// suffices to satisfy the linker requirements from libcompiler_builtins.
73+
#[unsafe(no_mangle)]
74+
static __stack_chk_guard: usize = 0x1234567890abcdef_u64 as usize;
75+
76+
// On 32-bit systems, PIC code uses __stack_chk_fail_local instead of __stack_chk_fail
77+
// as an optimization to avoid going through the PLT
78+
#[cfg(target_pointer_width = "32")]
79+
#[unsafe(no_mangle)]
80+
extern "C" fn __stack_chk_fail_local() -> ! {
81+
explode("stack smashing detected");
82+
}

0 commit comments

Comments
 (0)