diff --git a/compiler-rt/lib/builtins/loongarch/fp_mode.c b/compiler-rt/lib/builtins/loongarch/fp_mode.c --- 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 @@ 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 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -507,8 +507,13 @@ ThreadDescriptorSize(); *size = g_tls_size + ThreadDescriptorSize(); #elif SANITIZER_GLIBC && defined(__loongarch__) +# ifdef __clang__ *addr = reinterpret_cast(__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.