authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 23:03:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 23:03:16-07:00
log5771bd805ee48aca5d56088fb8a1449bb7c3760d
treeaa78925c06bbcf47cca8b1fb3a6e3aeb220cb931
parent1141e4f5b262f7490fe554cd4334ec6b1c886c5f

respect link order in source code


3 files changed, 13 insertions(+), 14 deletions(-)

src/all_types.hpp+1-1
...@@ -1061,9 +1061,9 @@ struct CodeGen {...@@ -1061,9 +1061,9 @@ struct CodeGen {
1061 LLVMZigDICompileUnit *compile_unit;1061 LLVMZigDICompileUnit *compile_unit;
10621062
1063 ZigList<Buf *> lib_search_paths;1063 ZigList<Buf *> lib_search_paths;
1064 ZigList<Buf *> link_libs;
10641065
1065 // reminder: hash tables must be initialized before use1066 // reminder: hash tables must be initialized before use
1066 HashMap<Buf *, bool, buf_hash, buf_eql_buf> link_table;
1067 HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;1067 HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
1068 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;1068 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
1069 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table;1069 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table;
src/codegen.cpp+2-2
...@@ -24,7 +24,6 @@...@@ -24,7 +24,6 @@
2424
25CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {25CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {
26 CodeGen *g = allocate<CodeGen>(1);26 CodeGen *g = allocate<CodeGen>(1);
27 g->link_table.init(32);
28 g->import_table.init(32);27 g->import_table.init(32);
29 g->builtin_fn_table.init(32);28 g->builtin_fn_table.init(32);
30 g->primitive_type_table.init(32);29 g->primitive_type_table.init(32);
...@@ -3831,9 +3830,10 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *abs_full_path,...@@ -3831,9 +3830,10 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *abs_full_path,
3831 if (buf_eql_str(name, "version")) {3830 if (buf_eql_str(name, "version")) {
3832 set_root_export_version(g, param, directive_node);3831 set_root_export_version(g, param, directive_node);
3833 } else if (buf_eql_str(name, "link")) {3832 } else if (buf_eql_str(name, "link")) {
3834 g->link_table.put(param, true);
3835 if (buf_eql_str(param, "c")) {3833 if (buf_eql_str(param, "c")) {
3836 g->link_libc = true;3834 g->link_libc = true;
3835 } else {
3836 g->link_libs.append(param);
3837 }3837 }
3838 } else {3838 } else {
3839 add_node_error(g, directive_node,3839 add_node_error(g, directive_node,
src/link.cpp+10-11
...@@ -210,17 +210,10 @@ static void construct_linker_job_linux(LinkJob *lj) {...@@ -210,17 +210,10 @@ static void construct_linker_job_linux(LinkJob *lj) {
210 lj->args.append(buf_ptr(compiler_rt_o_path));210 lj->args.append(buf_ptr(compiler_rt_o_path));
211 }211 }
212212
213 auto it = g->link_table.entry_iterator();213 for (int i = 0; i < g->link_libs.length; i += 1) {
214 for (;;) {214 Buf *link_lib = g->link_libs.at(i);
215 auto *entry = it.next();215 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
216 if (!entry)216 lj->args.append(buf_ptr(arg));
217 break;
218
219 // we handle libc explicitly, don't do it here
220 if (!buf_eql_str(entry->key, "c")) {
221 Buf *arg = buf_sprintf("-l%s", buf_ptr(entry->key));
222 lj->args.append(buf_ptr(arg));
223 }
224 }217 }
225218
226219
...@@ -333,6 +326,12 @@ static void construct_linker_job_mingw(LinkJob *lj) {...@@ -333,6 +326,12 @@ static void construct_linker_job_mingw(LinkJob *lj) {
333326
334 lj->args.append((const char *)buf_ptr(&lj->out_file_o));327 lj->args.append((const char *)buf_ptr(&lj->out_file_o));
335328
329 for (int i = 0; i < g->link_libs.length; i += 1) {
330 Buf *link_lib = g->link_libs.at(i);
331 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
332 lj->args.append(buf_ptr(arg));
333 }
334
336 if (g->link_libc) {335 if (g->link_libc) {
337 if (g->is_static) {336 if (g->is_static) {
338 lj->args.append("--start-group");337 lj->args.append("--start-group");