Branch instructions that depend on target distance
Andrew Stubbs
ams@codesourcery.com
Mon Feb 24 11:43:00 GMT 2020
On 24/02/2020 11:05, Petr Tesarik wrote:
> Hi all,
>
> I'm looking into reviving the efforts to port gcc to VideoCore IV [1].
> One issue I've run into is the need to find out target branch distance
> at compile time. I looked around, and it's not the first one
> architecture with such requirement, but AFAICS it has never been solved
> properly.
>
> For example, AVR tracks instruction length. Later, ret_cond_branch()
> selects between a branch instruction and an inverted branch followed by
> an unconditional jump based on these calculated lengths.
>
> This works great ... until there's some inline asm() statement, for
> which gcc cannot keep track of the length attribute, so it is probably
> taken as zero. Linker then fails with a cryptic message:
>
>> relocation truncated to fit: R_AVR_7_PCREL against `no symbol'
You can probably fix this by implementing the ADJUST_INSN_LENGTH macro
and recognising the inline assembler. See the internals manual.
We encountered similar issues with the recent GCN port, and the correct
solution was to add the length attribute everywhere. The attributes are
often conservative estimates (rather than having extra alternatives for
every possible encoding), so the asm problem is mitigated somewhat, at
the cost of a few "far" branches where they're not strictly necessary.
There were also addition problems because "far" branches clobber the
condition register, and "near" branches do not, but that's another story.
Andrew
More information about the Gcc
mailing list