Patch lld to have a more sensible kill-at implementation

Lift some code from llvm-dlltool, the lld code is meant to follow what
gnu ld does but that's not much useful for our purposes.

Also use the `--kill-at` option when generating the .lib files out of
mingw's .def files: this way our building process closely matches the
one use by the upstream and now finally generates files that allow both
C code and Zig code to link.
This commit is contained in:
LemonBoy
2019-10-09 22:41:38 +02:00
parent c9a3c945db
commit 86e5bbffd7
2 changed files with 21 additions and 4 deletions

View File

@@ -2057,10 +2057,19 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi
args.resize(0);
args.append("link");
coff_append_machine_arg(parent, &args);
args.append("-lldmingw");
args.append("-kill-at");
args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_final_path))));
args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(lib_final_path))));
if (parent->verbose_link) {
for (size_t i = 0; i < args.length; i += 1) {
fprintf(stderr, "%s ", args.at(i));
}
fprintf(stderr, "\n");
}
Buf diag = BUF_INIT;
ZigLLVM_ObjectFormatType target_ofmt = target_object_format(parent->zig_target);
if (!zig_lld_link(target_ofmt, args.items, args.length, &diag)) {