[lld] [LLD][COFF] Add support for CHPE code ranges metadata. (PR #105741)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 06:39:53 PDT 2024
================
@@ -1078,6 +1078,22 @@ void ECExportThunkChunk::writeTo(uint8_t *buf) const {
write32le(buf + 10, target->getRVA() - rva - 14);
}
+size_t CHPECodeRangesChunk::getSize() const {
+ return exportThunks.size() * sizeof(chpe_code_range_entry);
+}
+
+void CHPECodeRangesChunk::writeTo(uint8_t *buf) const {
+ auto ranges = reinterpret_cast<chpe_code_range_entry *>(buf);
+
+ for (uint32_t i = 0; i < exportThunks.size(); i++) {
+ Chunk *thunk = exportThunks[i].first;
+ uint32_t start = thunk->getRVA();
+ ranges[i].StartRva = start;
+ ranges[i].EndRva = start + thunk->getSize();
+ ranges[i].EntryPoint = start;
----------------
cjacek wrote:
I'm afraid it doesn't make more sense even when it's more complete. I've never seen StartRva and EntryPoint differ, even with some unusual synthetic inputs that I experimented with for custom export thunks. I’m not sure why it’s structured this way. Instead of duplicating the value in EntryPoint, I imagine it could store the redirection destination here and use a single structure instead of separate ones for redirection and code ranges.
As for how these structures are used, I can only speculate, so please keep in mind that this is just a guess. I think it might be useful for [auxiliary IAT](https://wiki.winehq.org/ARM64ECToolchain#Regular_IAT_and_Auxiliary_IAT) handling. The loader needs to populate the auxiliary IAT with addresses of actual ARM64EC functions, where something like redirection metadata could be used. It would also need to detect runtime patching of x86 thunks to know when to revert the auxiliary IAT to go through the call checker. For that, it would additionally need to know the thunks' sizes, which is what the code ranges metadata provides.
https://github.com/llvm/llvm-project/pull/105741
More information about the llvm-commits
mailing list