[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 01:40:24 PST 2025


mstorsjo wrote:

Your example yaml has got this small contradiction:
```
    SectionData:     '000000000000000000000000'
    SizeOfRawData:   8
```
That's 12 bytes of zeros. To make the testcase more interesting, I tweaked this to contain 10 bytes, while setting the empty section to align to 4 bytes.

When testing this synthetic case with MS link.exe, I'm hitting this error:
```
LINK : fatal error LNK1000: unknown error at 0000000140102A09; consult documentation for technical support options
```
I guess this is what you hit and refer to?

(Side note: Inspecting the short import libraries is quite messy, as all members have the same name; I have an old longstanding custom patch for `llvm-ar` that adds an extra option, that allows extracting them as `foo.dll`, `foo.dll-2`, `foo.dll-3` etc, for inspecting import libraries. If you have any suggestion on a clean way to achieve the same with upstream functionality, or a way to handle this, I'm all ears.)

It seems that link.exe gives this error if there's no other object file defining the empty section. If we do add a separate object that adds a concrete definition of the section, even if it is entirely empty, linking succeeds - and we can observe that link.exe doesn't give these empty sections any extra alignment at all.

I guess that shows a small discrepancy to how link.exe handles it - it defers the section chunk definition entirely to another object file, inferring the alignment from there. While with the way I implement it here, we have to invent a section and make up alignment. I chose to set 4 byte alignment here, as that's what is needed for `.idata$4` anyway; if we'd choose something less than what the individual IAT entries use, we'd end up with a gap between the header's reference to `.idata$4` and the actual contents.

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


More information about the llvm-commits mailing list