From deeb98da5328c6fbdfc4ad1c7638a205d86f83e7 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Thu, 20 Jan 2022 12:52:39 -0800 Subject: [PATCH] cmake: compiler/xcc: omit -g if needed for Clang Some older versions of XCC Clang would result in the following error during compilation: /tmp/file.s: Assembler messages: /tmp/file.s:20: Error: file number 1 already allocated clang-3.9: error: Xtensa-as command failed with exit code 1 due to a bug in LLVM: https://bugs.llvm.org/show_bug.cgi?id=11740. This is fixed in upstream, https://reviews.llvm.org/D20002, in 2016. However, it seems that it is only fixed after XCC RI-2018.0. Instead of blanket disabling usage of '-g', use an environment variable "XCC_NO_G_FLAG" to disable usage of flag '-g' to workaround this issue. This needs to be manually set because there is no way to know which XCC version is being used, and compiler flag checking for '-g' would not result in error (and thus '-g' is not ignored). This is only needed for older XCC Clang. For sufficiently new XCC verisons, there is no need for this. Signed-off-by: Daniel Leung --- cmake/compiler/gcc/compiler_flags.cmake | 12 +++++++----- cmake/compiler/xcc/compiler_flags.cmake | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index bc3f37b2fc5..1921d97dc52 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -162,12 +162,14 @@ check_set_compiler_property(APPEND PROPERTY hosted -fno-freestanding) # gcc flag for a freestandingapplication set_compiler_property(PROPERTY freestanding -ffreestanding) -# Flag to enable debugging -set_compiler_property(PROPERTY debug -g) +if(NOT DEFINED GCC_NO_G_FLAG) + # Flag to enable debugging + set_compiler_property(PROPERTY debug -g) -# GCC 11 by default emits DWARF version 5 which cannot be parsed by -# pyelftools. Can be removed once pyelftools supports v5. -check_set_compiler_property(APPEND PROPERTY debug -gdwarf-4) + # GCC 11 by default emits DWARF version 5 which cannot be parsed by + # pyelftools. Can be removed once pyelftools supports v5. + check_set_compiler_property(APPEND PROPERTY debug -gdwarf-4) +endif() set_compiler_property(PROPERTY no_common -fno-common) diff --git a/cmake/compiler/xcc/compiler_flags.cmake b/cmake/compiler/xcc/compiler_flags.cmake index a6205bbf546..6642eac2a6a 100644 --- a/cmake/compiler/xcc/compiler_flags.cmake +++ b/cmake/compiler/xcc/compiler_flags.cmake @@ -1,6 +1,10 @@ # No special flags are needed for xcc. # Only select whether gcc or clang flags should be inherited. if(CC STREQUAL "clang") + if($ENV{XCC_NO_G_FLAG}) + set(GCC_NO_G_FLAG 1) + endif() + include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake) else() include(${ZEPHYR_BASE}/cmake/compiler/gcc/compiler_flags.cmake)