Skip to content

[RISCV] Relocation truncated to fit with -O0 on very large functions. #87127

Closed
@topperc

Description

@topperc

clang -O0 implicitly passes -mrelax-all. This causes the MC layer to relax all jumps to the longest form possible. Except we don't convert uncompressed relative jumps to indirect since that requires a temporary register.

The CodeGen layer carefully measured the function size and relaxed any branches and unconditional branches that it needed to, but it is not aware of the relaxation the MC layer is going to do for -mrelax-all.

If the function is sufficiently large, relaxing the branches in the MC layer may cause some unconditional jump to go out of range leading to a linking failure.

I believe the branch relaxation was added to the MC layer to make things easier for programmers writing handwritten assembly so they didn't have to worry about the small offset of conditional branches. Maybe we should disable it when assembling CodeGen output?

cc: @preames @MaskRay @jrtc27 @kito-cheng @asb

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions