Skip to content

draft: libc support for hexagon linux #81815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 5 additions & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ if(LLVM_LIBC_ENABLE_LINTING)
endif()
endif()

if(LIBC_TARGET_ARCHITECTURE STREQUAL "hexagon")
add_compile_options(-mlong-calls)
endif()


option(LLVM_LIBC_INCLUDE_SCUDO "Include the SCUDO standalone as the allocator for LLVM libc" OFF)
if(LLVM_LIBC_INCLUDE_SCUDO)
if (NOT ("compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS OR "compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES))
Expand Down
4 changes: 4 additions & 0 deletions libc/cmake/modules/LLVMLibCArchitectures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function(get_arch_and_system_from_triple triple arch_var sys_var)
set(target_arch "riscv32")
elseif(target_arch MATCHES "^riscv64")
set(target_arch "riscv64")
elseif(target_arch MATCHES "^hexagon")
set(target_arch "hexagon")
else()
return()
endif()
Expand Down Expand Up @@ -156,6 +158,8 @@ elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv64")
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv32")
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV32 TRUE)
set(LIBC_TARGET_ARCHITECTURE "riscv")
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "hexagon")
set(LIBC_TARGET_ARCHITECTURE_IS_HEXAGON TRUE)
else()
message(FATAL_ERROR
"Unsupported libc target architecture ${LIBC_TARGET_ARCHITECTURE}")
Expand Down
9 changes: 6 additions & 3 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function(create_libc_unittest fq_target_name)
if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
add_custom_target(
${fq_target_name}
COMMAND ${fq_build_target_name}
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} ${fq_build_target_name}
COMMENT "Running unit test ${fq_target_name}"
)
endif()
Expand Down Expand Up @@ -538,9 +538,12 @@ function(add_integration_test test_name)

if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
elseif(LIBC_TARGET_ARCHITECTURE_IS_HEXAGON)
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static -lclang_rt.builtins-hexagon)
else()
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
endif()

target_link_libraries(
${fq_build_target_name}
# The NVIDIA 'nvlink' linker does not currently support static libraries.
Expand Down Expand Up @@ -571,7 +574,7 @@ function(add_integration_test test_name)
$<TARGET_FILE:${fq_build_target_name}> ${INTEGRATION_TEST_ARGS})
add_custom_target(
${fq_target_name}
COMMAND ${test_cmd}
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} ${test_cmd}
COMMAND_EXPAND_LISTS
COMMENT "Running integration test ${fq_target_name}"
)
Expand Down Expand Up @@ -737,7 +740,7 @@ function(add_libc_hermetic_test test_name)
$<TARGET_FILE:${fq_build_target_name}> ${HERMETIC_TEST_ARGS})
add_custom_target(
${fq_target_name}
COMMAND ${test_cmd}
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} ${test_cmd}
COMMAND_EXPAND_LISTS
COMMENT "Running hermetic test ${fq_target_name}"
${LIBC_HERMETIC_TEST_JOB_POOL}
Expand Down
6 changes: 4 additions & 2 deletions libc/config/linux/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ struct TLSImage {

#if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) || \
defined(LIBC_TARGET_ARCH_IS_HEXAGON)
// At the language level, argc is an int. But we use uint64_t as the x86_64
// ABI specifies it as an 8 byte value. Likewise, in the ARM64 ABI, arguments
// are usually passed in registers. x0 is a doubleword register, so this is
// 64 bit for aarch64 as well.
// 64 bit for aarch64 as well. For hexagon, argc is an int and uintptr_t
// is 32-bits so the size will correspond.
typedef uintptr_t ArgcType;

// At the language level, argv is a char** value. However, we use uint64_t as
Expand Down
Loading