@@ -575,7 +575,7 @@ bool Writer::createThunks(OutputSection *os, int margin) {
575575
576576// Create a code map for CHPE metadata.
577577void Writer::createECCodeMap () {
578- if (!isArm64EC ( ctx.config . machine ) )
578+ if (!ctx.symtabEC )
579579 return ;
580580
581581 // Clear the map in case we were're recomputing the map after adding
@@ -611,7 +611,8 @@ void Writer::createECCodeMap() {
611611
612612 closeRange ();
613613
614- Symbol *tableCountSym = ctx.symtab .findUnderscore (" __hybrid_code_map_count" );
614+ Symbol *tableCountSym =
615+ ctx.symtabEC ->findUnderscore (" __hybrid_code_map_count" );
615616 cast<DefinedAbsolute>(tableCountSym)->setVA (codeMap.size ());
616617}
617618
@@ -1229,8 +1230,7 @@ void Writer::createMiscChunks() {
12291230 // Create /guard:cf tables if requested.
12301231 createGuardCFTables ();
12311232
1232- if (isArm64EC (config->machine ))
1233- createECChunks ();
1233+ createECChunks ();
12341234
12351235 if (config->autoImport )
12361236 createRuntimePseudoRelocs ();
@@ -2158,7 +2158,11 @@ void Writer::maybeAddRVATable(SymbolRVASet tableSymbols, StringRef tableSym,
21582158
21592159// Create CHPE metadata chunks.
21602160void Writer::createECChunks () {
2161- for (Symbol *s : ctx.symtab .expSymbols ) {
2161+ SymbolTable *symtab = ctx.symtabEC ;
2162+ if (!symtab)
2163+ return ;
2164+
2165+ for (Symbol *s : symtab->expSymbols ) {
21622166 auto sym = dyn_cast<Defined>(s);
21632167 if (!sym || !sym->getChunk ())
21642168 continue ;
@@ -2177,9 +2181,9 @@ void Writer::createECChunks() {
21772181 // we should use the #foo$hp_target symbol as the redirection target.
21782182 // First, try to look up the $hp_target symbol. If it can't be found,
21792183 // assume it's a regular function and look for #foo instead.
2180- Symbol *targetSym = ctx. symtab . find ((targetName + " $hp_target" ).str ());
2184+ Symbol *targetSym = symtab-> find ((targetName + " $hp_target" ).str ());
21812185 if (!targetSym)
2182- targetSym = ctx. symtab . find (targetName);
2186+ targetSym = symtab-> find (targetName);
21832187 Defined *t = dyn_cast_or_null<Defined>(targetSym);
21842188 if (t && isArm64EC (t->getChunk ()->getMachine ()))
21852189 exportThunks.push_back ({chunk, t});
@@ -2188,20 +2192,20 @@ void Writer::createECChunks() {
21882192
21892193 auto codeMapChunk = make<ECCodeMapChunk>(codeMap);
21902194 rdataSec->addChunk (codeMapChunk);
2191- Symbol *codeMapSym = ctx. symtab . findUnderscore (" __hybrid_code_map" );
2195+ Symbol *codeMapSym = symtab-> findUnderscore (" __hybrid_code_map" );
21922196 replaceSymbol<DefinedSynthetic>(codeMapSym, codeMapSym->getName (),
21932197 codeMapChunk);
21942198
21952199 CHPECodeRangesChunk *ranges = make<CHPECodeRangesChunk>(exportThunks);
21962200 rdataSec->addChunk (ranges);
21972201 Symbol *rangesSym =
2198- ctx. symtab . findUnderscore (" __x64_code_ranges_to_entry_points" );
2202+ symtab-> findUnderscore (" __x64_code_ranges_to_entry_points" );
21992203 replaceSymbol<DefinedSynthetic>(rangesSym, rangesSym->getName (), ranges);
22002204
22012205 CHPERedirectionChunk *entryPoints = make<CHPERedirectionChunk>(exportThunks);
22022206 a64xrmSec->addChunk (entryPoints);
22032207 Symbol *entryPointsSym =
2204- ctx. symtab . findUnderscore (" __arm64x_redirection_metadata" );
2208+ symtab-> findUnderscore (" __arm64x_redirection_metadata" );
22052209 replaceSymbol<DefinedSynthetic>(entryPointsSym, entryPointsSym->getName (),
22062210 entryPoints);
22072211}
@@ -2294,53 +2298,54 @@ void Writer::setSectionPermissions() {
22942298
22952299// Set symbols used by ARM64EC metadata.
22962300void Writer::setECSymbols () {
2297- if (!isArm64EC (ctx.config .machine ))
2301+ SymbolTable *symtab = ctx.symtabEC ;
2302+ if (!symtab)
22982303 return ;
22992304
23002305 llvm::stable_sort (exportThunks, [](const std::pair<Chunk *, Defined *> &a,
23012306 const std::pair<Chunk *, Defined *> &b) {
23022307 return a.first ->getRVA () < b.first ->getRVA ();
23032308 });
23042309
2305- Symbol *rfeTableSym = ctx. symtab . findUnderscore (" __arm64x_extra_rfe_table" );
2310+ Symbol *rfeTableSym = symtab-> findUnderscore (" __arm64x_extra_rfe_table" );
23062311 replaceSymbol<DefinedSynthetic>(rfeTableSym, " __arm64x_extra_rfe_table" ,
23072312 pdata.first );
23082313
23092314 if (pdata.first ) {
23102315 Symbol *rfeSizeSym =
2311- ctx. symtab . findUnderscore (" __arm64x_extra_rfe_table_size" );
2316+ symtab-> findUnderscore (" __arm64x_extra_rfe_table_size" );
23122317 cast<DefinedAbsolute>(rfeSizeSym)
23132318 ->setVA (pdata.last ->getRVA () + pdata.last ->getSize () -
23142319 pdata.first ->getRVA ());
23152320 }
23162321
23172322 Symbol *rangesCountSym =
2318- ctx. symtab . findUnderscore (" __x64_code_ranges_to_entry_points_count" );
2323+ symtab-> findUnderscore (" __x64_code_ranges_to_entry_points_count" );
23192324 cast<DefinedAbsolute>(rangesCountSym)->setVA (exportThunks.size ());
23202325
23212326 Symbol *entryPointCountSym =
2322- ctx. symtab . findUnderscore (" __arm64x_redirection_metadata_count" );
2327+ symtab-> findUnderscore (" __arm64x_redirection_metadata_count" );
23232328 cast<DefinedAbsolute>(entryPointCountSym)->setVA (exportThunks.size ());
23242329
2325- Symbol *iatSym = ctx. symtab . findUnderscore (" __hybrid_auxiliary_iat" );
2330+ Symbol *iatSym = symtab-> findUnderscore (" __hybrid_auxiliary_iat" );
23262331 replaceSymbol<DefinedSynthetic>(iatSym, " __hybrid_auxiliary_iat" ,
23272332 idata.auxIat .empty () ? nullptr
23282333 : idata.auxIat .front ());
23292334
2330- Symbol *iatCopySym = ctx. symtab . findUnderscore (" __hybrid_auxiliary_iat_copy" );
2335+ Symbol *iatCopySym = symtab-> findUnderscore (" __hybrid_auxiliary_iat_copy" );
23312336 replaceSymbol<DefinedSynthetic>(
23322337 iatCopySym, " __hybrid_auxiliary_iat_copy" ,
23332338 idata.auxIatCopy .empty () ? nullptr : idata.auxIatCopy .front ());
23342339
23352340 Symbol *delayIatSym =
2336- ctx. symtab . findUnderscore (" __hybrid_auxiliary_delayload_iat" );
2341+ symtab-> findUnderscore (" __hybrid_auxiliary_delayload_iat" );
23372342 replaceSymbol<DefinedSynthetic>(
23382343 delayIatSym, " __hybrid_auxiliary_delayload_iat" ,
23392344 delayIdata.getAuxIat ().empty () ? nullptr
23402345 : delayIdata.getAuxIat ().front ());
23412346
23422347 Symbol *delayIatCopySym =
2343- ctx. symtab . findUnderscore (" __hybrid_auxiliary_delayload_iat_copy" );
2348+ symtab-> findUnderscore (" __hybrid_auxiliary_delayload_iat_copy" );
23442349 replaceSymbol<DefinedSynthetic>(
23452350 delayIatCopySym, " __hybrid_auxiliary_delayload_iat_copy" ,
23462351 delayIdata.getAuxIatCopy ().empty () ? nullptr
@@ -2695,6 +2700,23 @@ void Writer::prepareLoadConfig(SymbolTable &symtab, T *loadConfig) {
26952700 }
26962701 }
26972702
2703+ IF_CONTAINS (CHPEMetadataPointer) {
2704+ // On ARM64X, only the EC version of the load config contains
2705+ // CHPEMetadataPointer. Copy its value to the native load config.
2706+ if (ctx.hybridSymtab && !symtab.isEC () &&
2707+ ctx.hybridSymtab ->loadConfigSize >=
2708+ offsetof (T, CHPEMetadataPointer) + sizeof (T::CHPEMetadataPointer)) {
2709+ OutputSection *sec =
2710+ ctx.getOutputSection (ctx.hybridSymtab ->loadConfigSym ->getChunk ());
2711+ uint8_t *secBuf = buffer->getBufferStart () + sec->getFileOff ();
2712+ auto hybridLoadConfig =
2713+ reinterpret_cast <const coff_load_configuration64 *>(
2714+ secBuf +
2715+ (ctx.hybridSymtab ->loadConfigSym ->getRVA () - sec->getRVA ()));
2716+ loadConfig->CHPEMetadataPointer = hybridLoadConfig->CHPEMetadataPointer ;
2717+ }
2718+ }
2719+
26982720 if (ctx.config .guardCF == GuardCFLevel::Off)
26992721 return ;
27002722 RETURN_IF_NOT_CONTAINS (GuardFlags)
0 commit comments