Maximilian Brune has uploaded this change for review.

View Change

util/crossgcc/buildgcc: Compile RISC-V GCC with medany

currently the HiFive Unmatched mainboard produces the following error:
util/crossgcc/xgcc/lib/gcc/riscv64-elf/13.2.0/rv64imafdc/lp64d/libgcc.a(_clzsi2.o): in function `__clzdi2':
util/crossgcc/build-riscv64-elf-GCC/riscv64-elf/rv64imafdc/lp64d/libgcc/../../../../../gcc-13.2.0/libgcc/libgcc2.c:690:(.text+0x1e): relocation truncated to fit: R_RISCV_HI20 against symbol `__clz_tab' defined in .rodata section in /home/max/coreboot/coreboot-alderlake-p/util/crossgcc/xgcc/lib/gcc/riscv64-elf/13.2.0/rv64imafdc/lp64d/libgcc.a(_clz.o)

This is due to the fact that the libgcc.a library is compiled with the
medlow code model but the mainboards are compiled with the medany code
model.

Changing the code model of the GCC libraries to the medany code model
fixes the issue.

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: If5f07ce034686dd7fec160ea76838507c0ba7fa0
---
M util/crossgcc/buildgcc
1 file changed, 6 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/39/80139/1
diff --git a/util/crossgcc/buildgcc b/util/crossgcc/buildgcc
index 23a5caf..d200378 100755
--- a/util/crossgcc/buildgcc
+++ b/util/crossgcc/buildgcc
@@ -774,6 +774,11 @@
[ -n "$CXX" ] && $CXX --version | grep clang >/dev/null 2>&1 && \
CLANGCXXFLAGS="-fbracket-depth=1024"

+ # standard code model is medlow but all mainboards are compiled with medany code model
+ if [ "${TARGETARCH}" = "riscv64-elf" ]; then
+ CFLAGS_FOR_TARGET_EXTRA="-mcmodel=medany"
+ fi
+
# GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
# both target and host object files.
# There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
@@ -783,7 +788,7 @@
# using C++.
# shellcheck disable=SC2086
CC="$(hostcc target)" CXX="$(hostcxx target)" \
- CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" \
+ CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET_EXTRA} -O2 -Dinhibit_libc" \
CFLAGS="$HOSTCFLAGS $CLANGFLAGS" \
CFLAGS_FOR_BUILD="$HOSTCFLAGS $CLANGFLAGS" \
CXXFLAGS="$HOSTCFLAGS $CLANGCXXFLAGS" \

To view, visit change 80139. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: If5f07ce034686dd7fec160ea76838507c0ba7fa0
Gerrit-Change-Number: 80139
Gerrit-PatchSet: 1
Gerrit-Owner: Maximilian Brune <maximilian.brune@9elements.com>
Gerrit-MessageType: newchange