From e18170ee0bf32996635397e8e919a14a21c88b56 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 8 Feb 2016 22:11:09 -0700 Subject: [PATCH] support overriding the dynamic linker argument to ld --- src/all_types.hpp | 1 + src/codegen.cpp | 16 +++++++++++----- src/codegen.hpp | 1 + src/main.cpp | 6 ++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index c247e826693102a17db47ad76e8d19866aec7697..e831facfc835b3c64c2c53d4ba234aa0da186488 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1106,6 +1106,7 @@ struct CodeGen { Buf *libc_lib_dir; Buf *libc_static_lib_dir; Buf *libc_include_dir; + Buf *dynamic_linker; bool is_release_build; bool is_test_build; LLVMTargetMachineRef target_machine; diff --git a/src/codegen.cpp b/src/codegen.cpp index 97c528bc81a3755f37a93ac70d75cb93673b113d..d1a57a82bc0b54206df7f2785d3c9e610b7c5ea4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -33,6 +33,9 @@ CodeGen *codegen_create(Buf *root_source_dir) { g->is_test_build = false; g->root_source_dir = root_source_dir; g->error_value_count = 1; + if (ZIG_DYNAMIC_LINKER) { + g->dynamic_linker = buf_create_from_str(ZIG_DYNAMIC_LINKER); + } g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR); g->libc_static_lib_dir = buf_create_from_str(ZIG_LIBC_STATIC_LIB_DIR); @@ -90,6 +93,10 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { g->libc_include_dir = libc_include_dir; } +void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker) { + g->dynamic_linker = dynamic_linker; +} + void codegen_add_lib_dir(CodeGen *g, const char *dir) { g->lib_dirs.append(dir); } @@ -4157,13 +4164,12 @@ void codegen_link(CodeGen *g, const char *out_file) { args.append(buf_ptr(g->libc_static_lib_dir)); } - // TODO don't pass this parameter unless linking with libc - if (ZIG_DYNAMIC_LINKER[0] == 0) { + if (g->dynamic_linker) { + args.append("-dynamic-linker"); + args.append(buf_ptr(g->dynamic_linker)); + } else { args.append("-dynamic-linker"); args.append(buf_ptr(get_dynamic_linker(g->target_machine))); - } else { - args.append("-dynamic-linker"); - args.append(ZIG_DYNAMIC_LINKER); } if (g->out_type == OutTypeLib) { diff --git a/src/codegen.hpp b/src/codegen.hpp index 6fffaf06bd42dee020a043018845f13e6cc8370f..64053e04ca96752567535932081d29ec17b80a37 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -28,6 +28,7 @@ void codegen_set_out_name(CodeGen *codegen, Buf *out_name); void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir); void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); +void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); void codegen_add_lib_dir(CodeGen *codegen, const char *dir); void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); diff --git a/src/main.cpp b/src/main.cpp index 2d10cbb6f5ec04c3f7078be5b493c0c0f16377c5..36aa3497d314daa17e6dba47042e0be57bd45ae2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ static int usage(const char *arg0) { " --libc-lib-dir [path] set the C compiler data path\n" " --libc-static-lib-dir [path] set the C compiler data path\n" " --libc-include-dir [path] set the C compiler data path\n" + " --dynamic-linker [path] set the path to ld.so\n" " -isystem [dir] add additional search path for other .h files\n" " -dirafter [dir] same as -isystem but do it last\n" " --library-path [dir] add a directory to the library search path\n" @@ -62,6 +63,7 @@ int main(int argc, char **argv) { const char *libc_lib_dir = nullptr; const char *libc_static_lib_dir = nullptr; const char *libc_include_dir = nullptr; + const char *dynamic_linker = nullptr; ZigList clang_argv = {0}; ZigList lib_dirs = {0}; int err; @@ -114,6 +116,8 @@ int main(int argc, char **argv) { libc_static_lib_dir = argv[i]; } else if (strcmp(arg, "--libc-include-dir") == 0) { libc_include_dir = argv[i]; + } else if (strcmp(arg, "--dynamic-linker") == 0) { + dynamic_linker = argv[i]; } else if (strcmp(arg, "-isystem") == 0) { clang_argv.append("-isystem"); clang_argv.append(argv[i]); @@ -210,6 +214,8 @@ int main(int argc, char **argv) { codegen_set_libc_static_lib_dir(g, buf_create_from_str(libc_static_lib_dir)); if (libc_include_dir) codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); + if (dynamic_linker) + codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); codegen_set_verbose(g, verbose); codegen_set_errmsg_color(g, color); -- 2.54.0