[libc] Initiliaze the global pointer in riscv startup code.
authorSiva Chandra <sivachandra@google.com>
Fri, 26 May 2023 08:08:46 +0000 (08:08 +0000)
committerSiva Chandra <sivachandra@google.com>
Wed, 5 Jul 2023 07:32:31 +0000 (07:32 +0000)
Reviewed By: mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D151539

libc/startup/linux/riscv64/start.cpp
libc/test/src/stdio/CMakeLists.txt

index 80e7d3f..67aa3e6 100644 (file)
@@ -123,6 +123,10 @@ struct AuxEntry {
 };
 
 __attribute__((noinline)) static void do_start() {
+  LIBC_INLINE_ASM(".option push\n\t"
+                  ".option norelax\n\t"
+                  "lla gp, __global_pointer$\n\t"
+                  ".option pop\n\t");
   auto tid = __llvm_libc::syscall_impl(SYS_gettid);
   if (tid <= 0)
     __llvm_libc::syscall_impl(SYS_exit, 1);
index 19fd494..c138f35 100644 (file)
@@ -114,6 +114,7 @@ add_libc_unittest(
 
 add_fp_unittest(
   sprintf_test
+  UNIT_TEST_ONLY
   SUITE
     libc_stdio_unittests
   SRCS