This is the mail archive of the
mailing list for the GCC project.
Re: Branch instructions that depend on target distance
- From: Andrew Stubbs <ams at codesourcery dot com>
- To: Petr Tesarik <ptesarik at suse dot cz>, <gcc at gcc dot gnu dot org>
- Date: Mon, 24 Feb 2020 11:43:41 +0000
- Subject: Re: Branch instructions that depend on target distance
- Ironport-sdr: LHN/1f7C2+LNall78ItKXL40a+4chytba6aYMR2j4G+oGBR0mjbDcF7X0CWENzS53ZfZ6EtTDH 2XNvETstBXj7LO8dDtpDq2Y4GzdcC+owtMNyN7VV5hT2JzxtUkmvZceedBMcLnjiK9sIbw+CXj PT/uFe58Ll97+cuo9z3EpilbY392NHeqNyt/Ha25U5xuU2WP3vGcjX16D6TbDXdaE864+0H2d1 hfL3MAX5FIofNrPKWNshK1wNMfA2hI8gWyvC4fT9X0wUXdn3Kvq0DSDCjcRpItxVMtij/eVIFs M9c=
- Ironport-sdr: nz8JoUoxyTgwXDdZgXyOXkKpxI0AZDMvloX9T4y3hBt678Wn8tTtfs1R2Tw/JC9w98/lcRuR4U bUYkrRTBlZR3+zBMo2O/p8WR9STilN5uBsdGrcSDS3D/VMH5EMmW3UoIcZRTPCfz9xnAaO6R1g tHOKHGNfl0eO1GprMjYWvlcrUYNh17PirBqVQMu7UyaCmNVB7fxVrobaFcCbsZZpyrR2BDroJp nT9r8rBTtp6ENrxtATzW3DB/sx8xFasr/9BQDnPyy82+K+EZFsZ7TbCaDbQUVOqhUBi1PBj6O5 Cjs=
- References: <firstname.lastname@example.org>
On 24/02/2020 11:05, Petr Tesarik wrote:
I'm looking into reviving the efforts to port gcc to VideoCore IV .
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
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.