[U-Boot] ARMv8 linking: how to properly accommodate the exception vector table?

Alexander Graf agraf at suse.de
Wed Feb 20 13:52:32 UTC 2019


On 02/20/2019 01:36 PM, Alexander Graf wrote:
> On 02/20/2019 12:19 PM, Andre Przywara wrote:
>> Hi,
>>
>> I was looking for a solution to some linker problem and was hoping that
>> some linker cracks here on the list have some idea:
>>
>> The generic ARMv8 ("arm64") code provides an exception vector table,
>> which architecturally requires a 2KB alignment. At the moment we don't
>> take any special measures about it, so we end up with a random padding
>> between 0 and 2044 bytes before the table:
>>
>> 0 bytes                   n * 2KB
>> |                            |
>>   <code before table><padding>|<vector table> <code after table>
>>
>> The vector table takes up a bit more than 1KB, so we happily use the
>> space after that and can't afford to just waste the rest of the 2KB slot
>> (by putting it at the end of the code, for instance).
>>
>> Depending on the link order some code ends up before the table, other
>> behind it, with seemingly random effects on the resulting code size, due
>> to the padding.
>>
>> This is quite annoying with the Allwinner SPLs, which are quite tight.
>> On the H6 it seems like most code additions lead to a build break at the
>> moment due to this, which needs fixing. Actually it should affect all
>> ARMv8 boards, but it might just not be critical for most of them.
>>
>>
>> I was wondering if we can tell the linker in the (SPL) linker script to
>> drop code into *two* possible regions, so that we can use a fixed
>> location for the vector table somewhere in the middle, and tell the
>> linker to fill up the space before *and* after that at will, without
>> requiring us to specify the exact link order of code.
>> I can *manually* arrange the code to make best use of the space, but
>> this is very fragile and breaks every so often, and is thus not 
>> sustainable.
>>
>> Another idea would be to put the exception table at the end of the image
>> (at least for sunxi), then fill the remaining <1KB with some data. But I
>> didn't find a low hanging fruit data block which fills the gap nicely.
>>
>> If anyone has any ideas on how to overcome this, I would be very 
>> grateful
>> to hear about it.
>
> Can't you just put the exception table at 0x0 and make the first 
> instruction be the "b reset" from start.S? Then (if we need that 
> vector, I don't know) overwrite it with the real exception vector down 
> the road.

A few more ideas:

* Set CONFIG_ARMV8_SPL_EXCEPTION_VECTORS=n for H6
* Move "init" code to the lower 2kb, then dynamically generate vectors 
at a post-init step and set vbar to _start

Realistically, CONFIG_ARMV8_SPL_EXCEPTION_VECTORS is currently broken in 
the tree though (ifdefs on ...ARMV8__SPL...), so we may as well default 
it to n :). That should save quite some space across the board.


Alex



More information about the U-Boot mailing list