-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[AVR] Fix a crash in AVRInstrInfo::insertIndirectBranch #67324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
To make this test easier to read (and less likely to not work anymore in the future due to unrelated changes), I think it would be better to write the test like branch-relaxation.ll and jmp-long.ll (lots of "nop" instructions between from the jump instruction to the branch target). |
Done. I have modified |
This patch just fixes the crash, but incorrect code is still generated, and the assembler or the linker will report "out of range". A full solution would be introducing "code model", like riscv did when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Probably unnecessary. I think the only chips that are limited to
As for the current fix:
That seems like a reasonable solution to me. I hit this while compiling parts of the libc that will be too large anyway for these small chips, but it's nice to be able to compile those parts anyway. If those large functions are linked, they will result in a linker error anyway because they don't fit the flash space. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable solution. The only thing I'm worried about is what the linker will actually do. Will it report an out of range error? Do we have tests for this?
With the attached b.s, an linker error is reported as
but it is not easy to add such a test into my patch. |
The b.s is attached here. |
And what about the LLVM linker (lld)? Does it report a similar error?
No I don't think it should be part of the test, just something to verify before committing. If we add a test it would be a separate test to LLD that checks whether an error is generated as we would expect. In any case, I think this patch is ready to go from my POV, but perhaps others will like to take a look as well. |
Checked avr-gcc, and it behaves the same as this patch: it emits an |
We emit a `RJMP` and let the linker to report "out of range", other than crash or silently emit incorrect assembly code. Fixes #67042
LLD checks range for conditional branch: https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/AVR.cpp#L233, but does not for RJMP: https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/AVR.cpp#L240C8-L240C22 I will fix that in another patch. |
Fixes #67042