[lld] [ELF] -r: Synthesize R_RISCV_ALIGN at input section start (PR #151639)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 7 08:47:51 PDT 2025
================
@@ -959,6 +970,116 @@ bool RISCV::relaxOnce(int pass) const {
return changed;
}
+// If the section alignment is >= 4, advance `dot` to insert NOPs and synthesize
+// an ALIGN relocation. Otherwise, return false to use default handling.
+template <class ELFT, class RelTy>
+bool RISCV::synthesizeAlignOne(uint64_t &dot, InputSection *sec,
+ Relocs<RelTy> rels) {
+ if (!baseSec) {
+ // Record the first section with RELAX relocations.
+ for (auto rel : rels) {
+ if (rel.getType(false) == R_RISCV_RELAX) {
+ baseSec = sec;
+ break;
+ }
+ }
+ } else if (sec->addralign >= 4) {
+ // If the alignment is >= 4 and the section does not start with an ALIGN
+ // relocation, synthesize one.
+ bool alignRel = false;
+ for (auto rel : rels)
+ if (rel.r_offset == 0 && rel.getType(false) == R_RISCV_ALIGN)
+ alignRel = true;
+ if (!alignRel) {
+ synthesizedAligns.emplace_back(dot - baseSec->getVA(),
+ sec->addralign - 2);
+ dot += sec->addralign - 2;
+ return true;
+ }
+ }
+ return false;
+}
+
+// Finalize the relocation section by appending synthesized ALIGN relocations
+// after processing all input sections.
+template <class ELFT, class RelTy>
+void RISCV::synthesizeAlignEnd(uint64_t &dot, InputSection *sec,
----------------
MaskRay wrote:
Right. There are two phases. My main goal is to reduce the number of virtual functions and limit RISC-V's "pollution"/impact on `class Target`..
https://github.com/llvm/llvm-project/pull/151639
More information about the llvm-commits
mailing list