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 {
10611061 LLVMZigDICompileUnit *compile_unit;
10621062
10631063 ZigList<Buf *> lib_search_paths;
1064 ZigList<Buf *> link_libs;
10641065
10651066 // reminder: hash tables must be initialized before use
1066 HashMap<Buf *, bool, buf_hash, buf_eql_buf> link_table;
10671067 HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
10681068 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
10691069 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table;
src/codegen.cpp+2-2
......@@ -24,7 +24,6 @@
2424
2525CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {
2626 CodeGen *g = allocate<CodeGen>(1);
27 g->link_table.init(32);
2827 g->import_table.init(32);
2928 g->builtin_fn_table.init(32);
3029 g->primitive_type_table.init(32);
......@@ -3831,9 +3830,10 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *abs_full_path,
38313830 if (buf_eql_str(name, "version")) {
38323831 set_root_export_version(g, param, directive_node);
38333832 } else if (buf_eql_str(name, "link")) {
3834 g->link_table.put(param, true);
38353833 if (buf_eql_str(param, "c")) {
38363834 g->link_libc = true;
3835 } else {
3836 g->link_libs.append(param);
38373837 }
38383838 } else {
38393839 add_node_error(g, directive_node,
src/link.cpp+10-11
......@@ -210,17 +210,10 @@ static void construct_linker_job_linux(LinkJob *lj) {
210210 lj->args.append(buf_ptr(compiler_rt_o_path));
211211 }
212212
213 auto it = g->link_table.entry_iterator();
214 for (;;) {
215 auto *entry = it.next();
216 if (!entry)
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 }
213 for (int i = 0; i < g->link_libs.length; i += 1) {
214 Buf *link_lib = g->link_libs.at(i);
215 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
216 lj->args.append(buf_ptr(arg));
224217 }
225218
226219
......@@ -333,6 +326,12 @@ static void construct_linker_job_mingw(LinkJob *lj) {
333326
334327 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
336335 if (g->link_libc) {
337336 if (g->is_static) {
338337 lj->args.append("--start-group");