summaryrefslogtreecommitdiff
path: root/common/init
diff options
context:
space:
mode:
authorYao Zi <[email protected]>2025-04-27 14:50:11 +0000
committerLeo Yu-Chi Liang <[email protected]>2025-05-21 16:46:16 +0800
commit307666be28db0d89cbdcfafd2cf0e0cf5bf386db (patch)
tree318ba2cf0407a5e5bd51234177ff04aa03f8bd40 /common/init
parent60163080949a57ba28bc10cb599dc2a9b53c75c4 (diff)
riscv: Access gd with inline assembly when building with LTO or Clang
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 <[email protected]> Signed-off-by: Yao Zi <[email protected]> Reviewed-by: Leo Yu-Chi Liang <[email protected]>
Diffstat (limited to 'common/init')
-rw-r--r--common/init/board_init.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/common/init/board_init.c b/common/init/board_init.c
index a06ec1caa2c..2a6f39f51ad 100644
--- a/common/init/board_init.c
+++ b/common/init/board_init.c
@@ -13,8 +13,11 @@
DECLARE_GLOBAL_DATA_PTR;
-/* Unfortunately x86 or ARM can't compile this code as gd cannot be assigned */
-#if !defined(CONFIG_X86) && !defined(CONFIG_ARM)
+/*
+ * Unfortunately x86, ARM and RISC-V can't compile this code as gd is defined
+ * as macro and cannot be assigned.
+ */
+#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
__weak void arch_setup_gd(struct global_data *gd_ptr)
{
gd = gd_ptr;