Index: libc/cmake/modules/LLVMLibCArchitectures.cmake =================================================================== --- libc/cmake/modules/LLVMLibCArchitectures.cmake +++ libc/cmake/modules/LLVMLibCArchitectures.cmake @@ -178,8 +178,8 @@ set(LIBC_CROSSBUILD TRUE) if(CMAKE_COMPILER_IS_GNUCXX) message(FATAL_ERROR - "GCC target triple and the explicity specified target triple do " - "not match.") + "GCC target triple (${libc_compiler_triple}) and the explicity " + "specified target triple (${explicit_target_triple}) do not match.") else() list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple}") Index: libc/config/linux/api.td =================================================================== --- libc/config/linux/api.td +++ libc/config/linux/api.td @@ -173,7 +173,6 @@ let Types = ["off_t", "size_t"]; let Macros = [ ]; - } def SignalAPI : PublicAPI<"signal.h"> { Index: libc/config/linux/app.h =================================================================== --- libc/config/linux/app.h +++ libc/config/linux/app.h @@ -35,7 +35,9 @@ uintptr_t align; }; -#if defined(LIBC_TARGET_ARCH_IS_X86_64) || defined(LIBC_TARGET_ARCH_IS_AARCH64) +#if defined(LIBC_TARGET_ARCH_IS_X86_64) || \ + defined(LIBC_TARGET_ARCH_IS_AARCH64) || \ + defined(LIBC_TARGET_ARCH_IS_RISCV64) // 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 Index: libc/config/linux/riscv64/entrypoints.txt =================================================================== --- libc/config/linux/riscv64/entrypoints.txt +++ libc/config/linux/riscv64/entrypoints.txt @@ -17,8 +17,14 @@ libc.src.ctype.tolower libc.src.ctype.toupper - # errno.h entrypoints - libc.src.errno.errno + # fcntl.h entrypoints + libc.src.fcntl.creat + libc.src.fcntl.open + libc.src.fcntl.openat + + # sched.h entrypoints + # libc.src.sched.sched_getaffinity + # libc.src.sched.sched_setaffinity # string.h entrypoints libc.src.string.bcmp @@ -39,8 +45,12 @@ libc.src.string.strcat libc.src.string.strchr libc.src.string.strcmp + libc.src.string.strcoll libc.src.string.strcpy libc.src.string.strcspn + libc.src.string.strdup + libc.src.string.strerror + libc.src.string.strerror_r libc.src.string.strlcat libc.src.string.strlcpy libc.src.string.strlen @@ -48,9 +58,11 @@ libc.src.string.strncat libc.src.string.strncmp libc.src.string.strncpy + libc.src.string.strndup libc.src.string.strnlen libc.src.string.strpbrk libc.src.string.strrchr + libc.src.string.strsignal libc.src.string.strspn libc.src.string.strstr libc.src.string.strtok @@ -61,7 +73,7 @@ libc.src.inttypes.imaxdiv libc.src.inttypes.strtoimax libc.src.inttypes.strtoumax - + # stdlib.h entrypoints libc.src.stdlib.abs libc.src.stdlib.atoi @@ -75,6 +87,8 @@ libc.src.stdlib.llabs libc.src.stdlib.lldiv libc.src.stdlib.qsort + libc.src.stdlib.rand + libc.src.stdlib.srand libc.src.stdlib.strtod libc.src.stdlib.strtof libc.src.stdlib.strtol @@ -82,25 +96,413 @@ libc.src.stdlib.strtoll libc.src.stdlib.strtoul libc.src.stdlib.strtoull + + # stdlib.h external entrypoints + libc.src.stdlib.malloc + libc.src.stdlib.calloc + libc.src.stdlib.realloc + libc.src.stdlib.aligned_alloc + libc.src.stdlib.free + + # stdio.h entrypoints + libc.src.stdio.remove + # libc.src.stdio.sprintf + libc.src.stdio.snprintf + + # sys/mman.h entrypoints + libc.src.sys.mman.madvise + libc.src.sys.mman.mmap + libc.src.sys.mman.mprotect + libc.src.sys.mman.munmap + libc.src.sys.mman.posix_madvise + + # sys/random.h entrypoints + libc.src.sys.random.getrandom + + # sys/resource.h entrypoints + libc.src.sys.resource.getrlimit + libc.src.sys.resource.setrlimit + + # sys/sendfile entrypoints + libc.src.sys.sendfile.sendfile + + # sys/stat.h entrypoints + libc.src.sys.stat.chmod + libc.src.sys.stat.fchmod + libc.src.sys.stat.fchmodat + libc.src.sys.stat.fstat + libc.src.sys.stat.lstat + libc.src.sys.stat.mkdir + libc.src.sys.stat.mkdirat + libc.src.sys.stat.stat + + # sys/utsname.h entrypoints + libc.src.sys.utsname.uname + + # sys/wait.h entrypoints + libc.src.sys.wait.wait + libc.src.sys.wait.wait4 + libc.src.sys.wait.waitpid + + # termios.h entrypoints + libc.src.termios.cfgetispeed + libc.src.termios.cfgetospeed + libc.src.termios.cfsetispeed + libc.src.termios.cfsetospeed + libc.src.termios.tcgetattr + libc.src.termios.tcgetsid + libc.src.termios.tcdrain + libc.src.termios.tcflow + libc.src.termios.tcflush + libc.src.termios.tcsendbreak + libc.src.termios.tcsetattr + + # unistd.h entrypoints + libc.src.unistd.access + libc.src.unistd.chdir + libc.src.unistd.close + libc.src.unistd.dup + libc.src.unistd.dup2 + libc.src.unistd.dup3 + libc.src.unistd.execve + libc.src.unistd.fchdir + libc.src.unistd.fsync + libc.src.unistd.ftruncate + libc.src.unistd.getcwd + libc.src.unistd.geteuid + libc.src.unistd.getpid + libc.src.unistd.getppid + libc.src.unistd.getuid + libc.src.unistd.isatty + libc.src.unistd.link + libc.src.unistd.linkat + libc.src.unistd.lseek + libc.src.unistd.pread + libc.src.unistd.pwrite + libc.src.unistd.read + libc.src.unistd.readlink + libc.src.unistd.readlinkat + libc.src.unistd.rmdir + libc.src.unistd.symlink + libc.src.unistd.symlinkat + libc.src.unistd.sysconf + libc.src.unistd.truncate + libc.src.unistd.unlink + libc.src.unistd.unlinkat + libc.src.unistd.write ) set(TARGET_LIBM_ENTRYPOINTS + # fenv.h entrypoints + # libc.src.fenv.feclearexcept + # libc.src.fenv.fedisableexcept + # libc.src.fenv.feenableexcept + # libc.src.fenv.fegetenv + # libc.src.fenv.fegetexcept + # libc.src.fenv.fegetexceptflag + # libc.src.fenv.fegetround + # libc.src.fenv.feholdexcept + # libc.src.fenv.fesetenv + # libc.src.fenv.fesetexceptflag + # libc.src.fenv.fesetround + # libc.src.fenv.feraiseexcept + # libc.src.fenv.fetestexcept + # libc.src.fenv.feupdateenv + # math.h entrypoints + # libc.src.math.acosf + # libc.src.math.acoshf + # libc.src.math.asin + # libc.src.math.asinf + # libc.src.math.asinhf + # libc.src.math.atanf + # libc.src.math.atanhf + libc.src.math.copysign + libc.src.math.copysignf + libc.src.math.copysignl + libc.src.math.ceil + libc.src.math.ceilf + libc.src.math.ceill + # libc.src.math.cos + # libc.src.math.coshf + # libc.src.math.cosf + # libc.src.math.expf + # libc.src.math.exp10f + # libc.src.math.exp2f + # libc.src.math.expm1f libc.src.math.fabs libc.src.math.fabsf libc.src.math.fabsl libc.src.math.fdim libc.src.math.fdimf libc.src.math.fdiml - libc.src.math.fmax - libc.src.math.fmaxf - libc.src.math.fmaxl + libc.src.math.floor + libc.src.math.floorf + libc.src.math.floorl + # libc.src.math.fma + libc.src.math.fmaf libc.src.math.fmin libc.src.math.fminf libc.src.math.fminl + libc.src.math.fmax + libc.src.math.fmaxf + libc.src.math.fmaxl + # libc.src.math.fmod + # libc.src.math.fmodf + libc.src.math.frexp + libc.src.math.frexpf + libc.src.math.frexpl + # libc.src.math.hypot + # libc.src.math.hypotf + libc.src.math.ilogb + libc.src.math.ilogbf + libc.src.math.ilogbl + libc.src.math.ldexp + libc.src.math.ldexpf + libc.src.math.ldexpl + # libc.src.math.llrint + # libc.src.math.llrintf + # libc.src.math.llrintl + # libc.src.math.llround + # libc.src.math.llroundf + # libc.src.math.llroundl + # libc.src.math.log10 + # libc.src.math.log10f + # libc.src.math.log1pf + # libc.src.math.log2f + # libc.src.math.logf + libc.src.math.logb + libc.src.math.logbf + libc.src.math.logbl + # libc.src.math.lrint + # libc.src.math.lrintf + # libc.src.math.lrintl + # libc.src.math.lround + # libc.src.math.lroundf + # libc.src.math.lroundl + libc.src.math.modf + libc.src.math.modff + libc.src.math.modfl + libc.src.math.nearbyint + libc.src.math.nearbyintf + libc.src.math.nearbyintl + libc.src.math.nextafter + libc.src.math.nextafterf + libc.src.math.nextafterl + # libc.src.math.pow + libc.src.math.remainderf + libc.src.math.remainder + libc.src.math.remainderl + libc.src.math.remquof + libc.src.math.remquo + libc.src.math.remquol + # libc.src.math.rint + # libc.src.math.rintf + # libc.src.math.rintl + libc.src.math.round + libc.src.math.roundf + libc.src.math.roundl + libc.src.math.scalbn + libc.src.math.scalbnf + libc.src.math.scalbnl + # libc.src.math.sin + # libc.src.math.sincosf + # libc.src.math.sinhf + # libc.src.math.sinf + # libc.src.math.sqrt + # libc.src.math.sqrtf + # libc.src.math.sqrtl + # libc.src.math.tan + # libc.src.math.tanf + # libc.src.math.tanhf + libc.src.math.trunc + libc.src.math.truncf + libc.src.math.truncl ) +if(LLVM_LIBC_FULL_BUILD) + list(APPEND TARGET_LIBC_ENTRYPOINTS + # assert.h entrypoints + # libc.src.assert.__assert_fail + + # dirent.h entrypoints + # libc.src.dirent.closedir + libc.src.dirent.dirfd + # libc.src.dirent.opendir + # libc.src.dirent.readdir + + # network.h entrypoints + libc.src.network.htonl + libc.src.network.htons + libc.src.network.ntohl + libc.src.network.ntohs + + # pthread.h entrypoints + libc.src.pthread.pthread_atfork + libc.src.pthread.pthread_attr_destroy + libc.src.pthread.pthread_attr_init + libc.src.pthread.pthread_attr_getdetachstate + libc.src.pthread.pthread_attr_getguardsize + libc.src.pthread.pthread_attr_getstack + libc.src.pthread.pthread_attr_getstacksize + libc.src.pthread.pthread_attr_setdetachstate + libc.src.pthread.pthread_attr_setguardsize + libc.src.pthread.pthread_attr_setstack + libc.src.pthread.pthread_attr_setstacksize + libc.src.pthread.pthread_create + libc.src.pthread.pthread_detach + libc.src.pthread.pthread_equal + libc.src.pthread.pthread_exit + libc.src.pthread.pthread_getname_np + libc.src.pthread.pthread_getspecific + libc.src.pthread.pthread_join + libc.src.pthread.pthread_key_create + libc.src.pthread.pthread_key_delete + libc.src.pthread.pthread_self + libc.src.pthread.pthread_setname_np + libc.src.pthread.pthread_mutex_destroy + libc.src.pthread.pthread_mutex_init + libc.src.pthread.pthread_mutex_lock + libc.src.pthread.pthread_mutex_unlock + libc.src.pthread.pthread_mutexattr_destroy + libc.src.pthread.pthread_mutexattr_init + libc.src.pthread.pthread_mutexattr_getpshared + libc.src.pthread.pthread_mutexattr_getrobust + libc.src.pthread.pthread_mutexattr_gettype + libc.src.pthread.pthread_mutexattr_setpshared + libc.src.pthread.pthread_mutexattr_setrobust + libc.src.pthread.pthread_mutexattr_settype + libc.src.pthread.pthread_once + libc.src.pthread.pthread_setspecific + + # sched.h entrypoints + libc.src.sched.__sched_getcpucount + + # setjmp.h entrypoints + # libc.src.setjmp.longjmp + # libc.src.setjmp.setjmp + + # stdio.h entrypoints + libc.src.stdio.clearerr + libc.src.stdio.clearerr_unlocked + libc.src.stdio.fclose + libc.src.stdio.flockfile + libc.src.stdio.feof + libc.src.stdio.feof_unlocked + libc.src.stdio.ferror + libc.src.stdio.ferror_unlocked + libc.src.stdio.fgetc + libc.src.stdio.fgetc_unlocked + libc.src.stdio.fgets + libc.src.stdio.fflush + libc.src.stdio.fopen + libc.src.stdio.fputc + libc.src.stdio.fputs + libc.src.stdio.fopencookie + libc.src.stdio.fread + libc.src.stdio.fread_unlocked + libc.src.stdio.fseek + libc.src.stdio.ftell + libc.src.stdio.funlockfile + libc.src.stdio.fwrite + libc.src.stdio.fwrite_unlocked + libc.src.stdio.fprintf + libc.src.stdio.getc + libc.src.stdio.getc_unlocked + libc.src.stdio.printf + libc.src.stdio.sscanf + libc.src.stdio.scanf + libc.src.stdio.fscanf + libc.src.stdio.putc + libc.src.stdio.putchar + libc.src.stdio.puts + libc.src.stdio.setbuf + libc.src.stdio.setvbuf + libc.src.stdio.stderr + libc.src.stdio.stdin + libc.src.stdio.stdout + libc.src.stdio.ungetc + + # stdlib.h entrypoints + libc.src.stdlib._Exit + # libc.src.stdlib.abort + libc.src.stdlib.atexit + # libc.src.stdlib.exit + libc.src.stdlib.getenv + + # signal.h entrypoints + # libc.src.signal.raise + # libc.src.signal.kill + # libc.src.signal.sigaction + # libc.src.signal.sigaltstack + # libc.src.signal.sigdelset + # libc.src.signal.sigaddset + # libc.src.signal.sigemptyset + # libc.src.signal.sigprocmask + # libc.src.signal.sigfillset + # libc.src.signal.signal + + # spawn.h entrypoints + # libc.src.spawn.posix_spawn + libc.src.spawn.posix_spawn_file_actions_addclose + libc.src.spawn.posix_spawn_file_actions_adddup2 + libc.src.spawn.posix_spawn_file_actions_addopen + libc.src.spawn.posix_spawn_file_actions_destroy + libc.src.spawn.posix_spawn_file_actions_init + + # threads.h entrypoints + libc.src.threads.call_once + libc.src.threads.cnd_broadcast + libc.src.threads.cnd_destroy + libc.src.threads.cnd_init + libc.src.threads.cnd_signal + libc.src.threads.cnd_wait + libc.src.threads.mtx_destroy + libc.src.threads.mtx_init + libc.src.threads.mtx_lock + libc.src.threads.mtx_unlock + libc.src.threads.thrd_create + libc.src.threads.thrd_current + libc.src.threads.thrd_detach + libc.src.threads.thrd_equal + libc.src.threads.thrd_exit + libc.src.threads.thrd_join + libc.src.threads.tss_create + libc.src.threads.tss_delete + libc.src.threads.tss_get + libc.src.threads.tss_set + + # time.h entrypoints + libc.src.time.asctime + libc.src.time.asctime_r + libc.src.time.clock_gettime + libc.src.time.clock + libc.src.time.difftime + libc.src.time.gettimeofday + libc.src.time.gmtime + libc.src.time.gmtime_r + libc.src.time.mktime + libc.src.time.nanosleep + libc.src.time.time + + # unistd.h entrypoints + libc.src.unistd.environ + libc.src.unistd.execv + # libc.src.unistd.fork + # libc.src.unistd.__llvm_libc_syscall + libc.src.unistd.getopt + libc.src.unistd.optarg + libc.src.unistd.optind + libc.src.unistd.optopt + libc.src.unistd.opterr + + # sys/select.h entrypoints + libc.src.sys.select.select + ) +endif() + set(TARGET_LLVMLIBC_ENTRYPOINTS ${TARGET_LIBC_ENTRYPOINTS} ${TARGET_LIBM_ENTRYPOINTS} ) + Index: libc/config/linux/riscv64/headers.txt =================================================================== --- libc/config/linux/riscv64/headers.txt +++ libc/config/linux/riscv64/headers.txt @@ -1,8 +1,39 @@ set(TARGET_PUBLIC_HEADERS + libc.include.assert libc.include.ctype + libc.include.dirent libc.include.errno + libc.include.fcntl + libc.include.fenv libc.include.inttypes libc.include.math + libc.include.pthread + libc.include.sched + libc.include.signal + libc.include.spawn + libc.include.setjmp + libc.include.stdio libc.include.stdlib libc.include.string + libc.include.termios + libc.include.threads + libc.include.time + libc.include.unistd + + libc.include.arpa_inet + + libc.include.sys_auxv + libc.include.sys_ioctl + libc.include.sys_mman + libc.include.sys_prctl + libc.include.sys_random + libc.include.sys_resource + libc.include.sys_select + libc.include.sys_socket + libc.include.sys_stat + libc.include.sys_syscall + libc.include.sys_time + libc.include.sys_types + libc.include.sys_utsname + libc.include.sys_wait ) Index: libc/include/CMakeLists.txt =================================================================== --- libc/include/CMakeLists.txt +++ libc/include/CMakeLists.txt @@ -122,12 +122,12 @@ DEPENDS .llvm_libc_common_h .llvm-libc-macros.time_macros - .llvm-libc-types.time_t .llvm-libc-types.clock_t - .llvm-libc-types.clockid_t + .llvm-libc-types.time_t .llvm-libc-types.struct_tm .llvm-libc-types.struct_timespec .llvm-libc-types.struct_timeval + .llvm-libc-types.clockid_t ) add_gen_header( @@ -137,11 +137,11 @@ DEPENDS .llvm_libc_common_h .llvm-libc-types.__call_once_func_t + .llvm-libc-types.once_flag .llvm-libc-types.cnd_t .llvm-libc-types.mtx_t - .llvm-libc-types.once_flag - .llvm-libc-types.thrd_start_t .llvm-libc-types.thrd_t + .llvm-libc-types.thrd_start_t .llvm-libc-types.tss_t .llvm-libc-types.tss_dtor_t ) @@ -164,11 +164,12 @@ ../config/${LIBC_TARGET_OS}/signal.h.in DEPENDS .llvm-libc-macros.signal_macros - .llvm-libc-types.__sighandler_t - .llvm-libc-types.sigset_t .llvm-libc-types.sig_atomic_t - .llvm-libc-types.stack_t + .llvm-libc-types.sigset_t .llvm-libc-types.struct_sigaction + .llvm-libc-types.union_sigval + .llvm-libc-types.siginfo_t + .llvm-libc-types.stack_t .llvm-libc-types.pid_t ) @@ -180,10 +181,9 @@ .llvm_libc_common_h .llvm-libc-macros.file_seek_macros .llvm-libc-macros.stdio_macros - .llvm-libc-types.cookie_io_functions_t - .llvm-libc-types.FILE - .llvm-libc-types.off_t .llvm-libc-types.size_t + .llvm-libc-types.FILE + .llvm-libc-types.cookie_io_functions_t ) add_gen_header( @@ -193,12 +193,12 @@ DEPENDS .llvm_libc_common_h .llvm-libc-macros.stdlib_macros - .llvm-libc-types.__bsearchcompare_t - .llvm-libc-types.__qsortcompare_t .llvm-libc-types.div_t .llvm-libc-types.ldiv_t .llvm-libc-types.lldiv_t .llvm-libc-types.size_t + .llvm-libc-types.__bsearchcompare_t + .llvm-libc-types.__qsortcompare_t .llvm-libc-types.__atexithandler_t ) @@ -227,15 +227,15 @@ DEPENDS .llvm_libc_common_h .llvm-libc-types.__atfork_callback_t + .llvm-libc-types.__pthread_once_func_t .llvm-libc-types.__pthread_start_t .llvm-libc-types.__pthread_tss_dtor_t .llvm-libc-types.pthread_attr_t - .llvm-libc-types.pthread_key_t .llvm-libc-types.pthread_mutex_t .llvm-libc-types.pthread_mutexattr_t - .llvm-libc-types.pthread_once_t - .llvm-libc-types.__pthread_once_func_t .llvm-libc-types.pthread_t + .llvm-libc-types.pthread_key_t + .llvm-libc-types.pthread_once_t ) add_gen_header( @@ -244,8 +244,10 @@ GEN_HDR sched.h DEPENDS .llvm_libc_common_h - .llvm-libc-types.cpu_set_t .llvm-libc-macros.sched_macros + .llvm-libc-types.pid_t + .llvm-libc-types.size_t + .llvm-libc-types.cpu_set_t ) add_gen_header( @@ -289,9 +291,9 @@ GEN_HDR sys/mman.h DEPENDS .llvm_libc_common_h + .llvm-libc-macros.sys_mman_macros .llvm-libc-types.off_t .llvm-libc-types.ssize_t - .llvm-libc-macros.sys_mman_macros ) add_gen_header( @@ -309,8 +311,8 @@ DEPENDS .llvm_libc_common_h .llvm-libc-macros.sys_random_macros - .llvm-libc-types.ssize_t .llvm-libc-types.size_t + .llvm-libc-types.ssize_t ) add_gen_header( @@ -332,6 +334,16 @@ .llvm_libc_common_h .llvm-libc-macros.sys_stat_macros .llvm-libc-types.mode_t + .llvm-libc-types.dev_t + .llvm-libc-types.ino_t + .llvm-libc-types.nlink_t + .llvm-libc-types.uid_t + .llvm-libc-types.gid_t + .llvm-libc-types.off_t + .llvm-libc-types.struct_timespec + .llvm-libc-types.struct_timeval + .llvm-libc-types.blksize_t + .llvm-libc-types.blkcnt_t .llvm-libc-types.struct_stat ) @@ -344,11 +356,10 @@ .llvm-libc-macros.sys_select_macros .llvm-libc-types.fd_set .llvm-libc-types.sigset_t - .llvm-libc-types.struct_timespec - .llvm-libc-types.struct_timeval .llvm-libc-types.suseconds_t .llvm-libc-types.time_t - .llvm-libc-types.ssize_t + .llvm-libc-types.struct_timespec + .llvm-libc-types.struct_timeval ) add_gen_header( @@ -358,6 +369,7 @@ DEPENDS .llvm_libc_common_h .llvm-libc-types.off_t + .llvm-libc-types.size_t .llvm-libc-types.ssize_t ) @@ -447,6 +459,7 @@ .llvm_libc_common_h .llvm-libc-macros.termios_macros .llvm-libc-types.cc_t + .llvm-libc-types.pid_t .llvm-libc-types.speed_t .llvm-libc-types.struct_termios .llvm-libc-types.tcflag_t Index: libc/include/llvm-libc-macros/linux/signal-macros.h =================================================================== --- libc/include/llvm-libc-macros/linux/signal-macros.h +++ libc/include/llvm-libc-macros/linux/signal-macros.h @@ -82,6 +82,9 @@ #elif defined(__aarch64__) #define MINSIGSTKSZ 5120 #define SIGSTKSZ 16384 +#elif defined(__riscv) +#define MINSIGSTKSZ 2048 +#define SIGSTKSZ 8192 #else #error "Signal stack sizes not defined for your platform." #endif Index: libc/include/llvm-libc-types/fenv_t.h =================================================================== --- libc/include/llvm-libc-types/fenv_t.h +++ libc/include/llvm-libc-types/fenv_t.h @@ -21,5 +21,8 @@ unsigned char __mxcsr[4]; } fenv_t; #endif +#ifdef __riscv +typedef unsigned int fenv_t; +#endif #endif // __LLVM_LIBC_TYPES_FENV_T_H__ Index: libc/src/__support/FPUtil/FEnvImpl.h =================================================================== --- libc/src/__support/FPUtil/FEnvImpl.h +++ libc/src/__support/FPUtil/FEnvImpl.h @@ -30,6 +30,8 @@ #include "x86_64/FEnvImpl.h" #elif defined(LIBC_TARGET_ARCH_IS_ARM) #include "arm/FEnvImpl.h" +#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) +#include "riscv64/FEnvImpl.h" #else namespace __llvm_libc::fputil { @@ -44,13 +46,17 @@ LIBC_INLINE int raise_except(int) { return 0; } +LIBC_INLINE int enable_except(int) { return 0; } + +LIBC_INLINE int disable_except(int) { return 0; } + LIBC_INLINE int get_round() { return FE_TONEAREST; } LIBC_INLINE int set_round(int) { return 0; } -LIBC_INLINE int get_env(fenv_t *) { return 0; } +LIBC_INLINE int get_env(void *) { return 0; } -LIBC_INLINE int set_env(const fenv_t *) { return 0; } +LIBC_INLINE int set_env(const void *) { return 0; } } // namespace __llvm_libc::fputil #endif Index: libc/src/__support/FPUtil/FMA.h =================================================================== --- libc/src/__support/FPUtil/FMA.h +++ libc/src/__support/FPUtil/FMA.h @@ -18,6 +18,8 @@ #include "x86_64/FMA.h" #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) #include "aarch64/FMA.h" +#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) +#include "riscv64/FMA.h" #endif #else Index: libc/src/__support/FPUtil/riscv64/FEnvImpl.h =================================================================== --- /dev/null +++ libc/src/__support/FPUtil/riscv64/FEnvImpl.h @@ -0,0 +1,50 @@ +//===-- RISCV64 floating point env manipulation functions --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_RISCV64_FENVIMPL_H +#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_RISCV64_FENVIMPL_H + +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/macros/properties/architectures.h" + +#if !defined(LIBC_TARGET_ARCH_IS_RISCV64) +#error "Invalid include" +#endif + +#include +#include + +namespace __llvm_libc { +namespace fputil { + +LIBC_INLINE int clear_except(int) { return 0; } + +LIBC_INLINE int test_except(int) { return 0; } + +LIBC_INLINE int set_except(int) { return 0; } + +LIBC_INLINE int get_except() { return 0; } + +LIBC_INLINE int raise_except(int) { return 0; } + +LIBC_INLINE int enable_except(int) { return 0; } + +LIBC_INLINE int disable_except(int) { return 0; } + +LIBC_INLINE int get_round() { return FE_TONEAREST; } + +LIBC_INLINE int set_round(int) { return 0; } + +LIBC_INLINE int get_env(fenv_t *) { return 0; } + +LIBC_INLINE int set_env(const fenv_t *) { return 0; } + +} // namespace fputil +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_RISCV64_FENVIMPL_H Index: libc/src/__support/FPUtil/riscv64/FMA.h =================================================================== --- /dev/null +++ libc/src/__support/FPUtil/riscv64/FMA.h @@ -0,0 +1,49 @@ +//===-- Aarch64 implementations of the fma function -------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H +#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H + +#include "src/__support/macros/properties/architectures.h" +#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA + +#if !defined(LIBC_TARGET_ARCH_IS_RISCV64) +#error "Invalid include" +#endif + +#if !defined(LIBC_TARGET_CPU_HAS_FMA) +#error "FMA instructions are not supported" +#endif + +#include "src/__support/CPP/type_traits.h" + +namespace __llvm_libc { +namespace fputil { + +template +cpp::enable_if_t, T> fma(T x, T y, T z) { + float result; + __asm__ __volatile__("fmadd.s %0, %1, %2, %3\n\t" + : "=f"(result) + : "f"(x), "f"(y), "f"(z)); + return result; +} + +template +cpp::enable_if_t, T> fma(T x, T y, T z) { + double result; + __asm__ __volatile__("fmadd.d %0, %1, %2, %3\n\t" + : "=f"(result) + : "f"(x), "f"(y), "f"(z)); + return result; +} + +} // namespace fputil +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H Index: libc/src/__support/FPUtil/riscv64/sqrt.h =================================================================== --- /dev/null +++ libc/src/__support/FPUtil/riscv64/sqrt.h @@ -0,0 +1,39 @@ +//===-- Square root of IEEE 754 floating point numbers ----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_RISCV64_SQRT_H +#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_RISCV64_SQRT_H + +#include "src/__support/common.h" +#include "src/__support/macros/properties/architectures.h" + +#if !defined(LIBC_TARGET_ARCH_IS_RISCV64) +#error "Invalid include" +#endif + +#include "src/__support/FPUtil/generic/sqrt.h" + +namespace __llvm_libc { +namespace fputil { + +template <> LIBC_INLINE float sqrt(float x) { + float result; + __asm__ __volatile__("fsqrt.s %0, %1\n\t" : "=f"(result) : "f"(x)); + return result; +} + +template <> LIBC_INLINE double sqrt(double x) { + double result; + __asm__ __volatile__("fsqrt.d %0, %1\n\t" : "=f"(result) : "f"(x)); + return result; +} + +} // namespace fputil +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_RISCV64_SQRT_H Index: libc/src/__support/FPUtil/sqrt.h =================================================================== --- libc/src/__support/FPUtil/sqrt.h +++ libc/src/__support/FPUtil/sqrt.h @@ -15,6 +15,8 @@ #include "x86_64/sqrt.h" #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) #include "aarch64/sqrt.h" +#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) +#include "riscv64/sqrt.h" #else #include "generic/sqrt.h" Index: libc/src/__support/OSUtil/linux/riscv64/CMakeLists.txt =================================================================== --- /dev/null +++ libc/src/__support/OSUtil/linux/riscv64/CMakeLists.txt @@ -0,0 +1,7 @@ +add_header_library( + linux_riscv64_util + HDRS + syscall.h + DEPENDS + libc.src.__support.common +) Index: libc/src/__support/OSUtil/linux/riscv64/syscall.h =================================================================== --- /dev/null +++ libc/src/__support/OSUtil/linux/riscv64/syscall.h @@ -0,0 +1,99 @@ +//===---------- inline implementation of RISCV64 syscalls ---------* C++ *-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_RISCV64_SYSCALL_H +#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_RISCV64_SYSCALL_H + +#include "src/__support/common.h" + +#define SYSCALL_CLOBBER_LIST "cc", "memory" + +namespace __llvm_libc { + +inline long syscall_impl(long number) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("x0"); + LIBC_INLINE_ASM("scall" : "+r"(a0) : "r"(a7) : SYSCALL_CLOBBER_LIST); + return a0; +} + +inline long syscall_impl(long number, long arg0) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("a0") = arg0; + LIBC_INLINE_ASM("scall" : "+r"(a0) : "r"(a7) : SYSCALL_CLOBBER_LIST); + return a0; +} + +inline long syscall_impl(long number, long arg0, long arg1) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("a0") = arg0; + register long a1 __asm__("a1") = arg1; + LIBC_INLINE_ASM("scall" : "+r"(a0) : "r"(a1), "r"(a7) : SYSCALL_CLOBBER_LIST); + return a0; +} + +inline long syscall_impl(long number, long arg0, long arg1, long arg2) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("a0") = arg0; + register long a1 __asm__("a1") = arg1; + register long a2 __asm__("a2") = arg2; + LIBC_INLINE_ASM("scall" + : "+r"(a0) + : "r"(a1), "r"(a2), "r"(a7) + : SYSCALL_CLOBBER_LIST); + return a0; +} + +inline long syscall_impl(long number, long arg0, long arg1, long arg2, + long arg3) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("a0") = arg0; + register long a1 __asm__("a1") = arg1; + register long a2 __asm__("a2") = arg2; + register long a3 __asm__("a3") = arg3; + LIBC_INLINE_ASM("scall" + : "+r"(a0) + : "r"(a1), "r"(a2), "r"(a3), "r"(a7) + : SYSCALL_CLOBBER_LIST); + return a0; +} + +inline long syscall_impl(long number, long arg0, long arg1, long arg2, + long arg3, long arg4) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("a0") = arg0; + register long a1 __asm__("a1") = arg1; + register long a2 __asm__("a2") = arg2; + register long a3 __asm__("a3") = arg3; + register long a4 __asm__("a4") = arg4; + LIBC_INLINE_ASM("scall" + : "+r"(a0) + : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a7) + : SYSCALL_CLOBBER_LIST); + return a0; +} + +inline long syscall_impl(long number, long arg0, long arg1, long arg2, + long arg3, long arg4, long arg5) { + register long a7 __asm__("a7") = number; + register long a0 __asm__("a0") = arg0; + register long a1 __asm__("a1") = arg1; + register long a2 __asm__("a2") = arg2; + register long a3 __asm__("a3") = arg3; + register long a4 __asm__("a4") = arg4; + register long a5 __asm__("a5") = arg5; + LIBC_INLINE_ASM("scall" + : "+r"(a0) + : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a7) + : SYSCALL_CLOBBER_LIST); + return a0; +} + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_RISCV64_SYSCALL_H Index: libc/src/__support/OSUtil/linux/syscall.h =================================================================== --- libc/src/__support/OSUtil/linux/syscall.h +++ libc/src/__support/OSUtil/linux/syscall.h @@ -18,6 +18,8 @@ #include "aarch64/syscall.h" #elif defined(LIBC_TARGET_ARCH_IS_ARM) #include "arm/syscall.h" +#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) +#include "riscv64/syscall.h" #endif namespace __llvm_libc { Index: libc/src/__support/macros/properties/architectures.h =================================================================== --- libc/src/__support/macros/properties/architectures.h +++ libc/src/__support/macros/properties/architectures.h @@ -45,6 +45,10 @@ #define LIBC_TARGET_ARCH_IS_AARCH64 #endif +#if defined(__riscv) && (__riscv_xlen == 64) +#define LIBC_TARGET_ARCH_IS_RISCV64 +#endif + #if (defined(LIBC_TARGET_ARCH_IS_AARCH64) || defined(LIBC_TARGET_ARCH_IS_ARM)) #define LIBC_TARGET_ARCH_IS_ANY_ARM #endif Index: libc/src/__support/macros/properties/cpu_features.h =================================================================== --- libc/src/__support/macros/properties/cpu_features.h +++ libc/src/__support/macros/properties/cpu_features.h @@ -36,7 +36,7 @@ #define LIBC_TARGET_CPU_HAS_AVX512BW #endif -#if defined(__ARM_FEATURE_FMA) || defined(__AVX2__) || defined(__FMA__) +#if defined(__ARM_FEATURE_FMA) || defined(__AVX2__) || defined(__FMA__) || defined(__riscv) #define LIBC_TARGET_CPU_HAS_FMA #endif Index: libc/src/__support/threads/linux/thread.cpp =================================================================== --- libc/src/__support/threads/linux/thread.cpp +++ libc/src/__support/threads/linux/thread.cpp @@ -111,6 +111,9 @@ // is set to the stack pointer where start args are stored. So, we fetch // from there. return reinterpret_cast(__builtin_frame_address(1)); +#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) + // TODO + return 0; #endif } @@ -206,6 +209,9 @@ tls.tp, // The thread pointer value for the new thread. &clear_tid->val // The futex where the child thread status is signalled ); +#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) + // TODO + long register clone_result asm("x0"); #else #error "Unsupported architecture for the clone syscall." #endif Index: libc/src/__support/threads/thread.h =================================================================== --- libc/src/__support/threads/thread.h +++ libc/src/__support/threads/thread.h @@ -37,7 +37,8 @@ }; #if (defined(LIBC_TARGET_ARCH_IS_AARCH64) || \ - defined(LIBC_TARGET_ARCH_IS_X86_64)) + defined(LIBC_TARGET_ARCH_IS_X86_64) || \ + defined(LIBC_TARGET_ARCH_IS_RISCV64)) constexpr unsigned int STACK_ALIGNMENT = 16; #endif // TODO: Provide stack alignment requirements for other architectures. Index: libc/src/stdlib/linux/CMakeLists.txt =================================================================== --- libc/src/stdlib/linux/CMakeLists.txt +++ libc/src/stdlib/linux/CMakeLists.txt @@ -19,5 +19,5 @@ DEPENDS libc.include.stdlib libc.src.signal.raise - ._Exit + libc.src.stdlib._Exit ) Index: libc/utils/HdrGen/CMakeLists.txt =================================================================== --- libc/utils/HdrGen/CMakeLists.txt +++ libc/utils/HdrGen/CMakeLists.txt @@ -14,7 +14,7 @@ PublicAPICommand.h ) -target_include_directories(libc-hdrgen PRIVATE ${LIBC_SOURCE_DIR} ${LLVM_LIBC_INCLUDE_DIRS}) +target_include_directories(libc-hdrgen PRIVATE ${LIBC_SOURCE_DIR}) target_link_libraries(libc-hdrgen PRIVATE LibcTableGenUtil) add_subdirectory(PrototypeTestGen) Index: libc/utils/LibcTableGenUtil/CMakeLists.txt =================================================================== --- libc/utils/LibcTableGenUtil/CMakeLists.txt +++ libc/utils/LibcTableGenUtil/CMakeLists.txt @@ -4,4 +4,4 @@ APIIndexer.h LINK_COMPONENTS Support TableGen ) -target_include_directories(LibcTableGenUtil PUBLIC ${LIBC_SOURCE_DIR} ${LLVM_LIBC_INCLUDE_DIRS}) +target_include_directories(LibcTableGenUtil PUBLIC ${LIBC_SOURCE_DIR})