Binaries compiled with any optization model plus -fstack-protector-strong crash with segmentation on llvm12 and later due to bad pointer to "__stack_chk_guard" . This is known to affect powerpc64 (both BE and LE) on FreeBSD 13 and later.
Source of regression was traced to 2518433f861fcb877d0a7bdd9aec1aec1f77505a but it's not clear that this commit is the "real root cause", it probably uncovered a bug in PowerPC64 backend since other platforms generate a working binary. In any case on FreeBSD the "__stack_chk_guard" symbol is defined on external DSO (libc.so.7), so make sense not marking it as dso_local..
Linux doesn't follow the same path since it uses a different approach (LOAD_STACK_GUARD)
*Reported in bugzilla: https://bugs.llvm.org/show_bug.cgi?id=51590
*Similar patch was merged to FreeBSD source tree: https://cgit.freebsd.org/src/commit/?h=stable/13&id=e8e5d75e6a9676e76c3bfd6d1d52561ffbb40846
Test case:
int main(int argc, char *argv[]) { char name[10]; if (ttyname_r(0, name, 10)) err(1, "capsicum"); return 0; };
build parameters:
-target powerpc64-unknown-freebsd13 -O2 -fstack-protector-strong
Obviously fix the formatting, but otherwise this looks like the right fix to me.