From f5f47b3340a8d490243640ff8fe6aa78aae9503d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?=
 <bernhard.rosenkraenzer.ext@huawei.com>
Date: Thu, 21 Oct 2021 22:40:17 +0200
Subject: [PATCH] gcc: Use DWARF-4 by default on non-Linux targets
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Support for DWARF-5 is incomplete on Zephyr due to its reliance
on pyelftools for tests.
Default to DWARF-4 on non-Linux targets for the time being.

Signed-off-by: Bernhard Rosenkränzer <bernhard.rosenkraenzer.ext@huawei.com>
---
 meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc b/meta-oniro-staging/recipes-devtools/gcc/gcc-cross.inc
index 348bd1df..e9066274 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 () {
-- 
GitLab