[lld] [LLD][COFF] Generate X64 thunks for ARM64EC entry points and patchable functions. (PR #105499)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 14:11:47 PDT 2024
================
@@ -1317,6 +1317,70 @@ void LinkerDriver::convertResources() {
f->includeResourceChunks();
}
+void LinkerDriver::maybeCreateECExportThunk(StringRef name, Symbol *&sym) {
+ Defined *def;
+ if (!sym)
+ return;
+ if (auto undef = dyn_cast<Undefined>(sym))
+ def = undef->getWeakAlias();
+ else
+ def = dyn_cast<Defined>(sym);
+ if (!def)
+ return;
+
+ if (def->getChunk()->getArm64ECRangeType() != chpe_range_type::Arm64EC)
+ return;
+ StringRef expName;
+ if (auto mangledName = getArm64ECMangledFunctionName(name))
+ expName = saver().save("EXP+" + *mangledName);
+ else
+ expName = saver().save("EXP+" + name);
+ sym = addUndefined(expName);
+ if (auto undef = dyn_cast<Undefined>(sym)) {
+ if (!undef->getWeakAlias()) {
+ auto thunk = make<ECExportThunkChunk>(def);
+ replaceSymbol<DefinedSynthetic>(undef, undef->getName(), thunk);
+ }
+ }
+}
+
+void LinkerDriver::createECExportThunks() {
+ // Check if EXP+ symbols have corresponding $hp_target symbols and use them
+ // to create export thunks when available.
+ for (auto &s : ctx.symtab.expSymbols) {
+ if (!s->isUsedInRegularObj)
+ continue;
+ auto targetName = s->getName().substr(strlen("EXP+")) + "$hp_target";
+ Symbol *expSym = ctx.symtab.find(toString(targetName));
----------------
mstorsjo wrote:
Hmm. What data type is `targetName` here, really? Is it a `Twine`? In that case, we generally tend to not store Twines anywhere (especially on the heap, but ideally not on the stack either), but only use them as function parameters. IIRC Twines point towards the intermediate objects used within the `A + B` expression, which only are valid until the end of that statement.
I.e., it'd be safer if you'd wrap the `toString()` (where is that function defined for this use btw?) around the expression when defining `targetName` instead.
Also, I'm a bit unsure if `expSym` is the best name here, as this symbol isn't for the `EXP+name` symbol, but for the `$hp_target` symbol.
https://github.com/llvm/llvm-project/pull/105499
More information about the llvm-commits
mailing list