[lld] [ELF] -r: Synthesize R_RISCV_ALIGN at input section start (PR #151639)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 22:50:19 PDT 2025


================
@@ -1543,6 +1543,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
 
   uint32_t pass = 0, assignPasses = 0;
   for (;;) {
+    if (ctx.arg.relocatable)
----------------
MaskRay wrote:

For -r, createThunks should not be called. We've missed this in the past. We don't scan relocations for relocatable links, so InputSectionBase::relocations is empty, making createThunks a no-op anyway.

A separate issue is that if a relocatable link combines .text sections into one massive section, it could create internal branches that are out of range.
There's no good solution for this, but it's likely not a problem in practice since people typically use -ffunction-sections.
(You can still end up with many sections of the same name with -fno-unique-section-names (google3 uses it), and -r links will become a problem.)


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


More information about the llvm-commits mailing list