[compiler-rt] 2b15c63 - [compiler-rt] Fix build errors when using gcc on LoongArch
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 25 17:41:26 PST 2022
Author: Youling Tang
Date: 2022-12-26T09:33:54+08:00
New Revision: 2b15c63fb73011610ae83c05d0260e2dccf299fc
URL: https://github.com/llvm/llvm-project/commit/2b15c63fb73011610ae83c05d0260e2dccf299fc
DIFF: https://github.com/llvm/llvm-project/commit/2b15c63fb73011610ae83c05d0260e2dccf299fc.diff
LOG: [compiler-rt] Fix build errors when using gcc on LoongArch
- GCC does not recognize $fcsr0, uses $r0 instead.
- GCC does not implement __builtin_thread_pointer, which can be
obtained directly through $tp.
Reviewed By: SixWeining
Differential Revision: https://reviews.llvm.org/D140545
Added:
Modified:
compiler-rt/lib/builtins/loongarch/fp_mode.c
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/builtins/loongarch/fp_mode.c b/compiler-rt/lib/builtins/loongarch/fp_mode.c
index 0e3d7964786b..31877fb02bd5 100644
--- a/compiler-rt/lib/builtins/loongarch/fp_mode.c
+++ b/compiler-rt/lib/builtins/loongarch/fp_mode.c
@@ -20,7 +20,11 @@
CRT_FE_ROUND_MODE __fe_getround(void) {
#if __loongarch_frlen != 0
int fcsr;
+# ifdef __clang__
__asm__ __volatile__("movfcsr2gr %0, $fcsr0" : "=r" (fcsr));
+# else
+ __asm__ __volatile__("movfcsr2gr %0, $r0" : "=r" (fcsr));
+# endif
fcsr &= LOONGARCH_RMODE_MASK;
switch (fcsr) {
case LOONGARCH_TOWARDZERO:
@@ -41,9 +45,15 @@ CRT_FE_ROUND_MODE __fe_getround(void) {
int __fe_raise_inexact(void) {
#if __loongarch_frlen != 0
int fcsr;
+# ifdef __clang__
__asm__ __volatile__("movfcsr2gr %0, $fcsr0" : "=r" (fcsr));
__asm__ __volatile__(
"movgr2fcsr $fcsr0, %0" :: "r" (fcsr | LOONGARCH_INEXACT));
+# else
+ __asm__ __volatile__("movfcsr2gr %0, $r0" : "=r" (fcsr));
+ __asm__ __volatile__(
+ "movgr2fcsr $r0, %0" :: "r" (fcsr | LOONGARCH_INEXACT));
+# endif
#endif
return 0;
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index 6ceaf94a91d8..ec860fdc4ff9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -507,8 +507,13 @@ static void GetTls(uptr *addr, uptr *size) {
ThreadDescriptorSize();
*size = g_tls_size + ThreadDescriptorSize();
#elif SANITIZER_GLIBC && defined(__loongarch__)
+# ifdef __clang__
*addr = reinterpret_cast<uptr>(__builtin_thread_pointer()) -
ThreadDescriptorSize();
+# else
+ asm("or %0,$tp,$zero" : "=r"(*addr));
+ *addr -= ThreadDescriptorSize();
+# endif
*size = g_tls_size + ThreadDescriptorSize();
#elif SANITIZER_GLIBC && defined(__powerpc64__)
// Workaround for glibc<2.25(?). 2.27 is known to not need this.
More information about the llvm-commits
mailing list