authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-09 22:41:38+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-10 09:38:57+02:00
log86e5bbffd757c211c062acef6c244ec94f5db668
tree917aa9d23ec295bc0461bca4a8319b46f42a1dc3
parentc9a3c945dbc8d431fa5bdaf672401c312ead480f

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.

2 files changed, 21 insertions(+), 4 deletions(-)

deps/lld/COFF/DriverUtils.cpp+12-4
......@@ -638,10 +638,18 @@ void fixupExports() {
638638
639639 if (config->killAt && config->machine == I386) {
640640 for (Export &e : config->exports) {
641 e.name = killAt(e.name, true);
642 e.exportName = killAt(e.exportName, false);
643 e.extName = killAt(e.extName, true);
644 e.symbolName = killAt(e.symbolName, true);
641 if (!e.name.empty() && e.name[0] == '?')
642 continue;
643 e.symbolName = e.name;
644 // Trim off the trailing decoration. Symbols will always have a
645 // starting prefix here (either _ for cdecl/stdcall, @ for fastcall
646 // or ? for C++ functions). Vectorcall functions won't have any
647 // fixed prefix, but the function base name will still be at least
648 // one char.
649 e.name = e.name.substr(0, e.name.find('@', 1));
650 // By making sure E.SymbolName != E.Name for decorated symbols,
651 // writeImportLibrary writes these symbols with the type
652 // IMPORT_NAME_UNDECORATE.
645653 }
646654 }
647655
src/link.cpp+9
......@@ -2057,10 +2057,19 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi
20572057 args.resize(0);
20582058 args.append("link");
20592059 coff_append_machine_arg(parent, &args);
2060 args.append("-lldmingw");
2061 args.append("-kill-at");
20602062
20612063 args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_final_path))));
20622064 args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(lib_final_path))));
20632065
2066 if (parent->verbose_link) {
2067 for (size_t i = 0; i < args.length; i += 1) {
2068 fprintf(stderr, "%s ", args.at(i));
2069 }
2070 fprintf(stderr, "\n");
2071 }
2072
20642073 Buf diag = BUF_INIT;
20652074 ZigLLVM_ObjectFormatType target_ofmt = target_object_format(parent->zig_target);
20662075 if (!zig_lld_link(target_ofmt, args.items, args.length, &diag)) {