Browse Source

Merge pull request #1565 from semarie/openbsd-pie

openbsd: defaults to PIE executable
gingerBill 3 years ago
parent
commit
a70dde34da
2 changed files with 7 additions and 1 deletions
  1. 5 0
      src/llvm_backend.cpp
  2. 2 1
      src/main.cpp

+ 5 - 0
src/llvm_backend.cpp

@@ -1295,6 +1295,11 @@ void lb_generate_code(lbGenerator *gen) {
 		reloc_mode = LLVMRelocPIC;
 		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) {
 	for_array(i, gen->modules.entries) {
 		target_machines[i] = LLVMCreateTargetMachine(
 		target_machines[i] = LLVMCreateTargetMachine(
 			target, target_triple, llvm_cpu,
 			target, target_triple, llvm_cpu,

+ 2 - 1
src/main.cpp

@@ -463,7 +463,8 @@ i32 linker_stage(lbGenerator *gen) {
 			#endif
 			#endif
 			link_settings = gb_string_appendc(link_settings, "-Wl,-init,'_odin_entry_point' ");
 			link_settings = gb_string_appendc(link_settings, "-Wl,-init,'_odin_entry_point' ");
 			link_settings = gb_string_appendc(link_settings, "-Wl,-fini,'_odin_exit_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 ");
 			link_settings = gb_string_appendc(link_settings, "-no-pie ");
 		}
 		}
 		if (build_context.out_filepath.len > 0) {
 		if (build_context.out_filepath.len > 0) {