From 9a4b6b77325777062f6f128d499578bc3feac6e5 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Sat, 5 Jul 2025 11:05:34 -0400 Subject: [PATCH 1/3] Follow up comments on pr146610 --- lld/COFF/Config.h | 2 +- lld/COFF/Driver.cpp | 4 +- lld/COFF/InputFiles.cpp | 14 ++--- lld/test/COFF/imported-dllmain-i386.test | 59 +++++++++++++++++++ ...ted-dllmain.test => imported-dllmain.test} | 6 +- 5 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 lld/test/COFF/imported-dllmain-i386.test rename lld/test/COFF/{exported-dllmain.test => imported-dllmain.test} (86%) diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h index 79b63e5b7236f..9220c847f356d 100644 --- a/lld/COFF/Config.h +++ b/lld/COFF/Config.h @@ -307,7 +307,7 @@ struct Configuration { bool warnDebugInfoUnusable = true; bool warnLongSectionNames = true; bool warnStdcallFixup = true; - bool warnExportedDllMain = true; + bool warnImportedDllMain = true; bool incremental = true; bool integrityCheck = false; bool killAt = false; diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 283aeed1a19cd..0f649ff1cf4f8 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1643,8 +1643,8 @@ void LinkerDriver::linkerMain(ArrayRef argsArr) { config->warnLocallyDefinedImported = false; else if (s == "longsections") config->warnLongSectionNames = false; - else if (s == "exporteddllmain") - config->warnExportedDllMain = false; + else if (s == "importeddllmain") + config->warnImportedDllMain = false; // Other warning numbers are ignored. } } diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 0b7dbea8cdd99..1edd24cdf2dea 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -128,13 +128,13 @@ static bool fixupDllMain(COFFLinkerContext &ctx, llvm::object::Archive *file, file->getFileName() + ": could not get the buffer for a child buffer of the archive"); if (identify_magic(mb.getBuffer()) == file_magic::coff_import_library) { - if (ctx.config.warnExportedDllMain) { + if (ctx.config.warnImportedDllMain) { // We won't place DllMain symbols in the symbol table if they are // coming from a import library. This message can be ignored with the flag - // '/ignore:exporteddllmain' + // '/ignore:importeddllmain' Warn(ctx) << file->getFileName() - << ": skipping exported DllMain symbol [exporteddllmain]\nNOTE: this " + << ": skipping imported DllMain symbol [importeddllmain]\nNOTE: this " "might be a mistake when the DLL/library was produced."; } skipDllMain = true; @@ -207,10 +207,10 @@ void ArchiveFile::parse() { // Read the symbol table to construct Lazy objects. bool skipDllMain = false; for (const Archive::Symbol &sym : file->symbols()) { - // If the DllMain symbol was exported by mistake, skip importing it - // otherwise we might end up with a import thunk in the final binary which - // is wrong. - if (sym.getName() == "__imp_DllMain" || sym.getName() == "DllMain") { + // If an import library provides the DllMain symbol, skip importing it, as + // we should be using our own DllMain, not another DLL's DllMain. + if (sym.getName() == "__imp_DllMain" || sym.getName() == "DllMain" || + sym.getName() == "_DllMain") { if (fixupDllMain(ctx, file.get(), sym, skipDllMain)) continue; } diff --git a/lld/test/COFF/imported-dllmain-i386.test b/lld/test/COFF/imported-dllmain-i386.test new file mode 100644 index 0000000000000..a9cd94d089e29 --- /dev/null +++ b/lld/test/COFF/imported-dllmain-i386.test @@ -0,0 +1,59 @@ +REQUIRES: x86 +RUN: split-file %s %t.dir && cd %t.dir + +RUN: llvm-mc -filetype=obj -triple=i386-windows a.s -o a.obj + +RUN: llvm-mc -filetype=obj -triple=i386-windows b1.s -o b1.obj +RUN: llvm-mc -filetype=obj -triple=i386-windows b2.s -o b2.obj + +### This is the line where our problem occurs. Here, we export the DllMain symbol which shouldn't happen normally. +RUN: lld-link b1.obj b2.obj -out:b.dll -dll -implib:b.lib -entry:DllMain -export:bar -export:DllMain -safeseh:no + +RUN: llvm-mc -filetype=obj -triple=i386-windows c.s -o c.obj +RUN: lld-link -lib c.obj -out:c.lib + +### Later, if b.lib is provided before other libs/objs that export DllMain statically, we previously were using the dllimported DllMain from b.lib, which is wrong. +RUN: lld-link a.obj b.lib c.lib -dll -out:out.dll -entry:DllMain -safeseh:no 2>&1 | FileCheck -check-prefix=WARN %s +RUN: lld-link a.obj b.lib c.lib -dll -out:out.dll -entry:DllMain -ignore:importeddllmain -safeseh:no 2>&1 | FileCheck -check-prefix=IGNORED --allow-empty %s +RUN: llvm-objdump --private-headers -d out.dll | FileCheck -check-prefix=DISASM %s + +WARN: lld-link: warning: b.lib: skipping imported DllMain symbol [importeddllmain] +IGNORED-NOT: lld-link: warning: b.lib: skipping imported DllMain symbol [importeddllmain] + +DISASM: The Import Tables: +DISASM: DLL Name: b.dll +DISASM-NOT: DllMain +DISASM: bar +DISASM: Disassembly of section .text: +DISASM-EMPTY: +DISASM-NEXT: b0 01 movb $0x1, %al +DISASM-NEXT: c3 retl + +#--- a.s + .text + .globl _foo +_foo: + call *__imp__bar + ret + +#--- b1.s + .text + .globl _bar +_bar: + ret + +#--- b2.s + .intel_syntax noprefix + .text + .globl _DllMain +_DllMain: + xor al, al + ret + +#--- c.s + .intel_syntax noprefix + .text + .globl _DllMain +_DllMain: + mov al, 1 + ret diff --git a/lld/test/COFF/exported-dllmain.test b/lld/test/COFF/imported-dllmain.test similarity index 86% rename from lld/test/COFF/exported-dllmain.test rename to lld/test/COFF/imported-dllmain.test index fcf6ed1005379..fa8579b1b41c5 100644 --- a/lld/test/COFF/exported-dllmain.test +++ b/lld/test/COFF/imported-dllmain.test @@ -14,11 +14,11 @@ RUN: lld-link -lib c.obj -out:c.lib ### Later, if b.lib is provided before other libs/objs that export DllMain statically, we previously were using the dllimported DllMain from b.lib, which is wrong. RUN: lld-link a.obj b.lib c.lib -dll -out:out.dll -entry:DllMain 2>&1 | FileCheck -check-prefix=WARN %s -RUN: lld-link a.obj b.lib c.lib -dll -out:out.dll -entry:DllMain -ignore:exporteddllmain 2>&1 | FileCheck -check-prefix=IGNORED --allow-empty %s +RUN: lld-link a.obj b.lib c.lib -dll -out:out.dll -entry:DllMain -ignore:importeddllmain 2>&1 | FileCheck -check-prefix=IGNORED --allow-empty %s RUN: llvm-objdump --private-headers -d out.dll | FileCheck -check-prefix=DISASM %s -WARN: lld-link: warning: b.lib: skipping exported DllMain symbol [exporteddllmain] -IGNORED-NOT: lld-link: warning: b.lib: skipping exported DllMain symbol [exporteddllmain] +WARN: lld-link: warning: b.lib: skipping imported DllMain symbol [importeddllmain] +IGNORED-NOT: lld-link: warning: b.lib: skipping imported DllMain symbol [importeddllmain] DISASM: The Import Tables: DISASM: DLL Name: b.dll From 25f3b010bbef8e77aedad64c897561a893250142 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Thu, 17 Jul 2025 18:05:49 -0400 Subject: [PATCH 2/3] Address review comments especially i386 support --- lld/COFF/Driver.cpp | 46 +++++----- lld/COFF/InputFiles.cpp | 105 ++++++++++++++--------- lld/COFF/InputFiles.h | 1 + lld/test/COFF/implib-machine.s | 4 +- lld/test/COFF/imported-dllmain-i386.test | 3 +- 5 files changed, 91 insertions(+), 68 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 0f649ff1cf4f8..658beccebc7b0 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -198,28 +198,8 @@ static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) { } void LinkerDriver::addFile(InputFile *file) { - Log(ctx) << "Reading " << toString(file); - if (file->lazy) { - if (auto *f = dyn_cast(file)) - f->parseLazy(); - else - cast(file)->parseLazy(); - } else { - file->parse(); - if (auto *f = dyn_cast(file)) { - ctx.objFileInstances.push_back(f); - } else if (auto *f = dyn_cast(file)) { - if (ltoCompilationDone) { - Err(ctx) << "LTO object file " << toString(file) - << " linked in after " - "doing LTO compilation."; - } - f->symtab.bitcodeFileInstances.push_back(f); - } else if (auto *f = dyn_cast(file)) { - ctx.importFileInstances.push_back(f); - } - } - + // We need to process the machine type early on, so that APIs such as + // `mangle()` won't fail. MachineTypes mt = file->getMachineType(); // The ARM64EC target must be explicitly specified and cannot be inferred. if (mt == ARM64EC && @@ -242,6 +222,28 @@ void LinkerDriver::addFile(InputFile *file) { setMachine(mt); } + Log(ctx) << "Reading " << toString(file); + if (file->lazy) { + if (auto *f = dyn_cast(file)) + f->parseLazy(); + else + cast(file)->parseLazy(); + } else { + file->parse(); + if (auto *f = dyn_cast(file)) { + ctx.objFileInstances.push_back(f); + } else if (auto *f = dyn_cast(file)) { + if (ltoCompilationDone) { + Err(ctx) << "LTO object file " << toString(file) + << " linked in after " + "doing LTO compilation."; + } + f->symtab.bitcodeFileInstances.push_back(f); + } else if (auto *f = dyn_cast(file)) { + ctx.importFileInstances.push_back(f); + } + } + parseDirectives(file); } diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 1edd24cdf2dea..f0d7045a2f3ed 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -117,8 +117,6 @@ static coff_symbol_generic *cloneSymbol(COFFSymbolRef sym) { // Skip importing DllMain thunks from import libraries. static bool fixupDllMain(COFFLinkerContext &ctx, llvm::object::Archive *file, const Archive::Symbol &sym, bool &skipDllMain) { - if (skipDllMain) - return true; const Archive::Child &c = CHECK(sym.getMember(), file->getFileName() + ": could not get the member for symbol " + @@ -144,15 +142,15 @@ static bool fixupDllMain(COFFLinkerContext &ctx, llvm::object::Archive *file, } ArchiveFile::ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m) - : InputFile(ctx.symtab, ArchiveKind, m) {} + : InputFile(ctx.symtab, ArchiveKind, m) { + // Parse a MemoryBufferRef as an archive file. + file = CHECK(Archive::create(mb), this); +} void ArchiveFile::parse() { COFFLinkerContext &ctx = symtab.ctx; SymbolTable *archiveSymtab = &symtab; - // Parse a MemoryBufferRef as an archive file. - file = CHECK(Archive::create(mb), this); - // Try to read symbols from ECSYMBOLS section on ARM64EC. if (ctx.symtab.isEC()) { iterator_range symbols = @@ -168,56 +166,79 @@ void ArchiveFile::parse() { // be either a native-only ARM64 or x86_64 archive. Check the machine type // of the object containing a symbol to determine which symbol table to // use. - Archive::symbol_iterator sym = file->symbol_begin(); - if (sym != file->symbol_end()) { - MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN; - Archive::Child child = - CHECK(sym->getMember(), - file->getFileName() + - ": could not get the buffer for a child of the archive"); - MemoryBufferRef mb = CHECK( - child.getMemoryBufferRef(), - file->getFileName() + - ": could not get the buffer for a child buffer of the archive"); - switch (identify_magic(mb.getBuffer())) { - case file_magic::coff_object: { - std::unique_ptr obj = - CHECK(COFFObjectFile::create(mb), - check(child.getName()) + ":" + ": not a valid COFF file"); - machine = MachineTypes(obj->getMachine()); - break; - } - case file_magic::coff_import_library: - machine = MachineTypes(COFFImportFile(mb).getMachine()); - break; - case file_magic::bitcode: { - std::unique_ptr obj = - check(lto::InputFile::create(mb)); - machine = BitcodeFile::getMachineType(obj.get()); - break; - } - default: - break; - } + MachineTypes machine = getMachineType(); + if (machine != IMAGE_FILE_MACHINE_UNKNOWN) archiveSymtab = &ctx.getSymtab(machine); - } } } - // Read the symbol table to construct Lazy objects. bool skipDllMain = false; + StringRef mangledDllMain, impMangledDllMain; + + // The calls below will fail if we haven't set the machine type yet. Instead + // of failing, it is preferable to skip this "imported DllMain" check if we + // don't know the machine type at this point. + if (!file->isEmpty() && ctx.config.machine != IMAGE_FILE_MACHINE_UNKNOWN) { + mangledDllMain = archiveSymtab->mangle("DllMain"); + impMangledDllMain = uniqueSaver().save("__imp_" + mangledDllMain); + } + + // Read the symbol table to construct Lazy objects. for (const Archive::Symbol &sym : file->symbols()) { // If an import library provides the DllMain symbol, skip importing it, as // we should be using our own DllMain, not another DLL's DllMain. - if (sym.getName() == "__imp_DllMain" || sym.getName() == "DllMain" || - sym.getName() == "_DllMain") { - if (fixupDllMain(ctx, file.get(), sym, skipDllMain)) + if (!mangledDllMain.empty() && (sym.getName() == mangledDllMain || + sym.getName() == impMangledDllMain)) { + if (skipDllMain || fixupDllMain(ctx, file.get(), sym, skipDllMain)) continue; } archiveSymtab->addLazyArchive(this, sym); } } +MachineTypes ArchiveFile::getMachineType() const { + if (!file) + return IMAGE_FILE_MACHINE_UNKNOWN; + if (file->isEmpty()) + return IMAGE_FILE_MACHINE_UNKNOWN; + Archive::symbol_iterator sym = file->symbol_begin(); + if (sym != file->symbol_end()) { + Expected child = sym->getMember(); + if (!child) { + consumeError(child.takeError()); + return IMAGE_FILE_MACHINE_UNKNOWN; + } + Expected mb = child->getMemoryBufferRef(); + if (!mb) { + consumeError(mb.takeError()); + return IMAGE_FILE_MACHINE_UNKNOWN; + } + switch (identify_magic(mb->getBuffer())) { + case file_magic::coff_object: { + Expected> obj = + COFFObjectFile::create(*mb); + if (!obj) { + consumeError(obj.takeError()); + return IMAGE_FILE_MACHINE_UNKNOWN; + } + return MachineTypes((*obj)->getMachine()); + break; + } + case file_magic::coff_import_library: + return MachineTypes(COFFImportFile(*mb).getMachine()); + break; + case file_magic::bitcode: { + std::unique_ptr obj = check(lto::InputFile::create(*mb)); + return BitcodeFile::getMachineType(obj.get()); + break; + } + default: + break; + } + } + return IMAGE_FILE_MACHINE_UNKNOWN; +} + // Returns a buffer pointing to a member file containing a given symbol. void ArchiveFile::addMember(const Archive::Symbol &sym) { const Archive::Child &c = diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index 21b9aeef21d4f..ff3fc72debea2 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -121,6 +121,7 @@ class ArchiveFile : public InputFile { explicit ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m); static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; } void parse() override; + MachineTypes getMachineType() const override; // Enqueues an archive member load for the given symbol. If we've already // enqueued a load for the same archive member, this function does nothing, diff --git a/lld/test/COFF/implib-machine.s b/lld/test/COFF/implib-machine.s index 92f01bbc72799..94db6bff0aa82 100644 --- a/lld/test/COFF/implib-machine.s +++ b/lld/test/COFF/implib-machine.s @@ -6,10 +6,10 @@ # RUN: llvm-mc -triple x86_64-windows-msvc %t.dir/test.s -filetype=obj -o %t.dir/test64.obj # RUN: not lld-link -dll -noentry -out:%t32.dll %t.dir/test32.obj %t.dir/test64.lib 2>&1 | FileCheck --check-prefix=ERR32 %s -# ERR32: error: test64.lib(test.dll): machine type x64 conflicts with x86 +# ERR32: error: {{.*[/\\]}}test64.lib: machine type x64 conflicts with x86 # RUN: not lld-link -dll -noentry -out:%t64.dll %t.dir/test64.obj %t.dir/test32.lib 2>&1 | FileCheck --check-prefix=ERR64 %s -# ERR64: error: test32.lib(test.dll): machine type x86 conflicts with x64 +# ERR64: error: {{.*[/\\]}}test32.lib: machine type x86 conflicts with x64 #--- test.s .def @feat.00; diff --git a/lld/test/COFF/imported-dllmain-i386.test b/lld/test/COFF/imported-dllmain-i386.test index a9cd94d089e29..f8aa09006999c 100644 --- a/lld/test/COFF/imported-dllmain-i386.test +++ b/lld/test/COFF/imported-dllmain-i386.test @@ -25,8 +25,7 @@ DISASM: DLL Name: b.dll DISASM-NOT: DllMain DISASM: bar DISASM: Disassembly of section .text: -DISASM-EMPTY: -DISASM-NEXT: b0 01 movb $0x1, %al +DISASM: b0 01 movb $0x1, %al DISASM-NEXT: c3 retl #--- a.s From 312fd39406f43ba7d3a56782e4f760beffea5225 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Thu, 17 Jul 2025 18:24:10 -0400 Subject: [PATCH 3/3] Revert some of the previous changes --- lld/COFF/Driver.cpp | 46 +++++++++--------- lld/COFF/InputFiles.cpp | 85 ++++++++++++++-------------------- lld/COFF/InputFiles.h | 1 - lld/test/COFF/implib-machine.s | 4 +- 4 files changed, 60 insertions(+), 76 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 658beccebc7b0..0f649ff1cf4f8 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -198,30 +198,6 @@ static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) { } void LinkerDriver::addFile(InputFile *file) { - // We need to process the machine type early on, so that APIs such as - // `mangle()` won't fail. - MachineTypes mt = file->getMachineType(); - // The ARM64EC target must be explicitly specified and cannot be inferred. - if (mt == ARM64EC && - (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN || - (ctx.config.machineInferred && - (ctx.config.machine == ARM64 || ctx.config.machine == AMD64)))) { - Err(ctx) << toString(file) - << ": machine type arm64ec is ambiguous and cannot be " - "inferred, use /machine:arm64ec or /machine:arm64x"; - return; - } - if (!compatibleMachineType(ctx, mt)) { - Err(ctx) << toString(file) << ": machine type " << machineToStr(mt) - << " conflicts with " << machineToStr(ctx.config.machine); - return; - } - if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN && - mt != IMAGE_FILE_MACHINE_UNKNOWN) { - ctx.config.machineInferred = true; - setMachine(mt); - } - Log(ctx) << "Reading " << toString(file); if (file->lazy) { if (auto *f = dyn_cast(file)) @@ -244,6 +220,28 @@ void LinkerDriver::addFile(InputFile *file) { } } + MachineTypes mt = file->getMachineType(); + // The ARM64EC target must be explicitly specified and cannot be inferred. + if (mt == ARM64EC && + (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN || + (ctx.config.machineInferred && + (ctx.config.machine == ARM64 || ctx.config.machine == AMD64)))) { + Err(ctx) << toString(file) + << ": machine type arm64ec is ambiguous and cannot be " + "inferred, use /machine:arm64ec or /machine:arm64x"; + return; + } + if (!compatibleMachineType(ctx, mt)) { + Err(ctx) << toString(file) << ": machine type " << machineToStr(mt) + << " conflicts with " << machineToStr(ctx.config.machine); + return; + } + if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN && + mt != IMAGE_FILE_MACHINE_UNKNOWN) { + ctx.config.machineInferred = true; + setMachine(mt); + } + parseDirectives(file); } diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index f0d7045a2f3ed..2a6b63cbacca1 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -142,15 +142,15 @@ static bool fixupDllMain(COFFLinkerContext &ctx, llvm::object::Archive *file, } ArchiveFile::ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m) - : InputFile(ctx.symtab, ArchiveKind, m) { - // Parse a MemoryBufferRef as an archive file. - file = CHECK(Archive::create(mb), this); -} + : InputFile(ctx.symtab, ArchiveKind, m) {} void ArchiveFile::parse() { COFFLinkerContext &ctx = symtab.ctx; SymbolTable *archiveSymtab = &symtab; + // Parse a MemoryBufferRef as an archive file. + file = CHECK(Archive::create(mb), this); + // Try to read symbols from ECSYMBOLS section on ARM64EC. if (ctx.symtab.isEC()) { iterator_range symbols = @@ -166,9 +166,39 @@ void ArchiveFile::parse() { // be either a native-only ARM64 or x86_64 archive. Check the machine type // of the object containing a symbol to determine which symbol table to // use. - MachineTypes machine = getMachineType(); - if (machine != IMAGE_FILE_MACHINE_UNKNOWN) + Archive::symbol_iterator sym = file->symbol_begin(); + if (sym != file->symbol_end()) { + MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN; + Archive::Child child = + CHECK(sym->getMember(), + file->getFileName() + + ": could not get the buffer for a child of the archive"); + MemoryBufferRef mb = CHECK( + child.getMemoryBufferRef(), + file->getFileName() + + ": could not get the buffer for a child buffer of the archive"); + switch (identify_magic(mb.getBuffer())) { + case file_magic::coff_object: { + std::unique_ptr obj = + CHECK(COFFObjectFile::create(mb), + check(child.getName()) + ":" + ": not a valid COFF file"); + machine = MachineTypes(obj->getMachine()); + break; + } + case file_magic::coff_import_library: + machine = MachineTypes(COFFImportFile(mb).getMachine()); + break; + case file_magic::bitcode: { + std::unique_ptr obj = + check(lto::InputFile::create(mb)); + machine = BitcodeFile::getMachineType(obj.get()); + break; + } + default: + break; + } archiveSymtab = &ctx.getSymtab(machine); + } } } @@ -196,49 +226,6 @@ void ArchiveFile::parse() { } } -MachineTypes ArchiveFile::getMachineType() const { - if (!file) - return IMAGE_FILE_MACHINE_UNKNOWN; - if (file->isEmpty()) - return IMAGE_FILE_MACHINE_UNKNOWN; - Archive::symbol_iterator sym = file->symbol_begin(); - if (sym != file->symbol_end()) { - Expected child = sym->getMember(); - if (!child) { - consumeError(child.takeError()); - return IMAGE_FILE_MACHINE_UNKNOWN; - } - Expected mb = child->getMemoryBufferRef(); - if (!mb) { - consumeError(mb.takeError()); - return IMAGE_FILE_MACHINE_UNKNOWN; - } - switch (identify_magic(mb->getBuffer())) { - case file_magic::coff_object: { - Expected> obj = - COFFObjectFile::create(*mb); - if (!obj) { - consumeError(obj.takeError()); - return IMAGE_FILE_MACHINE_UNKNOWN; - } - return MachineTypes((*obj)->getMachine()); - break; - } - case file_magic::coff_import_library: - return MachineTypes(COFFImportFile(*mb).getMachine()); - break; - case file_magic::bitcode: { - std::unique_ptr obj = check(lto::InputFile::create(*mb)); - return BitcodeFile::getMachineType(obj.get()); - break; - } - default: - break; - } - } - return IMAGE_FILE_MACHINE_UNKNOWN; -} - // Returns a buffer pointing to a member file containing a given symbol. void ArchiveFile::addMember(const Archive::Symbol &sym) { const Archive::Child &c = diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index ff3fc72debea2..21b9aeef21d4f 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -121,7 +121,6 @@ class ArchiveFile : public InputFile { explicit ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m); static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; } void parse() override; - MachineTypes getMachineType() const override; // Enqueues an archive member load for the given symbol. If we've already // enqueued a load for the same archive member, this function does nothing, diff --git a/lld/test/COFF/implib-machine.s b/lld/test/COFF/implib-machine.s index 94db6bff0aa82..92f01bbc72799 100644 --- a/lld/test/COFF/implib-machine.s +++ b/lld/test/COFF/implib-machine.s @@ -6,10 +6,10 @@ # RUN: llvm-mc -triple x86_64-windows-msvc %t.dir/test.s -filetype=obj -o %t.dir/test64.obj # RUN: not lld-link -dll -noentry -out:%t32.dll %t.dir/test32.obj %t.dir/test64.lib 2>&1 | FileCheck --check-prefix=ERR32 %s -# ERR32: error: {{.*[/\\]}}test64.lib: machine type x64 conflicts with x86 +# ERR32: error: test64.lib(test.dll): machine type x64 conflicts with x86 # RUN: not lld-link -dll -noentry -out:%t64.dll %t.dir/test64.obj %t.dir/test32.lib 2>&1 | FileCheck --check-prefix=ERR64 %s -# ERR64: error: {{.*[/\\]}}test32.lib: machine type x86 conflicts with x64 +# ERR64: error: test32.lib(test.dll): machine type x86 conflicts with x64 #--- test.s .def @feat.00;