Skip to content

Commit

Permalink
change(build): Use integrated assembler with Clang for RISCV chips
Browse files Browse the repository at this point in the history
  • Loading branch information
gerekon committed Sep 18, 2024
1 parent 64203d1 commit 9ca231e
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 31 deletions.
11 changes: 6 additions & 5 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ build_clang_test_apps_esp32s3:
extends:
- .build_cmake_clang_template
variables:
# For RISCV clang generates '.linker-options' sections of type 'llvm_linker_options' in asm files.
# See (https://llvm.org/docs/Extensions.html#linker-options-section-linker-options).
# Binutils gas ignores them with warning.
# TODO: LLVM-333, Use integrated assembler.
TEST_BUILD_OPTS_EXTRA: "--ignore-warning-str 'Warning: unrecognized section type'"
# https://reviews.llvm.org/D90108.
# GNU 'as' lets .weak override .globl since binutils-gdb
# https://github.com/bminor/binutils-gdb/commit/5ca547dc2399a0a5d9f20626d4bf5547c3ccfddd (1996)
# while MC lets the last directive win (PR38921).
# For RISCV chips we use integrated assembler by default, so suppress this warning to pass CI pipeline.
TEST_BUILD_OPTS_EXTRA: "--ignore-warning-str 'changed binding to STB_WEAK'"

build_clang_test_apps_esp32c3:
extends:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ rtos_current_tcb:
lw a0, pxCurrentTCBs
#endif /* ( configNUM_CORES > 1 ) */
ret
.size, .-rtos_current_tcb
.size rtos_current_tcb, .-rtos_current_tcb


/**
Expand Down
8 changes: 7 additions & 1 deletion components/riscv/vectors.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@

#if ( SOC_CPU_COPROC_NUM > 0 )
/* Targets with coprocessors present a special CSR to get Illegal Instruction exception reason */
#ifdef __clang__
/* Clang does not support constant declared via `equ` as operand for csrrw
* TODO: LLVM-369
*/
#define EXT_ILL_CSR 0x7F0
#else
.equ EXT_ILL_CSR, 0x7F0
#endif

/* EXT_ILL CSR reasons are stored as follows:
* - Bit 0: FPU core instruction (Load/Store instructions NOT concerned)
Expand Down Expand Up @@ -167,7 +174,6 @@ _panic_handler:
la ra, _return_from_exception
/* EXT_ILL CSR should contain the reason for the Illegal Instruction */
csrrw a0, EXT_ILL_CSR, zero

/* Hardware loop cannot be treated lazily, so we should never end here if a HWLP instruction is used */
#if SOC_CPU_HAS_PIE
/* Check if the PIE bit is set. */
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32c2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32c3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32c5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32c6.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32c61.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imac_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32h2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32h4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imc_zicsr_zifencei -mabi=ilp32 \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down
6 changes: 3 additions & 3 deletions tools/cmake/toolchain-clang-esp32p4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ set(CMAKE_AR llvm-ar)
set(CMAKE_RANLIB llvm-ranlib)
set(CMAKE_OBJDUMP riscv32-esp-elf-clang-objdump)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imafc_zicsr_zifencei -mabi=ilp32f -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imafc_zicsr_zifencei -mabi=ilp32f \
${CMAKE_C_FLAGS}"
UNIQ_CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}"
CACHE STRING "C Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imafc_zicsr_zifencei -mabi=ilp32f -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imafc_zicsr_zifencei -mabi=ilp32f \
${CMAKE_CXX_FLAGS}"
UNIQ_CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}"
CACHE STRING "C++ Compiler Base Flags"
FORCE)

remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imafc_zicsr_zifencei -mabi=ilp32f -no-integrated-as \
remove_duplicated_flags("--target=riscv32-esp-elf -march=rv32imafc_zicsr_zifencei -mabi=ilp32f \
${CMAKE_ASM_FLAGS}"
UNIQ_CMAKE_ASM_FLAGS)
set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}"
Expand Down

0 comments on commit 9ca231e

Please sign in to comment.