This issue is found by build llvm-testsuite with -Oz, linker will complain
dangerous relocation: %pcrel_lo missing matching %pcrel_hi and that
turn out cause by we outlined pcrel-lo, but leave pcrel-hi there, that's
not problem in general, but the problem is they put into different section, they
pcrel-hi and pcrel-lo pair (e.g. AUIPC+ADDI) *MUST* put be present in same
section due to the implementation.
Outlined function will put into .text name, but the source functions
will put in .text.<function-name> if function-section is enabled or the
function has comdat attribute.
There are few solutions for this issue:
- Always disallow instructions with pcrel-lo flags.
- Only disallow instructions with pcrel-lo flags that when function-section is enabled or this function has comdat attribute.
- Check the corresponding instruction with pcrel-high also included in the outlining candidate sequence or not, and allow that only when pcrel-high is included in the outlining candidate.
First one is most conservative, that might lose some optimization
opportunities, and second one could save those opportunities, and last
one is hard to implement, and don't have any benefits since pcrel-high
are using different label even accessing same symbol.
Use custom section name might also cause this problem, but that already
filtered by RISCVInstrInfo::isFunctionSafeToOutlineFrom.
Nit: This line can be merged with line 1324, I think.