Skip to content

Commit

Permalink
[libc] Enable most of the libc entrypoitns for riscv (llvm#99771)
Browse files Browse the repository at this point in the history
This patch enables most of the libc entrypoints for riscv, except for fstatvfs, statvfs, dmull and fmull which are currently failing compilation. float16 is also not added, as rv32 doesn't seem to support it yet.

This patch also fixes the call to seek, which should take an off_t, and was missed in PR llvm#68269.
  • Loading branch information
mikhailramalho authored and sgundapa committed Jul 23, 2024
1 parent 390da3e commit d33cd41
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 16 deletions.
107 changes: 97 additions & 10 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.tolower
libc.src.ctype.toupper

# dlfcn.h entrypoints
libc.src.dlfcn.dlclose
libc.src.dlfcn.dlerror
libc.src.dlfcn.dlopen
libc.src.dlfcn.dlsym

# errno.h entrypoints
libc.src.errno.errno

Expand Down Expand Up @@ -52,6 +58,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.mempcpy
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.memset_explicit
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
Expand Down Expand Up @@ -180,6 +187,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.qsort_r
libc.src.stdlib.rand
libc.src.stdlib.srand
libc.src.stdlib.strfromd
libc.src.stdlib.strfromf
libc.src.stdlib.strfroml
libc.src.stdlib.strtod
libc.src.stdlib.strtof
libc.src.stdlib.strtol
Expand All @@ -197,6 +207,7 @@ set(TARGET_LIBC_ENTRYPOINTS

# stdio.h entrypoints
libc.src.stdio.fdopen
libc.src.stdio.fileno
libc.src.stdio.fprintf
libc.src.stdio.fscanf
libc.src.stdio.printf
Expand All @@ -211,6 +222,14 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.vsnprintf
libc.src.stdio.vsprintf

# sys/epoll.h entrypoints
libc.src.sys.epoll.epoll_create
libc.src.sys.epoll.epoll_create1
libc.src.sys.epoll.epoll_ctl
libc.src.sys.epoll.epoll_pwait
libc.src.sys.epoll.epoll_wait
libc.src.sys.epoll.epoll_pwait2

# sys/mman.h entrypoints
libc.src.sys.mman.madvise
libc.src.sys.mman.mincore
Expand Down Expand Up @@ -261,12 +280,6 @@ set(TARGET_LIBC_ENTRYPOINTS
# sys/auxv.h entrypoints
libc.src.sys.auxv.getauxval

# sys/epoll.h entrypoints
# Disabled due to epoll_wait syscalls not being available on this platform.
# libc.src.sys.epoll.epoll_wait
# libc.src.sys.epoll.epoll_pwait
# libc.src.sys.epoll.epoll_pwait2

# termios.h entrypoints
libc.src.termios.cfgetispeed
libc.src.termios.cfgetospeed
Expand Down Expand Up @@ -303,6 +316,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.linkat
libc.src.unistd.lseek
libc.src.unistd.pathconf
libc.src.unistd.pipe
libc.src.unistd.pread
libc.src.unistd.pwrite
libc.src.unistd.read
Expand Down Expand Up @@ -348,6 +362,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.atan2f
libc.src.math.atanf
libc.src.math.atanhf
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
Expand All @@ -366,6 +383,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.exp10f
libc.src.math.exp2
libc.src.math.exp2f
libc.src.math.exp2m1f
libc.src.math.expf
libc.src.math.expm1
libc.src.math.expm1f
Expand Down Expand Up @@ -493,6 +511,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintf
libc.src.math.rintl
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
libc.src.math.scalbn
Expand Down Expand Up @@ -524,8 +545,10 @@ set(TARGET_LIBM_ENTRYPOINTS
if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.dmulf128
libc.src.math.fabsf128
libc.src.math.fdimf128
libc.src.math.floorf128
Expand All @@ -540,6 +563,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fminimum_numf128
libc.src.math.fminimumf128
libc.src.math.fmodf128
libc.src.math.fmulf128
libc.src.math.frexpf128
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
Expand All @@ -557,7 +581,9 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalbnf128
libc.src.math.sqrtf128
Expand All @@ -567,14 +593,47 @@ if(LIBC_TYPES_HAS_FLOAT128)
)
endif()

if(LIBC_COMPILER_HAS_FIXED_POINT)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# stdfix.h _Fract and _Accum entrypoints
libc.src.stdfix.abshk
libc.src.stdfix.abshr
libc.src.stdfix.absk
libc.src.stdfix.abslk
libc.src.stdfix.abslr
libc.src.stdfix.absr
libc.src.stdfix.exphk
libc.src.stdfix.expk
libc.src.stdfix.roundhk
libc.src.stdfix.roundhr
libc.src.stdfix.roundk
libc.src.stdfix.roundlk
libc.src.stdfix.roundlr
libc.src.stdfix.roundr
libc.src.stdfix.rounduhk
libc.src.stdfix.rounduhr
libc.src.stdfix.rounduk
libc.src.stdfix.roundulk
libc.src.stdfix.roundulr
libc.src.stdfix.roundur
libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuhr
libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtur
libc.src.stdfix.sqrtulr
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
)
endif()

if(LLVM_LIBC_FULL_BUILD)
list(APPEND TARGET_LIBC_ENTRYPOINTS
# compiler entrypoints (no corresponding header)
libc.src.compiler.__stack_chk_fail

# assert.h entrypoints
libc.src.assert.__assert_fail

# compiler entrypoints (no corresponding header)
libc.src.compiler.__stack_chk_fail

# dirent.h entrypoints
libc.src.dirent.closedir
libc.src.dirent.dirfd
Expand All @@ -599,6 +658,12 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.pthread.pthread_attr_setguardsize
libc.src.pthread.pthread_attr_setstack
libc.src.pthread.pthread_attr_setstacksize
libc.src.pthread.pthread_condattr_destroy
libc.src.pthread.pthread_condattr_getclock
libc.src.pthread.pthread_condattr_getpshared
libc.src.pthread.pthread_condattr_init
libc.src.pthread.pthread_condattr_setclock
libc.src.pthread.pthread_condattr_setpshared
libc.src.pthread.pthread_create
libc.src.pthread.pthread_detach
libc.src.pthread.pthread_equal
Expand All @@ -621,6 +686,21 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.pthread.pthread_mutexattr_setrobust
libc.src.pthread.pthread_mutexattr_settype
libc.src.pthread.pthread_once
libc.src.pthread.pthread_rwlock_destroy
libc.src.pthread.pthread_rwlock_init
libc.src.pthread.pthread_rwlock_rdlock
libc.src.pthread.pthread_rwlock_timedrdlock
libc.src.pthread.pthread_rwlock_timedwrlock
libc.src.pthread.pthread_rwlock_tryrdlock
libc.src.pthread.pthread_rwlock_trywrlock
libc.src.pthread.pthread_rwlock_unlock
libc.src.pthread.pthread_rwlock_wrlock
libc.src.pthread.pthread_rwlockattr_destroy
libc.src.pthread.pthread_rwlockattr_getkind_np
libc.src.pthread.pthread_rwlockattr_getpshared
libc.src.pthread.pthread_rwlockattr_init
libc.src.pthread.pthread_rwlockattr_setkind_np
libc.src.pthread.pthread_rwlockattr_setpshared
libc.src.pthread.pthread_self
libc.src.pthread.pthread_setname_np
libc.src.pthread.pthread_setspecific
Expand All @@ -644,7 +724,6 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdio.fgetc
libc.src.stdio.fgetc_unlocked
libc.src.stdio.fgets
libc.src.stdio.fileno
libc.src.stdio.flockfile
libc.src.stdio.fopen
libc.src.stdio.fopencookie
Expand All @@ -653,7 +732,9 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdio.fread
libc.src.stdio.fread_unlocked
libc.src.stdio.fseek
libc.src.stdio.fseeko
libc.src.stdio.ftell
libc.src.stdio.ftello
libc.src.stdio.funlockfile
libc.src.stdio.fwrite
libc.src.stdio.fwrite_unlocked
Expand All @@ -674,9 +755,11 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
libc.src.stdlib.getenv
libc.src.stdlib.quick_exit

# signal.h entrypoints
libc.src.signal.kill
Expand Down Expand Up @@ -758,6 +841,10 @@ if(LLVM_LIBC_FULL_BUILD)

# sys/select.h entrypoints
libc.src.sys.select.select

# sys/socket.h entrypoints
libc.src.sys.socket.bind
libc.src.sys.socket.socket
)
endif()

Expand Down
4 changes: 1 addition & 3 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.epoll.epoll_ctl
libc.src.sys.epoll.epoll_pwait
libc.src.sys.epoll.epoll_wait
# TODO: Need to check if pwait2 is available before providing.
# https://github.com/llvm/llvm-project/issues/80060
# libc.src.sys.epoll.epoll_pwait2
libc.src.sys.epoll.epoll_pwait2

# sys/mman.h entrypoints
libc.src.sys.mman.madvise
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/File/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int File::ungetc_unlocked(int c) {
return c;
}

ErrorOr<int> File::seek(long offset, int whence) {
ErrorOr<int> File::seek(off_t offset, int whence) {
FileLock lock(this);
if (prev_op == FileOp::WRITE && pos > 0) {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/File/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class File {
return read_unlocked(data, len);
}

ErrorOr<int> seek(long offset, int whence);
ErrorOr<int> seek(off_t offset, int whence);

ErrorOr<off_t> tell();

Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/__support/File/platform_file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ TEST(LlvmLibcPlatformFileTest, CreateAppendSeekAndReadBack) {
constexpr size_t APPEND_TEXT_SIZE = sizeof(APPEND_TEXT) - 1;
ASSERT_EQ(file->write(APPEND_TEXT, APPEND_TEXT_SIZE).value, APPEND_TEXT_SIZE);

ASSERT_EQ(file->seek(-APPEND_TEXT_SIZE, SEEK_END).value(), 0);
ASSERT_EQ(file->seek(-static_cast<off_t>(APPEND_TEXT_SIZE), SEEK_END).value(),
0);
char data[APPEND_TEXT_SIZE + 1];
ASSERT_EQ(file->read(data, APPEND_TEXT_SIZE).value, APPEND_TEXT_SIZE);
data[APPEND_TEXT_SIZE] = '\0';
Expand Down

0 comments on commit d33cd41

Please sign in to comment.