public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Branch instructions that depend on target distance
@ 2020-02-24 11:05 Petr Tesarik
  2020-02-24 11:14 ` Jozef Lawrynowicz
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Petr Tesarik @ 2020-02-24 11:05 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1805 bytes --]

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'

I can provide a minimal test case and report a bug if you want...

Developers work around the issue by rewriting their code when they are
bitten by this, but it is less than optimal, because you cannot really
get rid of all inline assembly, and it's in general unpredictable where
these inline asm() blocks will be placed by the compiler.

OTOH, the avr backend is pretty outdated, so there may be a better
alternative that I'm just not seeing. Any hints?

Background: There is a port of the VC4 port of the LK embedded kernel
[2]. I have tried to build that kernel with optimization turned on, but
I'm getting:

compiling kernel/thread.c
/tmp/ccJFdnfX.s: Assembler messages:
/tmp/ccJFdnfX.s:1451: Error: operand out of range (64 not between -64 and 63)

That's because there is an inline "di" (disable interrupts) instruction
inside a conditional statement in thread_yield(), which causes this
off-by-one miscalculation.

Petr T

[1] https://github.com/itszor/gcc-vc4
[2] https://github.com/librerpi/lk

[-- Attachment #2: Digitální podpis OpenPGP --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-02-24 15:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 11:05 Branch instructions that depend on target distance Petr Tesarik
2020-02-24 11:14 ` Jozef Lawrynowicz
2020-02-24 11:36   ` Petr Tesarik
2020-02-24 15:12     ` Jeff Law
2020-02-24 11:29 ` Andreas Schwab
2020-02-24 11:41   ` Petr Tesarik
2020-02-24 11:51     ` Andreas Schwab
2020-02-24 12:03       ` Alexander Monakov
2020-02-24 12:24         ` Julian Brown
2020-02-24 12:32         ` Petr Tesarik
2020-02-24 11:43 ` Andrew Stubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).