Commit e18170ee0b
Changed files (4)
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;
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(get_dynamic_linker(g->target_machine)));
+ args.append(buf_ptr(g->dynamic_linker));
} else {
args.append("-dynamic-linker");
- args.append(ZIG_DYNAMIC_LINKER);
+ args.append(buf_ptr(get_dynamic_linker(g->target_machine)));
}
if (g->out_type == OutTypeLib) {
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);
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<const char *> clang_argv = {0};
ZigList<const char *> 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);