diff --git a/meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc b/meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc
index 348bd1df18803448101c9a6c9d730f529ea4da12..e9066274e80465b17f909b46eb138bf8554a3a4f 100644
--- a/meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc
+++ b/meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc
@@ -47,6 +47,15 @@ ARCH_FLAGS_FOR_TARGET += "-isystem${STAGING_DIR_TARGET}${target_includedir}"
 do_configure_prepend () {
 	install -d ${RECIPE_SYSROOT}${target_includedir}
 	touch ${RECIPE_SYSROOT}${target_includedir}/limits.h
+
+	if ! echo ${@d.getVar("TARGET_OS")} |grep -qi linux; then
+		# Building Zephyr with DWARF-5 is problematic because
+		# its kernel tests use pyelftools, which has incomplete
+		# DWARF-5 support (even after applying preliminary
+		# support patches). Use DWARF-4 on Zephyr and FreeRTOS
+		# for the time being.
+		sed -i -e 's,Var(dwarf_version) Init(5),Var(dwarf_version) Init(4),' ${S}/gcc/common.opt
+	fi
 }
 
 do_compile () {