Merge pull request #4449 from 0dminnimda/add-pie

Link as PIE for PIC by default
This commit is contained in:
Jeroen van Rijn
2024-11-04 14:25:31 +01:00
committed by GitHub
2 changed files with 13 additions and 4 deletions

View File

@@ -453,7 +453,7 @@ struct BuildContext {
bool no_threaded_checker;
bool show_debug_messages;
bool copy_file_contents;
bool no_rtti;

View File

@@ -605,9 +605,18 @@ gb_internal i32 linker_stage(LinkerData *gen) {
link_settings = gb_string_appendc(link_settings, "-Wl,-fini,'_odin_exit_point' ");
}
} else if (build_context.metrics.os != TargetOs_openbsd && build_context.metrics.os != TargetOs_haiku && build_context.metrics.arch != TargetArch_riscv64) {
// OpenBSD and Haiku default to PIE executable. do not pass -no-pie for it.
link_settings = gb_string_appendc(link_settings, "-no-pie ");
}
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)
} else if (build_context.build_mode != BuildMode_DynamicLibrary) {
if (build_context.metrics.os != TargetOs_openbsd
&& build_context.metrics.os != TargetOs_haiku
&& build_context.metrics.arch != TargetArch_riscv64
) {
// OpenBSD and Haiku default to PIE executable. do not pass -no-pie for it.
link_settings = gb_string_appendc(link_settings, "-no-pie ");
}
}
gbString platform_lib_str = gb_string_make(heap_allocator(), "");