Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using /WHOLEARCHIVE on a COFF import library with an MSVC linker fails to link #19

Closed
ChrisDenton opened this issue Aug 16, 2024 · 1 comment · Fixed by #20
Closed

Comments

@ChrisDenton
Copy link
Member

ChrisDenton commented Aug 16, 2024

Every COFF import library has a special object file containing the null import descriptor. This is exactly the same between import libraries, which causes a conflict if using /WHOLEARCHIVE.

The fact that it's exactly the same does however allow for a possible fix: add a COMDAT record to the special .idata$3 section so it behaves as if it's still in a library even if all objects are forced to be included. The downside would be that import libraries generated by this crate would no longer be byte-for-byte the same as LLVM import libraries.

Pseudo code:

// Placed before the `__NULL_IMPORT_DESCRIPTOR` in the COFF symbol table
ImageSymbol {
    name: *b".idata$3",
    section_number: 1,
    storage_class: IMAGE_SYM_CLASS_STATIC,
    number_of_aux_symbols: 1,
    ...
};
ImageAuxSymbolSection {
    length: mem::size_of::<ImageImportDescriptor>(),
    selection: IMAGE_COMDAT_SELECT_ANY,
    ...
};

cc @dpaoliello

@bjorn3
Copy link
Member

bjorn3 commented Aug 16, 2024

Maybe we could have a flag fo enable/disable usage of COMDAT. That way all tests can keep asserting matches between LLVM and ar_archive_writer, while rustc can use COMDAT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants