Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ endif (MSVC)

# Set commonly used directory names
set(CLR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(RUNTIME_DIR ${CMAKE_CURRENT_SOURCE_DIR}/runtime)
set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vm)
set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/inc)
set(GENERATED_EVENTING_DIR ${CMAKE_CURRENT_BINARY_DIR}/Eventing)
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ if(NOT DEFINED FEATURE_INTERPRETER)
set(FEATURE_PORTABLE_ENTRYPOINTS 1)
set(FEATURE_PORTABLE_HELPERS 1)
else()
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_RISCV64)
set(FEATURE_INTERPRETER $<IF:$<CONFIG:Debug,Checked>,1,0>)
else(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
else(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_RISCV64)
set(FEATURE_INTERPRETER 0)
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_RISCV64)
endif()
endif(NOT DEFINED FEATURE_INTERPRETER)

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
add_compile_definitions($<${FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH}:FEATURE_CACHED_INTERFACE_DISPATCH>)
add_compile_definitions($<${FEATURE_CORECLR_VIRTUAL_STUB_DISPATCH}:FEATURE_VIRTUAL_STUB_DISPATCH>)

include_directories(${RUNTIME_DIR})

add_subdirectory(daccess)
add_subdirectory(ee)
add_subdirectory(di)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_directories(${RUNTIME_DIR})

if(CLR_CMAKE_TARGET_WIN32 AND FEATURE_EVENT_TRACE)
add_subdirectory(clretwrc)
endif(CLR_CMAKE_TARGET_WIN32 AND FEATURE_EVENT_TRACE)
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
add_definitions(-DFEATURE_NO_HOST)

set(CLR_DAC_SOURCES
)
set(CLR_DAC_SOURCES)

add_definitions(-DFX_VER_INTERNALNAME_STR=mscordaccore.dll)

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(GC_DIR ../../gc)
set(RUNTIME_DIR ../../runtime)

set(COMMON_RUNTIME_SOURCES
allocheap.cpp
Expand Down
70 changes: 1 addition & 69 deletions src/coreclr/nativeaot/Runtime/unix/unixasmmacrosriscv64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -154,75 +154,7 @@ C_FUNC(\Name):
jalr \reg
.endm

// Loads the address of a thread-local variable into the target register.
// The target register cannot be a0.
.macro INLINE_GET_TLS_VAR target, var, ofs = 0
.ifc \target, a0
.error "target cannot be a0"
.endif

addi sp, sp, -72
sd ra, 64(sp)
sd t1, 56(sp)
sd a1, 48(sp)
sd a2, 40(sp)
sd a3, 32(sp)
sd a4, 24(sp)
sd a5, 16(sp)
sd a6, 8(sp)
sd a7, 0(sp)

// global dynamic TLS, see https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/eb2b2962/riscv-elf.adoc#global-dynamic
la.tls.gd a0, \var
call C_FUNC(__tls_get_addr)

ld ra, 64(sp)
ld t1, 56(sp)
ld a1, 48(sp)
ld a2, 40(sp)
ld a3, 32(sp)
ld a4, 24(sp)
ld a5, 16(sp)
ld a6, 8(sp)
ld a7, 0(sp)
addi sp, sp, 72

add \target, a0, \ofs

/*
In the future we should switch to TLS descriptors. Its support was added in 2024 in glibc, musl, llvm, gcc and binutils,
which is currently unavailable on majority devices. See https://maskray.me/blog/2024-01-23-riscv-tlsdesc-works

When the support for TLS descriptors is available in NativeAOT baseline, actions to perform:
* Apply this patch:
```
--- a/src/coreclr/nativeaot/CMakeLists.txt
+++ b/src/coreclr/nativeaot/CMakeLists.txt
@@ -30,6 +30,8 @@ endif (CLR_CMAKE_HOST_UNIX)

if(CLR_CMAKE_TARGET_ANDROID)
add_definitions(-DFEATURE_EMULATED_TLS)
+elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
+ add_definitions(-mtls-dialect=desc)
endif()

add_subdirectory(Bootstrap)
```
* Remove global dynamic code including prolog and epilog.
* Uncomment the following code and remove these comments.

// TLS descriptor, see https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/eb2b2962/riscv-elf.adoc#tls-descriptors
auipc a0, %tlsdesc_hi(\var)
lw t0, %tlsdesc_load_lo(\var)(a0)
addi a0, a0, %tlsdesc_add_lo(\var)
jalr t0, 0(t0), %tlsdesc_call(\var)
add \target, tp, a0
.ifnc \ofs, 0
add \target, \target, \ofs
.endif

*/
.endm
#include <riscv64/InlineTls.inc>

// Inlined version of RhpGetThread. Target cannot be x0.
.macro INLINE_GETTHREAD target
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/pal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project(COREPAL)

include(../clrfeatures.cmake)

include_directories(${RUNTIME_DIR})
include_directories(${COREPAL_SOURCE_DIR}/inc)
include_directories(${COREPAL_SOURCE_DIR}/src)
include_directories(${COREPAL_SOURCE_DIR}/../inc)
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/pal/inc/unixasmmacrosriscv64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,11 @@ C_FUNC(\Name):
0:
#endif
.endm

#include <riscv64/InlineTls.inc>

// Inlined version of RhpGetThread
.macro INLINE_GETTHREAD target
INLINE_GET_TLS_VAR \target, C_FUNC(t_CurrentThreadInfo)
ld \target, OFFSETOF__ThreadLocalInfo__m_pThread(\target)
.endm
72 changes: 72 additions & 0 deletions src/coreclr/runtime/riscv64/InlineTls.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Loads the address of a thread-local variable into the target register.
// The target register cannot be a0.
.macro INLINE_GET_TLS_VAR target, var, ofs = 0
.ifc \target, a0
.error "target cannot be a0"
.endif

addi sp, sp, -72
sd ra, 64(sp)
sd t1, 56(sp)
sd a1, 48(sp)
sd a2, 40(sp)
sd a3, 32(sp)
sd a4, 24(sp)
sd a5, 16(sp)
sd a6, 8(sp)
sd a7, 0(sp)

// global dynamic TLS, see https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/eb2b2962/riscv-elf.adoc#global-dynamic
la.tls.gd a0, \var
call C_FUNC(__tls_get_addr)

ld ra, 64(sp)
ld t1, 56(sp)
ld a1, 48(sp)
ld a2, 40(sp)
ld a3, 32(sp)
ld a4, 24(sp)
ld a5, 16(sp)
ld a6, 8(sp)
ld a7, 0(sp)
addi sp, sp, 72

add \target, a0, \ofs

/*
In the future we should switch to TLS descriptors. Its support was added in 2024 in glibc, musl, llvm, gcc and binutils,
which is currently unavailable on majority devices. See https://maskray.me/blog/2024-01-23-riscv-tlsdesc-works

When the support for TLS descriptors is available in NativeAOT baseline, actions to perform:
* Apply this patch:
```
--- a/src/coreclr/nativeaot/CMakeLists.txt
+++ b/src/coreclr/nativeaot/CMakeLists.txt
@@ -30,6 +30,8 @@ endif (CLR_CMAKE_HOST_UNIX)

if(CLR_CMAKE_TARGET_ANDROID)
add_definitions(-DFEATURE_EMULATED_TLS)
+elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
+ add_definitions(-mtls-dialect=desc)
endif()

add_subdirectory(Bootstrap)
```
* Remove global dynamic code including prolog and epilog.
* Uncomment the following code and remove these comments.

// TLS descriptor, see https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/eb2b2962/riscv-elf.adoc#tls-descriptors
auipc a0, %tlsdesc_hi(\var)
lw t0, %tlsdesc_load_lo(\var)(a0)
addi a0, a0, %tlsdesc_add_lo(\var)
jalr t0, 0(t0), %tlsdesc_call(\var)
add \target, tp, a0
.ifnc \ofs, 0
add \target, \target, \ofs
.endif

*/
.endm
2 changes: 0 additions & 2 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(RUNTIME_DIR ../runtime)

# Needed due to the munged files being in the binary folders, the set(CMAKE_INCLUDE_CURRENT_DIR ON) is not enough
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${ARCH_SOURCES_DIR})
Expand Down
Loading
Loading