[lld] [llvm] [LLD] [COFF] Fix linking import libraries with -wholearchive: (PR #122806)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 00:50:24 PST 2025


mstorsjo wrote:

> I was curious about the behavior of other linkers. The MSVC linker doesn't seem to allow linking entire import libraries this way. Either I made a mistake during testing, Rust has some specific handling for this, or it’s simply not expected to work there.

Hmm, at least the testcase I'm adding here seems to work if I swap in link.exe instead of lld-link. (There one also sees the ideal behaviour where the import directory doesn't contain a duplicate entry for this DLL.)

> I also experimented with a simplified version of your yaml file to isolate the issue from import libraries (and archives in general):
> 
> ```
> --- !COFF
> header:
>   Machine:         IMAGE_FILE_MACHINE_AMD64
>   Characteristics: [  ]
> sections:
>   - Name:            '.itest$2'
>     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
>     Alignment:       4
>     SectionData:     '000000000000000000000000'
>     SizeOfRawData:   8
>     Relocations:
>       - VirtualAddress:  0
>         SymbolName:      '.itest$4'
>         Type:            IMAGE_REL_AMD64_ADDR64
>   - Name:            '.itest$6'
>     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
>     Alignment:       2
>     SectionData:     01000000
>     SizeOfRawData:   4
> symbols:
>   - Name:            '.itest$2'
>     Value:           0
>     SectionNumber:   1
>     SimpleType:      IMAGE_SYM_TYPE_NULL
>     ComplexType:     IMAGE_SYM_DTYPE_NULL
>     StorageClass:    IMAGE_SYM_CLASS_SECTION
>   - Name:            '.itest$6'
>     Value:           0
>     SectionNumber:   2
>     SimpleType:      IMAGE_SYM_TYPE_NULL
>     ComplexType:     IMAGE_SYM_DTYPE_NULL
>     StorageClass:    IMAGE_SYM_CLASS_STATIC
>   - Name:            '.itest$4'
>     Value:           0
>     SectionNumber:   0
>     SimpleType:      IMAGE_SYM_TYPE_NULL
>     ComplexType:     IMAGE_SYM_DTYPE_NULL
>     StorageClass:    IMAGE_SYM_CLASS_SECTION
> ...
> ```
> 
> It might be worth adding something similar, paired with checks on the map file or by dumping section content as an additional test (that’s how I noticed the missing alignment).

Yes, a standalone test like that might be good to have as well. As the real use case is kinda entangled with with how LLD handles import libraries (and the curiosity where LLD normally entirely ignores these object files), I think it's good to test that case as well, but let's add such a standalone case too.

https://github.com/llvm/llvm-project/pull/122806


More information about the llvm-commits mailing list