From: Yao Zi <me@ziyao.cc>
To: Michal Simek <michal.simek@amd.com>, <u-boot@lists.denx.de>,
<git@amd.com>
Cc: Ben Dooks <ben.dooks@codethink.co.uk>,
Leo <ycliang@andestech.com>, Rick Chen <rick@andestech.com>,
Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH] riscv: Disable -fpic for SPL builds
Date: Fri, 1 May 2026 12:20:37 +0000 [thread overview]
Message-ID: <afSalS7aSMP1MHIV@pie> (raw)
In-Reply-To: <6ada697cef076eaed1971c4877c402a91ad5cb48.1777550346.git.michal.simek@amd.com>
On Thu, Apr 30, 2026 at 01:59:07PM +0200, Michal Simek wrote:
> When building U-Boot SPL for RISC-V with position-independent code
> (-fpic), the linker fails with relocation errors like:
>
> relocation truncated to fit: R_RISCV_PCREL_HI20 against `symbol'
>
> This occurs because SPL's linker script places .bss in a separate
> memory region (.bss_mem) from .text/.data (.spl_mem). With -fpic,
> accessing global variables uses PC-relative GOT addressing, which
> fails when the distance between code and data exceeds the 20-bit
> signed offset limit of R_RISCV_PCREL_HI20.
This sounds strange. R_RISCV_GOT_HI20 instead of R_RISCV_PCREL_HI20
should be used when addressing a variable through GOT in code. Thus I
suspect in your case, the compiler decides to address the .bss variable
PC-relatively, bypassing the GOT, possibly because it's static thus
considered non-preemptible.
Might you provide a reproducer for the problem so we could dig it
further and confirm the root cause?
Best regards,
Yao Zi
> The main U-Boot binary requires -fpic for runtime relocation support,
> but SPL runs from a fixed address and doesn't need position-independent
> code. Disable -fpic for SPL builds while keeping it enabled for the
> main U-Boot image.
>
> spl/u-boot-spl: all -1187 bss +4 data -2631 rodata +2440 text -1000
>
> Signed-off-by: Michal Simek <michal.simek@amd.com>
prev parent reply other threads:[~2026-05-01 12:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 11:59 [PATCH] riscv: Disable -fpic for SPL builds Michal Simek
2026-05-01 10:41 ` Yao Zi
2026-05-04 9:30 ` Michal Simek
2026-05-01 12:20 ` Yao Zi [this message]
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=afSalS7aSMP1MHIV@pie \
--to=me@ziyao.cc \
--cc=ben.dooks@codethink.co.uk \
--cc=git@amd.com \
--cc=michal.simek@amd.com \
--cc=rick@andestech.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=ycliang@andestech.com \
/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.