Alternative to D125036. Implement R_RISCV_ALIGN relaxation so that we can handle
-mrelax object files (i.e. -mno-relax is no longer needed) and creates a
framework for future relaxation.
relaxAux is placed in a union with InputSectionBase::jumpInstrMod, storing
auxiliary information for relaxation. In the first pass, relaxAux is allocated.
The main data structure is relocDeltas: when referencing relocations[i], the
actual offset is r_offset - (i ? relocDeltas[i-1] : 0).
relaxOnce performs one relaxation pass. It computes relocDeltas for all text
section. Then, adjust st_value/st_size for symbols relative to this section
based on SymbolAnchor. bytesDropped is set so that assignAddresses knows
that the size has changed.
Run relaxOnce in the finalizeAddressDependentContent loop to wait for
convergence of text sections and other address dependent sections (e.g.
SHT_RELR). Note: extrating relaxOnce into a separate loop works for many cases
but has issues in some linker script edge cases.
After convergence, compute section contents: shrink the NOP sequence of each
R_RISCV_ALIGN as appropriate. Instead of deleting bytes, we run a sequence of
memcpy on the content delimitered by relocation locations. For R_RISCV_ALIGN let
the next memcpy skip the desired number of bytes. Section content computation is
parallelizable, but let's ensure the implementation is mature before
optimizations. Technically we can save a copy if we interleave some code with
OutputSection::writeTo, but let's not pollute the generic code (we don't have
templated relocation resolving, so using conditions can impose overhead to
non-RISCV.)
Tested:
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- LLVM=1 defconfig all
built kernel is bootable.
ALIGN is not a hint, it's a requirement (as opposed to R_RISCV_RELAX, which is a true hint). I would suggest separating these two notions at the RelExpr level, then the config->relax check to skip R_RISCV_RELAX in the CALL(_PLT) patch can instead be done at the generic level rather than in the target.