Skip to content

Commit e6475fe

Browse files
authored
Merge pull request #4449 from 0dminnimda/add-pie
Link as PIE for PIC by default
2 parents a0b35f6 + 5e308ce commit e6475fe

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/build_settings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ struct BuildContext {
453453
bool no_threaded_checker;
454454

455455
bool show_debug_messages;
456-
456+
457457
bool copy_file_contents;
458458

459459
bool no_rtti;

src/linker.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,18 @@ gb_internal i32 linker_stage(LinkerData *gen) {
605605
link_settings = gb_string_appendc(link_settings, "-Wl,-fini,'_odin_exit_point' ");
606606
}
607607

608-
} else if (build_context.metrics.os != TargetOs_openbsd && build_context.metrics.os != TargetOs_haiku && build_context.metrics.arch != TargetArch_riscv64) {
609-
// OpenBSD and Haiku default to PIE executable. do not pass -no-pie for it.
610-
link_settings = gb_string_appendc(link_settings, "-no-pie ");
608+
}
609+
610+
if (build_context.build_mode == BuildMode_Executable && build_context.reloc_mode == RelocMode_PIC) {
611+
// Do not disable PIE, let the linker choose. (most likely you want it enabled)
612+
} else if (build_context.build_mode != BuildMode_DynamicLibrary) {
613+
if (build_context.metrics.os != TargetOs_openbsd
614+
&& build_context.metrics.os != TargetOs_haiku
615+
&& build_context.metrics.arch != TargetArch_riscv64
616+
) {
617+
// OpenBSD and Haiku default to PIE executable. do not pass -no-pie for it.
618+
link_settings = gb_string_appendc(link_settings, "-no-pie ");
619+
}
611620
}
612621

613622
gbString platform_lib_str = gb_string_make(heap_allocator(), "");

0 commit comments

Comments
 (0)