[PATCH 2/2] riscv: Access gd with inline assembly when building with LTO or Clang

Leo Liang ycliang at andestech.com
Mon May 12 11:36:09 CEST 2025


On Sun, Apr 27, 2025 at 02:50:11PM +0000, Yao Zi wrote:
> Similar to AArch64's case, Clang may wrongly fold accesses to gd pointer
> which is defined with register qualifier into constants, breaking
> various components.
> 
> This patch defines gd as a macro when building with Clang or LTO, which
> expands to get_gd() that accesses gp pointer in assembly, making RISC-V
> ports function properly and preparing for introduction of LTO in the
> future. Board initialization code is also adapted for non-assignable gd.
> 
> Reported-by: Nathaniel Hourt <I at nathaniel.land>
> Signed-off-by: Yao Zi <ziyao at disroot.org>
> ---
>  arch/riscv/cpu/cpu.c                 |  6 ++++++
>  arch/riscv/include/asm/global_data.h | 19 +++++++++++++++++++
>  common/board_r.c                     |  4 +++-
>  common/init/board_init.c             |  7 +++++--
>  4 files changed, 33 insertions(+), 3 deletions(-)

Reviewed-by: Leo Yu-Chi Liang <ycliang at andestech.com>


More information about the U-Boot mailing list