diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2025-09-30 22:06:36 -0700 |
|---|---|---|
| committer | Ryan Liptak <squeek502@hotmail.com> | 2025-10-03 18:26:05 -0700 |
| commit | e393543e630e29cda88737c85fa0aa19cc40f096 (patch) | |
| tree | 5f9821192e5378f066690c43227cf5207205d9b2 /src/zig_llvm.cpp | |
| parent | 900315a3f3b29ac18945152894fc772e37713619 (diff) | |
| download | zig-e393543e630e29cda88737c85fa0aa19cc40f096.tar.gz zig-e393543e630e29cda88737c85fa0aa19cc40f096.zip | |
Support generating import libraries from mingw .def files without LLVM
For the supported COFF machine types of X64 (x86_64), I386 (x86), ARMNT (thumb), and ARM64 (aarch64), this new Zig implementation results in byte-for-byte identical .lib files when compared to the previous LLVM-backed implementation.
Diffstat (limited to 'src/zig_llvm.cpp')
| -rw-r--r-- | src/zig_llvm.cpp | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 63663518c6..198f8ead15 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -39,9 +39,6 @@ #include <llvm/Passes/StandardInstrumentations.h> #include <llvm/Object/Archive.h> #include <llvm/Object/ArchiveWriter.h> -#include <llvm/Object/COFF.h> -#include <llvm/Object/COFFImportFile.h> -#include <llvm/Object/COFFModuleDefinition.h> #include <llvm/PassRegistry.h> #include <llvm/Support/CommandLine.h> #include <llvm/Support/FileSystem.h> @@ -475,62 +472,6 @@ void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) { cl::ParseCommandLineOptions(argc, argv); } -bool ZigLLVMWriteImportLibrary(const char *def_path, unsigned int coff_machine, - const char *output_lib_path, bool kill_at) -{ - COFF::MachineTypes machine = static_cast<COFF::MachineTypes>(coff_machine); - - auto bufOrErr = MemoryBuffer::getFile(def_path); - if (!bufOrErr) { - return false; - } - - MemoryBuffer& buf = *bufOrErr.get(); - Expected<object::COFFModuleDefinition> def = - object::parseCOFFModuleDefinition(buf, machine, /* MingwDef */ true); - - if (!def) { - return true; - } - - // The exports-juggling code below is ripped from LLVM's DlltoolDriver.cpp - - // If ExtName is set (if the "ExtName = Name" syntax was used), overwrite - // Name with ExtName and clear ExtName. When only creating an import - // library and not linking, the internal name is irrelevant. This avoids - // cases where writeImportLibrary tries to transplant decoration from - // symbol decoration onto ExtName. - for (object::COFFShortExport& E : def->Exports) { - if (!E.ExtName.empty()) { - E.Name = E.ExtName; - E.ExtName.clear(); - } - } - - if (kill_at) { - for (object::COFFShortExport& E : def->Exports) { - if (!E.ImportName.empty() || (!E.Name.empty() && E.Name[0] == '?')) - continue; - if (machine == COFF::IMAGE_FILE_MACHINE_I386) { - // By making sure E.SymbolName != E.Name for decorated symbols, - // writeImportLibrary writes these symbols with the type - // IMPORT_NAME_UNDECORATE. - E.SymbolName = E.Name; - } - // Trim off the trailing decoration. Symbols will always have a - // starting prefix here (either _ for cdecl/stdcall, @ for fastcall - // or ? for C++ functions). Vectorcall functions won't have any - // fixed prefix, but the function base name will still be at least - // one char. - E.Name = E.Name.substr(0, E.Name.find('@', 1)); - } - } - - return static_cast<bool>( - object::writeImportLibrary(def->OutputFile, output_lib_path, - def->Exports, machine, /* MinGW */ true)); -} - bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size_t file_name_count, ZigLLVMArchiveKind archive_kind) { |
