[llvm] [AVR] Force relocations for non-encodable jumps (PR #121498)
Patryk Wychowaniec via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 3 01:32:24 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.
----------------
Patryk27 wrote:
> [...] always contains illegal `RJMP` [...]
Not always, only for some targets - e.g. the code might be invalid for ATtiny88, but fine for ATmega328.
Forcing programmers to guard their code with extra compile-time pragmas is impractical, since the programmer can't possibly know which functions end up being too large - it depends on optimizations, feature flags, phases of the moon etc. (e.g. a function can be too large when compiling with `-O2`, but fine with `-Os`)
It would also require changes across entire ecosystems - from Rust's standard library to random packages on GitHub, that's just impractical and will cause people to keep using older toolchains, since "after I bump the toolchain version, my code stops compiling for seemingly no reason whatsoever".
Note that what you're proposing is essentially offloading an operation that's very easy for a linker to do ("this function is too big, fix it") to programmers, which can't possibly have the entire universe in their head (when writing a function, would you be able to say it's fine for ATtiny88, but not for ATtiny84?).
https://github.com/llvm/llvm-project/pull/121498
More information about the llvm-commits
mailing list