This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add riscv64 syscall implementation.
ClosedPublic

Authored by sivachandra on Mar 6 2023, 5:04 PM.

Details

Summary

All syscall wrapper functions which have unit tests have been enabled.

Diff Detail

Event Timeline

sivachandra created this revision.Mar 6 2023, 5:04 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 6 2023, 5:04 PM
sivachandra requested review of this revision.Mar 6 2023, 5:04 PM

@mikhail.ramalho - Feel free to submit this if you like it.

kito-cheng accepted this revision.Mar 6 2023, 6:15 PM

Per my experience from RISC-V newlib port, LGTM.

This revision is now accepted and ready to land.Mar 6 2023, 6:15 PM
jrtc27 added inline comments.Mar 6 2023, 6:42 PM
libc/src/__support/OSUtil/linux/riscv64/syscall.h
44

What condition codes?

  • Remove a copy paste remnant from the syscall implementation.
  • Enable more string functions.
libc/src/__support/OSUtil/linux/riscv64/syscall.h
44

Thanks for catching - it was a copy-paste remnant which I have now removed.

arichardson added inline comments.Mar 6 2023, 11:24 PM
libc/src/__support/OSUtil/linux/riscv64/syscall.h
11

Copy paste error in the include guard

Fix more typos.

Hey @sivachandra, we seem to need the signal-macros.h and the fenv stuff to get this patch compiling:

/home/mgadelha/llvm-project/build/projects/libc/include/llvm-libc-macros/linux/signal-macros.h:86:2: error: "Signal stack sizes not defined for your platform."
#error "Signal stack sizes not defined for your platform."
 ^
1 error generated.
/home/mgadelha/llvm-project/libc/src/__support/FPUtil/FEnvImpl.h:51:25: error: unknown type name 'fenv_t'
LIBC_INLINE int get_env(fenv_t *) { return 0; }
                        ^
/home/mgadelha/llvm-project/libc/src/__support/FPUtil/FEnvImpl.h:53:31: error: unknown type name 'fenv_t'
LIBC_INLINE int set_env(const fenv_t *) { return 0; }
                              ^
2 errors generated.

This was enough to fix compilation, and all tests are passing:

diff --git a/libc/include/llvm-libc-macros/linux/signal-macros.h b/libc/include/llvm-libc-macros/linux/signal-macros.h
index 069a23347797..4dc39dec47de 100644
--- a/libc/include/llvm-libc-macros/linux/signal-macros.h
+++ b/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
diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
index ec21555071c8..179140ae6b9b 100644
--- a/libc/src/__support/FPUtil/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -48,9 +48,9 @@ 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

@mikhail.ramalho - there are two modes for building the libc, the overlay mode and the full build mode. With this patch, I am only bringing up the overlay mode. The signal macros and fenv pieces become relevant in the full build mode. Can we do them as follow ups?

Oh, I see, my mistake! I was always building with -DLLVM_LIBC_FULL_BUILD=ON

I agree, let's disable it for now.

Em ter., 7 de mar. de 2023 às 16:55, Siva Chandra via Phabricator <
reviews@reviews.llvm.org> escreveu:

sivachandra added a comment.

@mikhail.ramalho - there are two modes for building the libc, the overlay
mode and the full build mode. With this patch, I am only bringing up the
overlay mode. The signal macros and fenv pieces become relevant in the full
build mode. Can we do them as follow ups?

Repository:

rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION

https://reviews.llvm.org/D145452/new/

https://reviews.llvm.org/D145452