diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-18 20:03:23 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-18 20:03:23 -0400 |
| commit | a581f4f0e29c14cc7faa54d9a2d4f7458a734fe4 (patch) | |
| tree | 18c0a93af431ab847b3998c467635b3e6465da47 /src/main.cpp | |
| parent | db0e188f0e54fc5bdf5001d0f76b0af145f8473a (diff) | |
| parent | 1b801bdbae2928d6b0ab5897d2e604fb3f87b3c4 (diff) | |
| download | zig-a581f4f0e29c14cc7faa54d9a2d4f7458a734fe4.tar.gz zig-a581f4f0e29c14cc7faa54d9a2d4f7458a734fe4.zip | |
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/src/main.cpp b/src/main.cpp index bf05bb281d..f58a00209a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,8 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { " --cache [auto|off|on] build in cache, print output path to stdout\n" " --color [auto|off|on] enable or disable colored error messages\n" " --disable-gen-h do not generate a C header file (.h)\n" - " --disable-pic disable Position Independent Code for libraries\n" + " --disable-pic disable Position Independent Code\n" + " --enable-pic enable Position Independent Code\n" " --disable-valgrind omit valgrind client requests in debug builds\n" " --enable-valgrind include valgrind client requests release builds\n" " --emit [asm|bin|llvm-ir] emit a specific file format as compilation output\n" @@ -67,7 +68,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { " --release-safe build with optimizations on and safety on\n" " --release-small build with size optimizations on and safety off\n" " --single-threaded source may assume it is only used single-threaded\n" - " --static output will be statically linked\n" + " -dynamic create a shared library (.so; .dll; .dylib)\n" " --strip exclude debug symbols\n" " -target [name] <arch><sub>-<os>-<abi> see the targets command\n" " --verbose-tokenize enable compiler debug output for tokenization\n" @@ -397,7 +398,7 @@ int main(int argc, char **argv) { const char *in_file = nullptr; Buf *output_dir = nullptr; bool strip = false; - bool is_static = false; + bool is_dynamic = false; OutType out_type = OutTypeUnknown; const char *out_name = nullptr; bool verbose_tokenize = false; @@ -416,6 +417,7 @@ int main(int argc, char **argv) { ZigList<const char *> link_libs = {0}; ZigList<const char *> forbidden_link_libs = {0}; ZigList<const char *> frameworks = {0}; + bool have_libc = false; const char *target_string = nullptr; bool rdynamic = false; const char *mmacosx_version_min = nullptr; @@ -432,7 +434,6 @@ int main(int argc, char **argv) { size_t ver_minor = 0; size_t ver_patch = 0; bool timing_info = false; - bool disable_pic = false; const char *cache_dir = nullptr; CliPkg *cur_pkg = allocate<CliPkg>(1); BuildMode build_mode = BuildModeDebug; @@ -445,6 +446,7 @@ int main(int argc, char **argv) { Buf *override_std_dir = nullptr; Buf *main_pkg_path = nullptr; ValgrindSupport valgrind_support = ValgrindSupportAuto; + WantPIC want_pic = WantPICAuto; ZigList<const char *> llvm_argv = {0}; llvm_argv.append("zig (LLVM option parsing)"); @@ -620,8 +622,8 @@ int main(int argc, char **argv) { } } else if (strcmp(arg, "--strip") == 0) { strip = true; - } else if (strcmp(arg, "--static") == 0) { - is_static = true; + } else if (strcmp(arg, "-dynamic") == 0) { + is_dynamic = true; } else if (strcmp(arg, "--verbose-tokenize") == 0) { verbose_tokenize = true; } else if (strcmp(arg, "--verbose-ast") == 0) { @@ -642,12 +644,14 @@ int main(int argc, char **argv) { each_lib_rpath = true; } else if (strcmp(arg, "-ftime-report") == 0) { timing_info = true; - } else if (strcmp(arg, "--disable-pic") == 0) { - disable_pic = true; } else if (strcmp(arg, "--enable-valgrind") == 0) { valgrind_support = ValgrindSupportEnabled; } else if (strcmp(arg, "--disable-valgrind") == 0) { valgrind_support = ValgrindSupportDisabled; + } else if (strcmp(arg, "--enable-pic") == 0) { + want_pic = WantPICEnabled; + } else if (strcmp(arg, "--disable-pic") == 0) { + want_pic = WantPICDisabled; } else if (strcmp(arg, "--system-linker-hack") == 0) { system_linker_hack = true; } else if (strcmp(arg, "--single-threaded") == 0) { @@ -742,6 +746,8 @@ int main(int argc, char **argv) { } else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) { lib_dirs.append(argv[i]); } else if (strcmp(arg, "--library") == 0) { + if (strcmp(argv[i], "c") == 0) + have_libc = true; link_libs.append(argv[i]); } else if (strcmp(arg, "--forbid-library") == 0) { forbidden_link_libs.append(argv[i]); @@ -904,12 +910,24 @@ int main(int argc, char **argv) { } if (output_dir != nullptr && enable_cache == CacheOptOn) { - fprintf(stderr, "The --output-dir argument is incompatible with --cache on.\n"); + fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n"); + return print_error_usage(arg0); + } + + if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) { + Buf triple_buf = BUF_INIT; + get_target_triple(&triple_buf, &target); + fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&triple_buf)); return print_error_usage(arg0); } if (emit_file_type != EmitFileTypeBinary && in_file == nullptr) { - fprintf(stderr, "A root source file is required when using --emit asm or --emit llvm-ir"); + fprintf(stderr, "A root source file is required when using `--emit asm` or `--emit llvm-ir`\n"); + return print_error_usage(arg0); + } + + if (out_type != OutTypeLib && is_dynamic) { + fprintf(stderr, "`-dynamic` may only be specified with `build-lib`.\n"); return print_error_usage(arg0); } @@ -936,6 +954,7 @@ int main(int argc, char **argv) { CodeGen *g = codegen_create(main_pkg_path, nullptr, &target, out_type, build_mode, get_zig_lib_dir(), override_std_dir, nullptr, nullptr); g->valgrind_support = valgrind_support; + g->want_pic = want_pic; g->is_single_threaded = is_single_threaded; Buf *builtin_source = codegen_generate_builtin_source(g); if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) { @@ -1027,16 +1046,9 @@ int main(int argc, char **argv) { get_zig_lib_dir(), override_std_dir, libc, cache_dir_buf); if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2); g->valgrind_support = valgrind_support; + g->want_pic = want_pic; g->subsystem = subsystem; - if (disable_pic) { - if (out_type != OutTypeLib || !is_static) { - fprintf(stderr, "--disable-pic only applies to static libraries"); - return EXIT_FAILURE; - } - g->disable_pic = true; - } - g->enable_time_report = timing_info; codegen_set_out_name(g, buf_out_name); codegen_set_lib_version(g, ver_major, ver_minor, ver_patch); @@ -1049,7 +1061,7 @@ int main(int argc, char **argv) { codegen_set_clang_argv(g, clang_argv.items, clang_argv.length); codegen_set_strip(g, strip); - g->is_static = is_static; + g->is_dynamic = is_dynamic; g->dynamic_linker_path = dynamic_linker; g->verbose_tokenize = verbose_tokenize; g->verbose_ast = verbose_ast; |
