@@ -298,6 +298,9 @@ class Writer {
298298 CVDebugRecordChunk *buildId = nullptr ;
299299 ArrayRef<uint8_t > sectionTable;
300300
301+ // List of Arm64EC export thunks.
302+ std::vector<std::pair<Chunk *, Defined *>> exportThunks;
303+
301304 uint64_t fileSize;
302305 uint32_t pointerToSymbolTable = 0 ;
303306 uint64_t sizeOfImage;
@@ -312,6 +315,7 @@ class Writer {
312315 OutputSection *idataSec;
313316 OutputSection *edataSec;
314317 OutputSection *didatSec;
318+ OutputSection *a64xrmSec;
315319 OutputSection *rsrcSec;
316320 OutputSection *relocSec;
317321 OutputSection *ctorsSec;
@@ -995,6 +999,8 @@ void Writer::createSections() {
995999 idataSec = createSection (" .idata" , data | r);
9961000 edataSec = createSection (" .edata" , data | r);
9971001 didatSec = createSection (" .didat" , data | r);
1002+ if (isArm64EC (ctx.config .machine ))
1003+ a64xrmSec = createSection (" .a64xrm" , data | r);
9981004 rsrcSec = createSection (" .rsrc" , data | r);
9991005 relocSec = createSection (" .reloc" , data | discardable | r);
10001006 ctorsSec = createSection (" .ctors" , data | r | w);
@@ -2053,15 +2059,24 @@ void Writer::createECChunks() {
20532059 auto sym = dyn_cast<Defined>(s);
20542060 if (!sym || !sym->getChunk ())
20552061 continue ;
2056- if (auto thunk = dyn_cast<ECExportThunkChunk>(sym->getChunk ()))
2062+ if (auto thunk = dyn_cast<ECExportThunkChunk>(sym->getChunk ())) {
20572063 hexpthkSec->addChunk (thunk);
2064+ exportThunks.push_back ({thunk, thunk->target });
2065+ }
20582066 }
20592067
20602068 auto codeMapChunk = make<ECCodeMapChunk>(codeMap);
20612069 rdataSec->addChunk (codeMapChunk);
20622070 Symbol *codeMapSym = ctx.symtab .findUnderscore (" __hybrid_code_map" );
20632071 replaceSymbol<DefinedSynthetic>(codeMapSym, codeMapSym->getName (),
20642072 codeMapChunk);
2073+
2074+ CHPERedirectionChunk *entryPoints = make<CHPERedirectionChunk>(exportThunks);
2075+ a64xrmSec->addChunk (entryPoints);
2076+ Symbol *entryPointsSym =
2077+ ctx.symtab .findUnderscore (" __arm64x_redirection_metadata" );
2078+ replaceSymbol<DefinedSynthetic>(entryPointsSym, entryPointsSym->getName (),
2079+ entryPoints);
20652080}
20662081
20672082// MinGW specific. Gather all relocations that are imported from a DLL even
@@ -2154,6 +2169,11 @@ void Writer::setECSymbols() {
21542169 if (!isArm64EC (ctx.config .machine ))
21552170 return ;
21562171
2172+ llvm::stable_sort (exportThunks, [](const std::pair<Chunk *, Defined *> &a,
2173+ const std::pair<Chunk *, Defined *> &b) {
2174+ return a.first ->getRVA () < b.first ->getRVA ();
2175+ });
2176+
21572177 Symbol *rfeTableSym = ctx.symtab .findUnderscore (" __arm64x_extra_rfe_table" );
21582178 replaceSymbol<DefinedSynthetic>(rfeTableSym, " __arm64x_extra_rfe_table" ,
21592179 pdata.first );
@@ -2165,6 +2185,10 @@ void Writer::setECSymbols() {
21652185 ->setVA (pdata.last ->getRVA () + pdata.last ->getSize () -
21662186 pdata.first ->getRVA ());
21672187 }
2188+
2189+ Symbol *entryPointCountSym =
2190+ ctx.symtab .findUnderscore (" __arm64x_redirection_metadata_count" );
2191+ cast<DefinedAbsolute>(entryPointCountSym)->setVA (exportThunks.size ());
21682192}
21692193
21702194// Write section contents to a mmap'ed file.
0 commit comments