[llvm] [AVR] Force relocations for non-encodable jumps (PR #121498)

Ben Shi via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 01:18:35 PST 2025


================
@@ -512,14 +535,25 @@ bool AVRAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
 bool AVRAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
                                           const MCFixup &Fixup,
                                           const MCValue &Target,
+                                          const uint64_t Value,
                                           const MCSubtargetInfo *STI) {
   switch ((unsigned)Fixup.getKind()) {
   default:
     return Fixup.getKind() >= FirstLiteralRelocationKind;
+
   case AVR::fixup_7_pcrel:
-  case AVR::fixup_13_pcrel:
-    // Always resolve relocations for PC-relative branches
-    return false;
+  case AVR::fixup_13_pcrel: {
+    uint64_t ValueEx = Value;
+    uint64_t Size = AVRAsmBackend::getFixupKindInfo(Fixup.getKind()).TargetSize;
+
+    // If the jump is too large to encode it, fall back to a relocation.
----------------
benshi001 wrote:

For your example `main.c` and `library.c` (with `small()` and `large()`), the `large()` function always contains illegal `RJMP`, and this `large()` can never be called. In my opinion, it would be better to let the author of `library.c` (author-A) known that at compile phase, not let the author of `main.c` (author-B) report to author-A.

It is author-A's responsibility to fix his code, a compiler should report any potential bug, not walk around it.

https://github.com/llvm/llvm-project/pull/121498


More information about the llvm-commits mailing list