diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-13 23:03:16 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-02-13 23:03:16 -0700 |
| commit | 5771bd805ee48aca5d56088fb8a1449bb7c3760d (patch) | |
| tree | aa78925c06bbcf47cca8b1fb3a6e3aeb220cb931 /src | |
| parent | 1141e4f5b262f7490fe554cd4334ec6b1c886c5f (diff) | |
| download | zig-5771bd805ee48aca5d56088fb8a1449bb7c3760d.tar.gz zig-5771bd805ee48aca5d56088fb8a1449bb7c3760d.zip | |
respect link order in source code
Diffstat (limited to 'src')
| -rw-r--r-- | src/all_types.hpp | 2 | ||||
| -rw-r--r-- | src/codegen.cpp | 4 | ||||
| -rw-r--r-- | src/link.cpp | 21 |
3 files changed, 13 insertions, 14 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 894be41b2d..07218a40d6 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1061,9 +1061,9 @@ struct CodeGen { LLVMZigDICompileUnit *compile_unit; ZigList<Buf *> lib_search_paths; + ZigList<Buf *> link_libs; // reminder: hash tables must be initialized before use - HashMap<Buf *, bool, buf_hash, buf_eql_buf> link_table; HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table; HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table; HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table; diff --git a/src/codegen.cpp b/src/codegen.cpp index 7cfd699ce4..f7b05bf37b 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -24,7 +24,6 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) { CodeGen *g = allocate<CodeGen>(1); - g->link_table.init(32); g->import_table.init(32); g->builtin_fn_table.init(32); g->primitive_type_table.init(32); @@ -3831,9 +3830,10 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *abs_full_path, if (buf_eql_str(name, "version")) { set_root_export_version(g, param, directive_node); } else if (buf_eql_str(name, "link")) { - g->link_table.put(param, true); if (buf_eql_str(param, "c")) { g->link_libc = true; + } else { + g->link_libs.append(param); } } else { add_node_error(g, directive_node, diff --git a/src/link.cpp b/src/link.cpp index 5d684c46e6..5fbcdfefb7 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -210,17 +210,10 @@ static void construct_linker_job_linux(LinkJob *lj) { lj->args.append(buf_ptr(compiler_rt_o_path)); } - auto it = g->link_table.entry_iterator(); - for (;;) { - auto *entry = it.next(); - if (!entry) - break; - - // we handle libc explicitly, don't do it here - if (!buf_eql_str(entry->key, "c")) { - Buf *arg = buf_sprintf("-l%s", buf_ptr(entry->key)); - lj->args.append(buf_ptr(arg)); - } + for (int i = 0; i < g->link_libs.length; i += 1) { + Buf *link_lib = g->link_libs.at(i); + Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); + lj->args.append(buf_ptr(arg)); } @@ -333,6 +326,12 @@ static void construct_linker_job_mingw(LinkJob *lj) { lj->args.append((const char *)buf_ptr(&lj->out_file_o)); + for (int i = 0; i < g->link_libs.length; i += 1) { + Buf *link_lib = g->link_libs.at(i); + Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); + lj->args.append(buf_ptr(arg)); + } + if (g->link_libc) { if (g->is_static) { lj->args.append("--start-group"); |
