aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Marie <semarie@online.fr>2022-02-28 15:24:22 +0000
committerSébastien Marie <semarie@online.fr>2022-02-28 15:24:22 +0000
commitf76f70c7cf369a7e247a52e0c36da2fbe8d960c6 (patch)
treea743d4960eeb6de964f854b4c3fc5e2532dd37fc /src
parentdd9843aa2102ba2df42e04d86680e03a27fa45f8 (diff)
openbsd: defaults to PIE executable
OpenBSD uses PIE code by default to allow the system to load the binary at a random location. don't pass -no-pie to preserve this behaviour, and build objects with -fPIC (LLVMRelocPIC).
Diffstat (limited to 'src')
-rw-r--r--src/llvm_backend.cpp5
-rw-r--r--src/main.cpp3
2 files changed, 7 insertions, 1 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 52c46cadc..3b11f95a2 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -1295,6 +1295,11 @@ void lb_generate_code(lbGenerator *gen) {
reloc_mode = LLVMRelocPIC;
}
+ if (build_context.metrics.os == TargetOs_openbsd) {
+ // Always use PIC for OpenBSD: it defaults to PIE
+ reloc_mode = LLVMRelocPIC;
+ }
+
for_array(i, gen->modules.entries) {
target_machines[i] = LLVMCreateTargetMachine(
target, target_triple, llvm_cpu,
diff --git a/src/main.cpp b/src/main.cpp
index c738b860d..f8a3e6f85 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -463,7 +463,8 @@ i32 linker_stage(lbGenerator *gen) {
#endif
link_settings = gb_string_appendc(link_settings, "-Wl,-init,'_odin_entry_point' ");
link_settings = gb_string_appendc(link_settings, "-Wl,-fini,'_odin_exit_point' ");
- } else {
+ } else if (build_context.metrics.os != TargetOs_openbsd) {
+ // OpenBSD defaults to PIE executable. do not pass -no-pie for it.
link_settings = gb_string_appendc(link_settings, "-no-pie ");
}
if (build_context.out_filepath.len > 0) {