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 <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2022-01-20 12:52:39 -08:00 committed by Anas Nashif
parent 8ab9ac2668
commit deeb98da53
2 changed files with 11 additions and 5 deletions

View file

@ -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)

View file

@ -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)