[stack-canaries] fixed platform behavior

This commit is contained in:
A1029384756
2026-06-12 23:27:32 -04:00
parent 2373fabe47
commit 8ccee66157
2 changed files with 31 additions and 12 deletions

View File

@@ -1909,16 +1909,6 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
}
break;
}
} else if (metrics->os == TargetOs_linux) {
if (bc->reloc_mode == RelocMode_Default) {
bc->reloc_mode = RelocMode_PIC;
}
switch (metrics->arch) {
case TargetArch_arm64:
case TargetArch_amd64:
bc->no_plt = LLVM_VERSION_MAJOR >= 19;
break;
}
} else if (metrics->os == TargetOs_openbsd) {
// Always use PIC for OpenBSD: it defaults to PIE
if (bc->reloc_mode == RelocMode_Default) {
@@ -1947,10 +1937,37 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
bc->metrics.target_triplet = str_lit("i686-linux-android");
bc->reloc_mode = RelocMode_PIC;
break;
default:
GB_PANIC("Unknown architecture for -subtarget:android");
}
} else if (metrics->os == TargetOs_linux) {
if (bc->reloc_mode == RelocMode_Default) {
bc->reloc_mode = RelocMode_PIC;
}
switch (metrics->arch) {
case TargetArch_arm64:
case TargetArch_amd64:
bc->no_plt = LLVM_VERSION_MAJOR >= 19;
break;
}
}
if (metrics->os == TargetOs_windows ||
metrics->os == TargetOs_darwin ||
metrics->os == TargetOs_linux ||
metrics->os == TargetOs_freebsd ||
metrics->os == TargetOs_openbsd ||
metrics->os == TargetOs_netbsd) {
if (bc->stack_protector == StackProtector_Default) {
bc->stack_protector = StackProtector_Ssp;
}
} else {
if (bc->stack_protector == StackProtector_Default) {
bc->stack_protector = StackProtector_None;
} else {
gb_printf_err("-stack-protector is not supported on this target\n");
gb_exit(1);
}
}
if (bc->metrics.os == TargetOs_windows) {

View File

@@ -161,13 +161,15 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
}
switch (build_context.stack_protector) {
case StackProtector_Default:
case StackProtector_Ssp:
lb_add_attribute_to_proc(m, p->value, "ssp");
break;
case StackProtector_SspReq:
lb_add_attribute_to_proc(m, p->value, "sspreq");
break;
case StackProtector_SspStrong:
lb_add_attribute_to_proc(m, p->value, "sspstrong");
break;
}
if (build_context.disable_unwind) {