From e4d595a8ba2e4466dc29bec7bc90a04420b34d4d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 4 Apr 2019 01:08:26 -0400 Subject: fix thread local variables for non- position independent code This fixes comes thanks to Rich Felker from the musl libc project, who gave me this crucial information: "to satisfy the abi, your init code has to write the same value to that memory location as the value passed to the [arch_prctl] syscall" This commit also changes the rules for when to build statically by default. When building objects and static libraries, position independent code is disabled if no libraries will be dynamically linked and the target does not require position independent code. closes #2063 --- src/codegen.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 5573346452..cf8af9664f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7314,17 +7314,14 @@ static bool detect_dynamic_link(CodeGen *g) { return false; if (target_requires_pic(g->zig_target, g->libc_link_lib != nullptr)) return true; - if (g->out_type == OutTypeExe) { - // If there are no dynamic libraries then we can disable PIC - for (size_t i = 0; i < g->link_libs_list.length; i += 1) { - LinkLib *link_lib = g->link_libs_list.at(i); - if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) - continue; - return true; - } - return false; + // If there are no dynamic libraries then we can disable PIC + for (size_t i = 0; i < g->link_libs_list.length; i += 1) { + LinkLib *link_lib = g->link_libs_list.at(i); + if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) + continue; + return true; } - return true; + return false; } static bool detect_pic(CodeGen *g) { -- cgit v1.2.3