<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Warn on .lib files with the wrong arch"
   href="https://bugs.llvm.org/show_bug.cgi?id=38965">38965</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Warn on .lib files with the wrong arch
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>COFF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang-cl defaults to 64-bit builds. If you accidentally have your env set up to
point to the 32-bit .lib paths, you get these cryptic diags:

$ ./clang-cl.sh foo.cc -fuse-ld=lld
lld-link: error: <root>: undefined symbol: mainCRTStartup
$ ./clang-cl.sh -m32 foo.cc -fuse-ld=lld   # works


link.exe is much better, it has this warning telling you what the actual issue
is:

C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x64\advapi32.lib :
warning LNK4272: library machine type 'x64' conflicts with target machine type
'x86'

(copied from a different bug; it probably complains about a different .lib for
a trivial foo.cc with just main() -- but the warning is the same otherwise)


lld-link should warn on this too.


Hans says: """
.lib files themselves don't have a machine type.

However, the import lib pseudo-files inside them do. lld currently
doesn't check the machine type of those (it would if ImportFile
overrode getMachineType; it probably should).

But, lld will only look at the members of a .lib file lazily, i.e. if
it seems something that it needs in the .lib file's symbol table.
Because of this, I'm not sure that implementing
ImportFile::getMachineType is enough to produce a warning in Bruce's
case. Probably no symbols from advapi32.lib's symbol table are being
referenced, and so we would never parse the .lib file members :-/
"""


Zach says: """
It's pretty rare for a .lib file to have mixed arch object files.  You would
have to go out of your way to make it happen.  Given that, can we just open the
first object file, parse just enough of it to get the object file, and
early-warn if it mismatches on the assumption that all other objects in the
archive will have the same architecture?
"""


We should find some way to make this work.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>