[lld] [lld] Add support for EC code map. (PR #69101)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 11 14:30:54 PST 2023
================
@@ -528,6 +531,53 @@ bool Writer::createThunks(OutputSection *os, int margin) {
return addressesChanged;
}
+// Create a code map for CHPE metadata.
+void Writer::createECCodeMap() {
+ if (!isArm64EC(ctx.config.machine))
+ return;
+
+ // Clear the map in case we were're recomputing the map after adding
+ // a range extension thunk.
+ codeMap.clear();
+
+ std::optional<chpe_range_type> lastType;
+ Chunk *first, *last;
+
+ auto closeRange = [&]() {
+ if (lastType) {
+ codeMap.push_back({first, last, *lastType});
+ lastType.reset();
+ }
+ };
+
+ for (OutputSection *sec : ctx.outputSections) {
+ if (!sec->isCodeSection()) {
+ closeRange();
+ continue;
+ }
+
+ for (Chunk *c : sec->chunks) {
+ // Skip empty section chunks. MSVC does not seem to do that and
+ // generates empty code ranges in some cases.
+ if (isa<SectionChunk>(c) && !c->getSize())
+ continue;
+
+ std::optional<chpe_range_type> chunkType = c->getArm64ECRangeType();
+ if (chunkType != lastType) {
+ closeRange();
+ first = c;
+ lastType = chunkType;
+ }
+ last = c;
+ }
+ }
----------------
mstorsjo wrote:
Oh, I overlooked the ` if (!sec->isCodeSection()) { closeRange(); continue; }` bit in the previous version - I guess that would have covered the case I thougth about. But with that removed, I guess this also looks good. Thanks!
https://github.com/llvm/llvm-project/pull/69101
More information about the llvm-commits
mailing list