Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qualcomm-software/embedded/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ set(LLVM_TOOLCHAIN_DISTRIBUTION_COMPONENTS
installed by the install-llvm-toolchain target"
)
set(LLVM_ENABLE_PROJECTS clang;lld;polly CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD AArch64;ARM CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD AArch64;ARM;RISCV CACHE STRING "")
set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-unknown-linux-gnu CACHE STRING "")
set(LLVM_BUILD_RUNTIME OFF CACHE BOOL "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
Expand Down
25 changes: 25 additions & 0 deletions qualcomm-software/embedded/cmake/get_canonical_riscv_march.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Retrieve the canonical `-march` string given a set of valid compiler flags.
#
# We require the following arguments:
# - `compiler_path` is expected to contain the path to the compiler to use.
# - `build_args` is expected to be a CMake list (';' separated) of the compiler
# commands to use (typically `--target=`, `-march=`, etc.). These arguments
# are expected to all be valid and be sufficient to determine the correct set
# of extensions.
# - `march_out` should contain the variable to be used to return the
# canonicalized arch string.
function(get_canonical_riscv_march compiler_path build_args march_out)
set(command_args ${build_args} "--print-enabled-extensions")
execute_process(
COMMAND ${compiler_path}
${command_args}
RESULT_VARIABLE return_val
OUTPUT_VARIABLE extension_output
)
if(NOT return_val EQUAL 0)
message(FATAL_ERROR "Unable to execute `--print-enabled-extensions` to retreive canonical `-march` string")
endif()
string(REGEX MATCH
"ISA String: ([A-Za-z0-9_]+)" out_var "${extension_output}")
set(${march_out} ${CMAKE_MATCH_1} PARENT_SCOPE)
endfunction()
25 changes: 25 additions & 0 deletions qualcomm-software/embedded/embedded-multilib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ string(JSON multilib_defs GET ${multilib_json_str} "libs")
string(JSON lib_count LENGTH ${multilib_defs})
math(EXPR lib_count_dec "${lib_count} - 1")

include(${TOOLCHAIN_SOURCE_DIR}/cmake/get_canonical_riscv_march.cmake)

foreach(lib_idx RANGE ${lib_count_dec})
string(JSON lib_def GET ${multilib_defs} ${lib_idx})
string(JSON variant GET ${lib_def} "variant")
Expand Down Expand Up @@ -172,6 +174,10 @@ foreach(lib_idx RANGE ${lib_count_dec})
# Sort by target triple
if(variant MATCHES "^aarch64")
set(parent_dir_name aarch64-none-elf)
elseif(variant MATCHES "^riscv32")
set(parent_dir_name riscv32-unknown-elf)
elseif(variant MATCHES "^riscv64")
set(parent_dir_name riscv64-unknown-elf)
else()
set(parent_dir_name arm-none-eabi)
endif()
Expand Down Expand Up @@ -328,6 +334,25 @@ foreach(lib_idx RANGE ${lib_count_dec})
string(APPEND multilib_yaml_content " Flags:\n")
string(REPLACE " " ";" multilib_flags_list ${variant_multilib_flags})
foreach(flag ${multilib_flags_list})
if(variant MATCHES "^riscv")
if(flag MATCHES "-march=")
get_canonical_riscv_march(
"${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}"
"${multilib_flags_list}"
canonical_riscv_march
)
set(flag "-march=${canonical_riscv_march}")

# This forgoes any special handling of extension versions, but that seems
# fine as we don't support multiple versions of the same extensions, and we
# generally expect our compiler, libraries, and multilib file) to be coupled.
string(REPLACE "_" "_.*" expanded_riscv_march_match ${flag})
string(APPEND riscv_march_mappings "- Match: ${expanded_riscv_march_match}.*\n")
string(APPEND riscv_march_mappings " Flags:\n")
string(APPEND riscv_march_mappings " - ${flag}\n")
endif()
endif()

string(APPEND multilib_yaml_content " - ${flag}\n")
endforeach()
string(APPEND multilib_yaml_content " Group: stdlibs\n")
Expand Down
24 changes: 24 additions & 0 deletions qualcomm-software/embedded/embedded-multilib/json/multilib.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@
"json": "armv7a_soft_neon.json",
"flags": "--target=thumbv7-unknown-none-eabi -mfpu=neon -fno-exceptions",
"libraries_supported": "musl-embedded"
},
{
"variant": "riscv32imac_ilp32_nopic",
"json": "riscv32imac_ilp32_nopic.json",
"flags": "--target=riscv32-unknown-unknown-elf -march=rv32imac -mabi=ilp32 -fno-pic -fno-exceptions",
"libraries_supported": "picolibc"
},
{
"variant": "riscv32imac_zba_zbb_ilp32",
"json": "riscv32imac_zba_zbb_ilp32.json",
"flags": "--target=riscv32-unknown-unknown-elf -march=rv32imac_zba_zbb -mabi=ilp32 -fno-exceptions",
"libraries_supported": "picolibc"
},
{
"variant": "riscv32imac_zba_zbb_ilp32_nopic",
"json": "riscv32imac_zba_zbb_ilp32_nopic.json",
"flags": "--target=riscv32-unknown-unknown-elf -march=rv32imac_zba_zbb -mabi=ilp32 -fno-pic -fno-exceptions",
"libraries_supported": "picolibc"
},
{
"variant": "riscv64imac_lp64_nopic",
"json": "riscv64imac_lp64_nopic.json",
"flags": "--target=riscv64-unknown-unknown-elf -march=rv64imac -mabi=lp64 -fno-pic -fno-exceptions",
"libraries_supported": "picolibc"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"args": {
"common": {
"TARGET_ARCH": "riscv32",
"VARIANT": "riscv32imac_ilp32_nopic",
"COMPILE_FLAGS": "-march=rv32imac -mabi=ilp32",
"ENABLE_EXCEPTIONS": "OFF",
"ENABLE_RTTI": "ON",
"TEST_EXECUTOR": "qemu",
"QEMU_MACHINE": "virt",
"QEMU_CPU": "rv32",
"QEMU_PARAMS": "-bios none",
"FLASH_ADDRESS": "0x80000000",
"FLASH_SIZE": "0x00400000",
"RAM_ADDRESS": "0x80400000",
"RAM_SIZE": "0x00200000",
"LIBRARY_BUILD_TYPE": "minsizerelease"
},
"picolibc": {
"ENABLE_CXX_LIBS": "ON",
"ENABLE_LIBC_TESTS": "ON",
"ENABLE_COMPILER_RT_TESTS": "OFF",
"ENABLE_LIBCXX_TESTS": "OFF"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"args": {
"common": {
"TARGET_ARCH": "riscv32",
"VARIANT": "riscv32imac_zba_zbb_ilp32_fpic",
"COMPILE_FLAGS": "-march=rv32imac_zba_zbb -mabi=ilp32 -fPIC",
"ENABLE_EXCEPTIONS": "OFF",
"ENABLE_RTTI": "ON",
"TEST_EXECUTOR": "qemu",
"QEMU_MACHINE": "virt",
"QEMU_CPU": "rv32",
"QEMU_PARAMS": "-bios none",
"FLASH_ADDRESS": "0x80000000",
"FLASH_SIZE": "0x00400000",
"RAM_ADDRESS": "0x80400000",
"RAM_SIZE": "0x00200000",
"LIBRARY_BUILD_TYPE": "minsizerelease"
},
"picolibc": {
"ENABLE_CXX_LIBS": "ON",
"ENABLE_LIBC_TESTS": "ON",
"ENABLE_COMPILER_RT_TESTS": "OFF",
"ENABLE_LIBCXX_TESTS": "OFF"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"args": {
"common": {
"TARGET_ARCH": "riscv32",
"VARIANT": "riscv32imac_zba_zbb_ilp32_nopic",
"COMPILE_FLAGS": "-march=rv32imac_zba_zbb -mabi=ilp32",
"ENABLE_EXCEPTIONS": "OFF",
"ENABLE_RTTI": "ON",
"TEST_EXECUTOR": "qemu",
"QEMU_MACHINE": "virt",
"QEMU_CPU": "rv32",
"QEMU_PARAMS": "-bios none",
"FLASH_ADDRESS": "0x80000000",
"FLASH_SIZE": "0x00400000",
"RAM_ADDRESS": "0x80400000",
"RAM_SIZE": "0x00200000",
"LIBRARY_BUILD_TYPE": "minsizerelease"
},
"picolibc": {
"ENABLE_CXX_LIBS": "ON",
"ENABLE_LIBC_TESTS": "ON",
"ENABLE_COMPILER_RT_TESTS": "OFF",
"ENABLE_LIBCXX_TESTS": "OFF"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"args": {
"common": {
"TARGET_ARCH": "riscv64",
"VARIANT": "riscv64imac_lp64",
"COMPILE_FLAGS": "-march=rv64imac -mabi=lp64 -mcmodel=medany",
"ENABLE_EXCEPTIONS": "OFF",
"ENABLE_RTTI": "ON",
"TEST_EXECUTOR": "qemu",
"QEMU_MACHINE": "virt",
"QEMU_CPU": "rv64",
"QEMU_PARAMS": "-bios none",
"FLASH_ADDRESS": "0x80000000",
"FLASH_SIZE": "0x00400000",
"RAM_ADDRESS": "0x80400000",
"RAM_SIZE": "0x00200000",
"LIBRARY_BUILD_TYPE": "minsizerelease"
},
"picolibc": {
"ENABLE_CXX_LIBS": "ON",
"ENABLE_LIBC_TESTS": "ON",
"ENABLE_COMPILER_RT_TESTS": "OFF",
"ENABLE_LIBCXX_TESTS": "OFF"
}
}
}
4 changes: 4 additions & 0 deletions qualcomm-software/embedded/embedded-multilib/multilib.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Variants:

Mappings:

# Map extended sets of extensions back to the variants provided
# for RISC-V targets.
@riscv_march_mappings@

# Map higher architecture versions to subsets of them, so that a
# compatible library can be found even for architectures we don't have
# specific variants for.
Expand Down
22 changes: 20 additions & 2 deletions qualcomm-software/embedded/embedded-runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ endif()
if(TARGET_ARCH MATCHES "^aarch64")
set(target_triple "aarch64-none-elf")
set(cpu_family aarch64)
elseif(TARGET_ARCH MATCHES "^riscv32")
set(target_triple "riscv32-unknown-elf")
set(cpu_family riscv32)
elseif(TARGET_ARCH MATCHES "^riscv64")
set(target_triple "riscv64-unknown-elf")
set(cpu_family riscv64)
else()
# Choose the target triple so that compiler-rt will do the
# right thing. We can't always put the exact target
Expand Down Expand Up @@ -169,6 +175,10 @@ if(ENABLE_LIBC_TESTS OR ENABLE_COMPILER_RT_TESTS OR ENABLE_LIBCXX_TESTS)
if(TEST_EXECUTOR STREQUAL qemu)
if(TARGET_ARCH MATCHES "^aarch64")
find_program(QEMU_EXECUTABLE qemu-system-aarch64 REQUIRED)
elseif(TARGET_ARCH MATCHES "^riscv32")
find_program(QEMU_EXECUTABLE qemu-system-riscv32 REQUIRED)
elseif(TARGET_ARCH MATCHES "^riscv64")
find_program(QEMU_EXECUTABLE qemu-system-riscv64 REQUIRED)
else()
find_program(QEMU_EXECUTABLE qemu-system-arm REQUIRED)
endif()
Expand Down Expand Up @@ -228,7 +238,7 @@ endif()
# Exceptions are architectures pre-armv7, which compiler-rt expects to
# see in the triple because that's where it looks to decide whether to
# use specific assembly sources.
if(NOT target_triple MATCHES "^(aarch64-none-elf|arm-none-eabi|armv[4-6])")
if(NOT target_triple MATCHES "^(aarch64-none-elf|arm-none-eabi|armv[4-6]|riscv32-unknown-elf|riscv64-unknown-elf)")
message(FATAL_ERROR "\
Target triple name \"${target_triple}\" not compatible with compiler-rt.
Use -march to specify the architecture.")
Expand All @@ -239,7 +249,11 @@ if(flags MATCHES "-mfloat-abi=hard" AND NOT target_triple MATCHES "-eabihf$")
message(FATAL_ERROR "\
Hard-float library with target triple \"${target_triple}\" must end \"-eabihf\"")
endif()
string(REPLACE "-none-" "-unknown-none-" normalized_target_triple ${target_triple})
if(target_triple MATCHES "^riscv")
string(REPLACE "-unknown-" "-unknown-unknown-" normalized_target_triple ${target_triple})
else()
string(REPLACE "-none-" "-unknown-none-" normalized_target_triple ${target_triple})
endif()

if(ENABLE_COMPILER_RT_TESTS)
# Generate xfails for compiler-rt.
Expand Down Expand Up @@ -528,6 +542,10 @@ if(C_LIBRARY STREQUAL musl-embedded)
message(FATAL_ERROR "Building MUSL is not supported on Windows hosts")
endif()

if(TARGET_ARCH MATCHES "^riscv")
message(FATAL_ERROR "Only Arm and AArch64 targets are supported for musl-embedded")
endif()

include(${TOOLCHAIN_SOURCE_DIR}/cmake/fetch_musl-embedded.cmake)

include(ProcessorCount)
Expand Down
17 changes: 17 additions & 0 deletions qualcomm-software/embedded/test/multilib/riscv32.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32imac -mabi=ilp32 -fno-pic -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-FNO-PIC
# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32imafc_zba -mabi=ilp32 -fno-pic -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-FNO-PIC
# CHECK-IMAC-FNO-PIC: riscv32-unknown-elf/riscv32imac_ilp32_nopic{{$}}
# CHECK-IMAC-FNO-PIC-EMPTY:

# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32imac_zba_zbb -mabi=ilp32 -fpic -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-ZBA-ZBB
# CHECK-IMAC-ZBA-ZBB: riscv32-unknown-elf/riscv32imac_zba_zbb_ilp32{{$}}
# CHECK-IMAC-ZBA-ZBB-EMPTY:

# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32imac_zba_zbb -mabi=ilp32 -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-ZBA-ZBB-NO-PIC
# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32imac_zba_zbb -mabi=ilp32 -fno-pic -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-ZBA-ZBB-NO-PIC
# CHECK-IMAC-ZBA-ZBB-NO-PIC: riscv32-unknown-elf/riscv32imac_zba_zbb_ilp32_nopic{{$}}
# CHECK-IMAC-ZBA-ZBB-NO-PIC-EMPTY:

# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32imac -mabi=ilp32 -fpic -fno-exceptions 2>&1 | FileCheck %s --check-prefix=NOT-FOUND
# RUN: %clang -print-multi-directory --target=riscv32-unknown-elf -march=rv32ima -mabi=ilp32 -fno-pic -fno-exceptions 2>&1 | FileCheck %s --check-prefix=NOT-FOUND
# NOT-FOUND: warning: no multilib found matching flags
8 changes: 8 additions & 0 deletions qualcomm-software/embedded/test/multilib/riscv64.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# RUN: %clang -print-multi-directory --target=riscv64-unknown-elf -march=rv64imac -mabi=lp64 -fno-pic -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-FNO-PIC
# RUN: %clang -print-multi-directory --target=riscv64-unknown-elf -march=rv64imafc_zba -mabi=lp64 -fno-pic -fno-exceptions | FileCheck %s --check-prefix=CHECK-IMAC-FNO-PIC
# CHECK-IMAC-FNO-PIC: riscv64-unknown-elf/riscv64imac_lp64_nopic{{$}}
# CHECK-IMAC-FNO-PIC-EMPTY:

# RUN: %clang -print-multi-directory --target=riscv64-unknown-elf -march=rv64imac -mabi=lp64 -fpic -fno-exceptions 2>&1 | FileCheck %s --check-prefix=NOT-FOUND
# RUN: %clang -print-multi-directory --target=riscv64-unknown-elf -march=rv64imc -mabi=lp64 -fno-pic -fno-exceptions 2>&1 | FileCheck %s --check-prefix=NOT-FOUND
# NOT-FOUND: warning: no multilib found matching flags
Loading