| author | |
| committer | |
| log | 86e5bbffd757c211c062acef6c244ec94f5db668 |
| tree | 917aa9d23ec295bc0461bca4a8319b46f42a1dc3 |
| parent | c9a3c945dbc8d431fa5bdaf672401c312ead480f |
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() { |
| 638 | 638 | |
| 639 | 639 | if (config->killAt && config->machine == I386) { |
| 640 | 640 | 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. | |
| 645 | 653 | } |
| 646 | 654 | } |
| 647 | 655 |
src/link.cpp+9| ... | ... | @@ -2057,10 +2057,19 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi |
| 2057 | 2057 | args.resize(0); |
| 2058 | 2058 | args.append("link"); |
| 2059 | 2059 | coff_append_machine_arg(parent, &args); |
| 2060 | args.append("-lldmingw"); | |
| 2061 | args.append("-kill-at"); | |
| 2060 | 2062 | |
| 2061 | 2063 | args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_final_path)))); |
| 2062 | 2064 | args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(lib_final_path)))); |
| 2063 | 2065 | |
| 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 | ||
| 2064 | 2073 | Buf diag = BUF_INIT; |
| 2065 | 2074 | ZigLLVM_ObjectFormatType target_ofmt = target_object_format(parent->zig_target); |
| 2066 | 2075 | if (!zig_lld_link(target_ofmt, args.items, args.length, &diag)) { |