MCExpr::evaluateAsAbsolute has a longstanding bug. When the MCAssembler is
non-null and the MCAsmLayout is null, it may incorrectly fold A-B even if A and
B are separated by a linker-relaxable instruction. This behavior can suppress
some ADD/SUB relocations and lead to wrong results if the linker performs
relaxation.
To fix the bug, ensure that linker-relaxable instructions only appear at the end
of an MCDataFragment, thereby making them terminate the fragment. When computing
A-B, suppress folding if A and B are separated by a linker-relaxable
instruction.
- .subsection now correctly give errors for non-foldable expressions.
- gen-dwarf.s will pass even if we add back the .debug_line or .eh_frame/.debug_frame code from D150004
- This will fix suppressed relocation when we add R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128.
In the future, we should investigate the desired behavior for
MCExpr::evaluateAsAbsolute when both MCAssembler and MCAsmLayout are non-null.
(Note: MCRelaxableFragment is only for assembler-relaxation. If we ever need
linker-relaxable MCRelaxableFragment, we would need to adjust RISCVMCExpr.cpp
(D58943/D73211).)
Depends on D153096
I assume the point of labelling this as RISC-V thing is to note that it hasn't been put to use across multiple targets. So perhaps "Fixup kind used for linker relaxation. Currently only used by RISC-V" might be a better description? (i.e. in theory general code, but hasn't been used in practice outside of one target).