[lld] lld: add support for NOCROSSREFS(_TO) (PR #95714)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 11:01:11 PDT 2024


================
@@ -2358,3 +2358,62 @@ template void elf::scanRelocations<ELF32LE>();
 template void elf::scanRelocations<ELF32BE>();
 template void elf::scanRelocations<ELF64LE>();
 template void elf::scanRelocations<ELF64BE>();
+
+static bool isNoCrefFromSection(const CrossRefList &list,
+                                const OutputSection *section) {
+  const auto *begin =
+      list.firstOnly ? list.refs.begin() + 1 : list.refs.begin();
+
+  return std::find(begin, list.refs.end(), section->name) != list.refs.end();
+}
+
+static bool isNoCrefToSection(const CrossRefList &list,
+                              const OutputSection *section) {
+  if (list.firstOnly)
+    return list.refs[0] == section->name;
+
+  return std::find(list.refs.begin(), list.refs.end(), section->name) !=
+         list.refs.end();
+}
+
+void elf::checkNoCrossRefs() {
+  // Basic brute-force algorithm, since in reality NOCROSSRES lists are quite
+  // small.
+  //
+  // Idea is to traverse all relocations in all sections and report if
----------------
smithp35 wrote:

Does this include synthetic sections as well? These sections do not have an object file?

It may be worth doing something similar to the Thunk creation and iterating through OutputSection contents via InputSectionDescriptions. This may permit better ordering of diagnostics too as all the relocations from an output section will be traversed together.


See https://github.com/llvm/llvm-project/blob/main/lld/ELF/Relocations.cpp#L1864

For Thunks we deliberately only go through executable sections.

For CROSSREFS is it worth restricting to SHF_ALLOC sections, or is the person expected to just not do that.




https://github.com/llvm/llvm-project/pull/95714


More information about the llvm-commits mailing list