[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Commit 'x86-64: Fix calls via absolute function point

From: Daniel Glöckner
Subject: Re: [Tinycc-devel] Commit 'x86-64: Fix calls via absolute function pointers' makes 07 test fail on ARM
Date: Sat, 22 Dec 2018 11:50:46 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

On Thu, Dec 20, 2018 at 08:48:17AM +0100, Christian Jullien wrote:
>  * At least on ARM (like RPi), zfunc below fails with something like:
>  * +tcc: error: can't relocate value at 1ef93bc,1

> void zfunc()
> {
>    ((void (*)(void))0) ();
> }

The issue is that TCC does not know how to encode an absolute address
in the BL instruction. BL is always a relative call within +/- 32MB.
GCC generates a "veener" (aka trampoline) during linking if the link
target turns out to be outside of this range. For calls to absolute
addresses this is "LDR PC, [PC, #-4]" followed by the address.

We might also have this problem when we have to link a binary with a
.text section bigger than 32 MB. We could use the same veener in that
case, but if we aim for position independent code, we need one more
instruction: "LDR IP, [PC] ; ADD PC, PC, IP ; .word target - 0f ; 0:"

I have not looked at the code, but I believe it will be difficult to
insert the veeners between sections after the linker has made a plan
at which address to place the sections. We might also need several
iterations since adding veeners might increase the distance for calls
or branches beyond 32MB that were barely within 32MB without veeners.

Best regards,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]