This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add WasForced parameter to MCAsmBackend::fixupNeedsRelaxationAdvanced
ClosedPublic

Authored by shiva0217 on May 1 2018, 10:36 PM.

Details

Summary

For RISCV branch instructions, we need to preserve relocation types when linker relaxation enabled, so then linker could modify offset when the branch offsets changed.

We preserve relocation types by define shouldForceRelocation. IsResolved return by evaluateFixup will always false when shouldForceRelocation return true. It will make RISCV MC Branch Relaxation always relax 16-bit branches to 32-bit form, even if the symbol actually could be resolved.

To avoid 16-bit branches always relax to 32-bit form when linker relaxation enabled, we add a new parameter WasForced to indicate that the symbol actually couldn't be resolved and not forced by shouldForceRelocation return true.

RISCVAsmBackend::fixupNeedsRelaxationAdvanced could relax branches with unresolved symbols by (!IsResolved && !WasForced).

RISCV MC Branch Relaxation is needed because RISCV could perform 32-bit to 16-bit transformation in MC layer.

The patch is based on the discussion in https://reviews.llvm.org/D44887.

Diff Detail

Repository
rL LLVM