Merge pull request #6790 from A1029384756/linux_pie

[linux] change default settings to enable pie and full relro
This commit is contained in:
Jeroen van Rijn
2026-06-12 11:21:51 +02:00
committed by GitHub
5 changed files with 49 additions and 11 deletions

View File

@@ -801,7 +801,12 @@ try_cross_linking:;
}
if (build_context.build_mode == BuildMode_Executable && build_context.reloc_mode == RelocMode_PIC) {
// Do not disable PIE, let the linker choose. (most likely you want it enabled)
if (build_context.metrics.os == TargetOs_linux) {
// Linux does not enable PIE by default but required for ASLR
link_settings = gb_string_appendc(link_settings, "-pie ");
} else {
// Do not disable PIE, let the linker choose. (most likely you want it enabled)
}
} else if (build_context.build_mode != BuildMode_DynamicLibrary) {
if (build_context.metrics.os != TargetOs_openbsd
&& build_context.metrics.arch != TargetArch_riscv64
@@ -919,6 +924,9 @@ try_cross_linking:;
// need to pass -z nobtcfi in order to allow the resulting program to run under
// OpenBSD 7.4 and newer. Once support is added at compile time, this can be dropped.
platform_lib_str = gb_string_appendc(platform_lib_str, "-Wl,-z,nobtcfi ");
} else if (build_context.metrics.os == TargetOs_linux) {
// required for RELRO
platform_lib_str = gb_string_appendc(platform_lib_str, "-Wl,-z,now -Wl,-z,relro ");
}
if (is_android) {