[lld] [ELF] -r: Synthesize R_RISCV_ALIGN at input section start (PR #151639)
Daniel Thornburgh via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 14:38:28 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;
----------------
mysterymath wrote:
This might be a bit clearer as `bool alignRel = llvm::any_of(rels, [](RelTy &rel) { return rel.r_offset == 0 && rel.getType(false) == R_RISCV_ALIGN;});`. This also directly expresses "there is an align relocation with offset 0", which may be close enough to the comment to make it redundant. One could also fold this directly into the `else if`, but that might make it too difficult to read.
https://github.com/llvm/llvm-project/pull/151639
More information about the llvm-commits
mailing list