Freestanding hex dumper, x86-64 Linux, own _start, raw syscalls, linked with -nostdlib -static -no-pie. It builds clean with no undefined symbols, but ./hexd -v < /etc/hostname segfaults before the first note() output.
Under gdb the fault is at the very top of hexd_main, on a load through %fs that I didn't write, fault address 0x28. Nothing else has run. With -fno-stack-protector it's fine.
I defined the two symbols I thought the protector wanted:
unsigned long __stack_chk_guard = 0x595e9fbd94fda766UL;
__attribute__((noreturn))
void __stack_chk_fail(void) { /* write to fd 2, sys_exit(134) */ }
CFLAGS = -std=c11 -O2 -Wall -Wextra -ffreestanding -fno-pic -fno-asynchronous-unwind-tables -fstack-protector-strong
Why is the compiler reading %fs at all, when the guard is sitting right there as a plain global? Stack alignment in _start is right, and -mno-red-zone changed nothing. Do I have to set up the thread pointer myself, with prctl and ARCH_SET_FS, before calling anything?