All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: u-boot@lists.denx.de
Subject: [PATCH] arm64: Add support for bigger u-boot when CONFIG_POSITION_INDEPENDENT=y
Date: Wed, 2 Sep 2020 16:51:36 +0200	[thread overview]
Message-ID: <4b1f5f95-3c69-0b8c-dc96-809c7efbac99@xilinx.com> (raw)
In-Reply-To: <67147ba5-4bcc-2f2d-d979-17d4798198e0@arm.com>

Hi,

On 02. 09. 20 16:43, Andr? Przywara wrote:
> On 02/09/2020 12:15, Michal Simek wrote:
> 
> Hi,
> 
>> From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
>>
>> When U-Boot binary exceeds 1MB with CONFIG_POSITION_INDEPENDENT=y
>> compilation error is shown:
>> /mnt/disk/u-boot/arch/arm/cpu/armv8/start.S:71:(.text+0x3c): relocation
>> truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol `__rel_dyn_end'
>> defined in .bss_start section in u-boot.
>>
>> It is caused by adr instruction which permits the calculation of any byte
>> address within +- 1MB of the current PC.
>> Because U-Boot is bigger then 1MB calculation is failing.
>>
>> The patch is using adrp/add instructions where adrp shifts a signed, 21-bit
>> immediate left by 12 bits (4k page), adds it to the value of the program
>> counter with the bottom 12 bits cleared to zero. Then add instruction
>> provides the lower 12 bits which is offset within 4k page.
>> These two instructions together compose full 32bit offset which should be
>> more then enough to cover the whole u-boot size.
>>
>> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> 
> It's a bit scary that you need more than 1MB, but indeed what you do
> below is the canonical pattern to get the full range of PC relative
> addressing (this is used heavily in Trusted Firmware, for instance).

We have generic u-boot where we are enabling all features which you can
use and it is up to everybody to disable what they don't need. We are at
1MB limit that's why I spot this issue and trying to solve it.

> 
> The only thing to keep in mind is that this assumes that the load
> address of the binary is 4K aligned, so that the low 12 bits of the
> symbol stay the same. I wonder if we should enforce this somehow? But
> the load address is not controlled by the build process (the whole
> purpose of PIE), so that's not doable just in the build system?

That's more question to you if we can enforce is somehow. :-)


> Shall we at least document this? I guess typical load address are
> actually quite well aligned, so it might not be an issue in practice.

maybe note this in Kconfig help for POSITION_INDEPENDENT?
Any other location?

Thanks,
Michal

  reply	other threads:[~2020-09-02 14:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 11:15 [PATCH] arm64: Add support for bigger u-boot when CONFIG_POSITION_INDEPENDENT=y Michal Simek
2020-09-02 14:43 ` André Przywara
2020-09-02 14:51   ` Michal Simek [this message]
2020-09-02 14:53   ` Edgar E. Iglesias
2020-09-02 15:18     ` André Przywara
2020-09-02 15:25       ` Edgar E. Iglesias
2020-09-02 18:59         ` André Przywara
2020-09-03 13:41           ` Michal Simek
2020-09-03 13:52             ` André Przywara
2020-09-03 13:59               ` Edgar E. Iglesias
2020-09-03 14:03                 ` Michal Simek
2020-09-02 16:34 ` Stephen Warren
2020-09-03 13:35   ` Michal Simek
2020-09-03 13:40     ` André Przywara
2020-09-03 15:45       ` Stephen Warren
2020-09-03 19:07         ` Edgar E. Iglesias
2020-09-03 19:10           ` Stephen Warren
2020-09-03 19:12             ` Edgar E. Iglesias

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b1f5f95-3c69-0b8c-dc96-809c7efbac99@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.