-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][COFF] Add support for ARM64EC entry thunks. #88132
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,38 @@ void ObjFile::parseLazy() { | |
} | ||
} | ||
|
||
struct ECMapEntry { | ||
ulittle32_t src; | ||
ulittle32_t dst; | ||
ulittle32_t type; | ||
}; | ||
|
||
void ObjFile::initializeECThunks() { | ||
for (SectionChunk *chunk : hybmpChunks) { | ||
if (chunk->getContents().size() % sizeof(ECMapEntry)) { | ||
error("Invalid .hybmp chunk size " + Twine(chunk->getContents().size())); | ||
continue; | ||
} | ||
|
||
const uint8_t *end = | ||
chunk->getContents().data() + chunk->getContents().size(); | ||
for (const uint8_t *iter = chunk->getContents().data(); iter != end; | ||
iter += sizeof(ECMapEntry)) { | ||
auto entry = reinterpret_cast<const ECMapEntry *>(iter); | ||
switch (entry->type) { | ||
case Arm64ECThunkType::Entry: | ||
ctx.symtab.addEntryThunk(getSymbol(entry->src), getSymbol(entry->dst)); | ||
break; | ||
case Arm64ECThunkType::Exit: | ||
case Arm64ECThunkType::GuestExit: | ||
break; | ||
default: | ||
warn("Ignoring unknown EC thunk type " + Twine(entry->type)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ObjFile::parse() { | ||
// Parse a memory buffer as a COFF file. | ||
std::unique_ptr<Binary> bin = CHECK(createBinary(mb), this); | ||
|
@@ -168,6 +200,7 @@ void ObjFile::parse() { | |
initializeSymbols(); | ||
initializeFlags(); | ||
initializeDependencies(); | ||
initializeECThunks(); | ||
} | ||
|
||
const coff_section *ObjFile::getSection(uint32_t i) { | ||
|
@@ -242,7 +275,11 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber, | |
|
||
if (sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE) | ||
return nullptr; | ||
auto *c = make<SectionChunk>(this, sec); | ||
SectionChunk *c; | ||
if (isArm64EC(getMachineType())) | ||
c = make<SectionChunkEC>(this, sec); | ||
else | ||
c = make<SectionChunk>(this, sec); | ||
if (def) | ||
c->checksum = def->CheckSum; | ||
|
||
|
@@ -260,6 +297,8 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber, | |
guardEHContChunks.push_back(c); | ||
else if (name == ".sxdata") | ||
sxDataChunks.push_back(c); | ||
else if (isArm64EC(getMachineType()) && name == ".hybmp$x") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the section name always have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked with MSVC, it seems to apply the special treatment only for that exact name. Things like ".hybmp", ".hybmp$xy" or ".hybmp$y" don't get that treatment. |
||
hybmpChunks.push_back(c); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this change both has the effect that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there is no reason for them to be in the output file. Entry thunks are looked up from the offset in padding in runtime. Later, the linker will need exit thunk association for generating import thunks, but once the image is linked, there is no need for such map. |
||
else if (ctx.config.tailMerge && sec->NumberOfRelocations == 0 && | ||
name == ".rdata" && leaderName.starts_with("??_C@")) | ||
// COFF sections that look like string literal sections (i.e. no | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
+1
feels quite odd here. I don't doubt that it's right, but it feels quite surprising to see an odd number when it comes to arm64 function offsets (which all should be multiples of 4). Is there something more you can write here to explain it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's what I observed with MSVC and what Windows expects, I can only speculate about the reason. It could be just "have the low bit set", or it could be interpreted as the offset being from the last byte of the padding, not the first byte of the function. I added a comment about it.