aboutsummaryrefslogtreecommitdiff
path: root/src/stage1
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-11-22 17:30:34 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-11-22 17:30:34 -0700
commitc7170e4a5480581db5f30913eebd9ad4f7cd121e (patch)
treefba79b8f4241c94f886e7708d18081e8fc0e31fe /src/stage1
parent98d5bfbd4d21e99363a0a68ef5a0d0104c302ecb (diff)
parentabc717f203060f7ab16d36f2afe681d838b46801 (diff)
downloadzig-c7170e4a5480581db5f30913eebd9ad4f7cd121e.tar.gz
zig-c7170e4a5480581db5f30913eebd9ad4f7cd121e.zip
Support PIE (Position Independent Executables)
Closes #4503 Revives #3960 Merges branch 'pie' into master
Diffstat (limited to 'src/stage1')
-rw-r--r--src/stage1/all_types.hpp1
-rw-r--r--src/stage1/codegen.cpp9
-rw-r--r--src/stage1/stage1.cpp1
-rw-r--r--src/stage1/stage1.h1
4 files changed, 12 insertions, 0 deletions
diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp
index d56bcffff1..957a377b6d 100644
--- a/src/stage1/all_types.hpp
+++ b/src/stage1/all_types.hpp
@@ -2177,6 +2177,7 @@ struct CodeGen {
bool is_test_build;
bool is_single_threaded;
bool have_pic;
+ bool have_pie;
bool link_mode_dynamic;
bool dll_export_fns;
bool have_stack_probing;
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp
index 26fe00228e..d0bb9b4411 100644
--- a/src/stage1/codegen.cpp
+++ b/src/stage1/codegen.cpp
@@ -9043,6 +9043,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents, "pub const have_error_return_tracing = %s;\n", bool_to_str(g->have_err_ret_tracing));
buf_appendf(contents, "pub const valgrind_support = false;\n");
buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));
+ buf_appendf(contents, "pub const position_independent_executable = %s;\n", bool_to_str(g->have_pie));
buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));
buf_appendf(contents, "pub const code_model = CodeModel.default;\n");
@@ -9170,6 +9171,14 @@ static void init(CodeGen *g) {
reloc_mode = LLVMRelocStatic;
}
+ if (g->have_pic) {
+ ZigLLVMSetModulePICLevel(g->module);
+ }
+
+ if (g->have_pie) {
+ ZigLLVMSetModulePIELevel(g->module);
+ }
+
const char *target_specific_cpu_args = "";
const char *target_specific_features = "";
diff --git a/src/stage1/stage1.cpp b/src/stage1/stage1.cpp
index 1034f9ff88..fec6760623 100644
--- a/src/stage1/stage1.cpp
+++ b/src/stage1/stage1.cpp
@@ -89,6 +89,7 @@ void zig_stage1_build_object(struct ZigStage1 *stage1) {
g->link_mode_dynamic = stage1->link_mode_dynamic;
g->dll_export_fns = stage1->dll_export_fns;
g->have_pic = stage1->pic;
+ g->have_pie = stage1->pie;
g->have_stack_probing = stage1->enable_stack_probing;
g->is_single_threaded = stage1->is_single_threaded;
g->valgrind_enabled = stage1->valgrind_enabled;
diff --git a/src/stage1/stage1.h b/src/stage1/stage1.h
index 412118a6fa..0552aa09e0 100644
--- a/src/stage1/stage1.h
+++ b/src/stage1/stage1.h
@@ -177,6 +177,7 @@ struct ZigStage1 {
enum ErrColor err_color;
bool pic;
+ bool pie;
bool link_libc;
bool link_libcpp;
bool strip;