[lld] [lld] Add support for EC code map. (PR #69101)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 11 07:32:48 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;
+ }
+ }
----------------
cjacek wrote:
It is valid for code range to span over multiple sections of the same type. I will add a test covering that case.
I retested more corner cases with MS link.exe, because I noticed that the isCodeSection may not be exactly right. As implemented in #69100 and #70722, data chunks properties are preserved when merging into code sections, code chunks may be preserved when merging into data sections. That's indeed the case, although I ran
https://github.com/llvm/llvm-project/pull/69101
More information about the llvm-commits
mailing list