[lld] [LLD][COFF] Always locate the IAT at the beginning of the .rdata section and align its size to 4KB on ARM64EC. (PR #107588)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 7 05:51:53 PDT 2024
cjacek wrote:
Yes, I believe the new version is more correct, though the practical difference may be minimal.
The main distinction lies in how `.idata` sections provided by object files are handled - such as the long-form import libraries generated by binutils, as opposed to synthesized chunks generated from import files. I tested this with the MSVC linker, and it places the `.idata$5` contents together with the synthesized ones. To match this behavior, I needed to adjust the logic to operate based on partial sections rather than working directly with IdataContents.
I tested this by using an x86_64 import library generated by binutils. Since such a library is unaware of the auxiliary IAT, the resulting binary isn't quite correct and is unlikely to function properly. However, it would be possible to create an ARM64EC-aware library that handles things correctly. This would require additional `.idata$9` and `.idata$a` sections (for the auxiliary IAT and its copy), along with the necessary thunks to populate them. While I don't see a practical need for this, the new approach supports it, and MSVC's link.exe seems to handle it as well.
By the way, when such invalid import libraries are used, we may want to emit some diagnostics. This kind of mistake is not obvious and could be easily made in a MinGW environment. MSVC handles it by checking if the IAT aligns with the auxiliary IAT, and if not, it emits a warning like:
```
LINK : warning LNK4308: the auxiliary import address table is not properly aligned with the primary import address table. This may have negative perf impact.
```
(I think this warning is somewhat misleading - it’s not just a performance issue; in my test case, it would actually lead to crashes.)
As for the partial section insertion, my goal was to make the LLD state as close to the "regular" chunk addition process as possible. Since we use contributing sections when emitting PDBs, this should make that process more accurate. MSVC also emits partial sections in the map file (which is how I discovered the section names for auxiliary IATs). While LLD doesn’t do this yet, if we ever decide to, the code from this PR will be ready for it.
https://github.com/llvm/llvm-project/pull/107588
More information about the llvm-commits
mailing list