authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-13 23:15:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-13 23:15:34-04:00
log20c36949e1d82e9e8790ca51a0f7713f6e853ff0
tree0c8f23358aeb2ba28083ddbf617df1ed90a9528a
parent5d2edac12dc9eec626977a5bf9b0630504b28c15
signaturelock-open Commit is signed but in an unrecognized format.

fix target_requires_pic and reloc_mode

disable failing thread local variable test. see #2063

6 files changed, 27 insertions(+), 7 deletions(-)

src/codegen.cpp+10-3
......@@ -7288,7 +7288,7 @@ static bool detect_dynamic_link(CodeGen *g) {
72887288 return true;
72897289 if (g->zig_target->os == OsFreestanding)
72907290 return false;
7291 if (target_requires_pic(g->zig_target))
7291 if (target_requires_pic(g->zig_target, g->libc_link_lib != nullptr))
72927292 return true;
72937293 if (g->out_type == OutTypeExe) {
72947294 // If there are no dynamic libraries then we can disable PIC
......@@ -7304,7 +7304,7 @@ static bool detect_dynamic_link(CodeGen *g) {
73047304}
73057305
73067306static bool detect_pic(CodeGen *g) {
7307 if (target_requires_pic(g->zig_target))
7307 if (target_requires_pic(g->zig_target, g->libc_link_lib != nullptr))
73087308 return true;
73097309 switch (g->want_pic) {
73107310 case WantPICDisabled:
......@@ -7848,7 +7848,14 @@ static void init(CodeGen *g) {
78487848 bool is_optimized = g->build_mode != BuildModeDebug;
78497849 LLVMCodeGenOptLevel opt_level = is_optimized ? LLVMCodeGenLevelAggressive : LLVMCodeGenLevelNone;
78507850
7851 LLVMRelocMode reloc_mode = g->have_pic ? LLVMRelocPIC: LLVMRelocStatic;
7851 LLVMRelocMode reloc_mode;
7852 if (g->have_pic) {
7853 reloc_mode = LLVMRelocPIC;
7854 } else if (g->have_dynamic_link) {
7855 reloc_mode = LLVMRelocDynamicNoPic;
7856 } else {
7857 reloc_mode = LLVMRelocStatic;
7858 }
78527859
78537860 const char *target_specific_cpu_args;
78547861 const char *target_specific_features;
src/main.cpp+4-1
......@@ -417,6 +417,7 @@ int main(int argc, char **argv) {
417417 ZigList<const char *> link_libs = {0};
418418 ZigList<const char *> forbidden_link_libs = {0};
419419 ZigList<const char *> frameworks = {0};
420 bool have_libc = false;
420421 const char *target_string = nullptr;
421422 bool rdynamic = false;
422423 const char *mmacosx_version_min = nullptr;
......@@ -745,6 +746,8 @@ int main(int argc, char **argv) {
745746 } else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) {
746747 lib_dirs.append(argv[i]);
747748 } else if (strcmp(arg, "--library") == 0) {
749 if (strcmp(argv[i], "c") == 0)
750 have_libc = true;
748751 link_libs.append(argv[i]);
749752 } else if (strcmp(arg, "--forbid-library") == 0) {
750753 forbidden_link_libs.append(argv[i]);
......@@ -911,7 +914,7 @@ int main(int argc, char **argv) {
911914 return print_error_usage(arg0);
912915 }
913916
914 if (target_requires_pic(&target) && want_pic == WantPICDisabled) {
917 if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) {
915918 Buf triple_buf = BUF_INIT;
916919 get_target_triple(&triple_buf, &target);
917920 fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&triple_buf));
src/target.cpp+3-2
......@@ -1300,9 +1300,10 @@ bool target_supports_fpic(const ZigTarget *target) {
13001300 return target->os != OsWindows;
13011301}
13021302
1303bool target_requires_pic(const ZigTarget *target) {
1303bool target_requires_pic(const ZigTarget *target, bool linking_libc) {
13041304 // This function returns whether non-pic code is completely invalid on the given target.
1305 return target->os == OsWindows || target_os_requires_libc(target->os) || target_is_glibc(target);
1305 return target->os == OsWindows || target_os_requires_libc(target->os) ||
1306 (linking_libc && target_is_glibc(target));
13061307}
13071308
13081309bool target_is_glibc(const ZigTarget *target) {
src/target.hpp+1-1
......@@ -161,7 +161,7 @@ bool target_can_build_libc(const ZigTarget *target);
161161const char *target_libc_generic_name(const ZigTarget *target);
162162bool target_is_libc_lib_name(const ZigTarget *target, const char *name);
163163bool target_supports_fpic(const ZigTarget *target);
164bool target_requires_pic(const ZigTarget *target);
164bool target_requires_pic(const ZigTarget *target, bool linking_libc);
165165bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi);
166166bool target_abi_is_musl(ZigLLVM_EnvironmentType abi);
167167bool target_is_glibc(const ZigTarget *target);
std/os/test.zig+4
......@@ -108,6 +108,10 @@ test "AtomicFile" {
108108
109109test "thread local storage" {
110110 if (builtin.single_threaded) return error.SkipZigTest;
111 if (!builtin.position_independent_code and !builtin.link_libc) {
112 // TODO https://github.com/ziglang/zig/issues/2063
113 return error.SkipZigTest;
114 }
111115 const thread1 = try std.os.spawnThread({}, testTls);
112116 const thread2 = try std.os.spawnThread({}, testTls);
113117 testTls({});
test/stage1/behavior/misc.zig+5
......@@ -688,6 +688,11 @@ fn getNull() ?*i32 {
688688}
689689
690690test "thread local variable" {
691 if (!builtin.position_independent_code and !builtin.link_libc) {
692 // TODO https://github.com/ziglang/zig/issues/2063
693 return error.SkipZigTest;
694 }
695
691696 const S = struct {
692697 threadlocal var t: i32 = 1234;
693698 };