Skip to content

Commit

Permalink
Merge pull request #4449 from 0dminnimda/add-pie
Browse files Browse the repository at this point in the history
Link as PIE for PIC by default
  • Loading branch information
Kelimion authored Nov 4, 2024
2 parents a0b35f6 + 5e308ce commit e6475fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/build_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ struct BuildContext {
bool no_threaded_checker;

bool show_debug_messages;

bool copy_file_contents;

bool no_rtti;
Expand Down
15 changes: 12 additions & 3 deletions src/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "");
Expand Down

0 comments on commit e6475fe

Please sign in to comment.