aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2020-06-24 14:12:46 -0700
committerSiva Chandra Reddy <sivachandra@google.com>2020-08-07 23:19:03 -0700
commit5d59385ba67ec20dc4a3e13b9a7088ace970df4d (patch)
treef976a0309b0014c184298f1691061f2131b2b6fc /libc/test
parent595d3b5ecc59d1c89a8eefbfc37083b0d45f502f (diff)
downloadllvm-project-5d59385ba67ec20dc4a3e13b9a7088ace970df4d.tar.gz
[libc] Setup TLS in x86_64 loader.
The new code added is still very x86_64 specific. AArch64 support will be added very soon and refactoring of the loader code will be done as part of the patches adding it. Reviewed By: asteinhauser Differential Revision: https://reviews.llvm.org/D82700
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/loader/CMakeLists.txt9
-rw-r--r--libc/test/loader/linux/CMakeLists.txt14
-rw-r--r--libc/test/loader/linux/tls_test.cpp40
3 files changed, 60 insertions, 3 deletions
diff --git a/libc/test/loader/CMakeLists.txt b/libc/test/loader/CMakeLists.txt
index a38d3884ded6..5123bed8aaa9 100644
--- a/libc/test/loader/CMakeLists.txt
+++ b/libc/test/loader/CMakeLists.txt
@@ -37,9 +37,12 @@ function(add_loader_test target_name)
${LIBC_BUILD_DIR}/include
)
- get_fq_deps_list(fq_deps_list ${ADD_LOADER_TEST_DEPENDS})
- get_object_files_for_test(link_object_files has_skipped_entrypoint_list ${fq_deps_list})
- target_link_libraries(${fq_target_name} ${link_object_files})
+ if(ADD_LOADER_TEST_DEPENDS)
+ get_fq_deps_list(fq_deps_list ${ADD_LOADER_TEST_DEPENDS})
+ add_dependencies(${fq_target_name} ${fq_deps_list})
+ get_object_files_for_test(link_object_files has_skipped_entrypoint_list ${fq_deps_list})
+ target_link_libraries(${fq_target_name} ${link_object_files})
+ endif()
target_link_options(
${fq_target_name}
diff --git a/libc/test/loader/linux/CMakeLists.txt b/libc/test/loader/linux/CMakeLists.txt
index 1f47b2ce3f06..b7899fa4c5c1 100644
--- a/libc/test/loader/linux/CMakeLists.txt
+++ b/libc/test/loader/linux/CMakeLists.txt
@@ -35,3 +35,17 @@ add_loader_test(
DEPENDS
libc.loader.linux.crt1
)
+
+add_loader_test(
+ loader_tls_test
+ SRC
+ tls_test.cpp
+ DEPENDS
+ libc.config.linux.app_h
+ libc.include.errno
+ libc.include.sys_mman
+ libc.loader.linux.crt1
+ libc.src.assert.__assert_fail
+ libc.src.errno.__errno_location
+ libc.src.sys.mman.mmap
+)
diff --git a/libc/test/loader/linux/tls_test.cpp b/libc/test/loader/linux/tls_test.cpp
new file mode 100644
index 000000000000..144d894a2caf
--- /dev/null
+++ b/libc/test/loader/linux/tls_test.cpp
@@ -0,0 +1,40 @@
+//===-- Loader test to check if tls size is read correctly ----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "include/errno.h"
+#include "include/sys/mman.h"
+
+#undef NDEBUG
+#include "src/assert/assert.h"
+
+#include "src/errno/llvmlibc_errno.h"
+#include "src/sys/mman/mmap.h"
+
+constexpr int threadLocalDataSize = 101;
+_Thread_local int a[threadLocalDataSize] = {123};
+
+int main(int argc, char **argv, char **envp) {
+ assert(a[0] == 123);
+
+ for (int i = 1; i < threadLocalDataSize; ++i)
+ a[i] = i;
+ for (int i = 1; i < threadLocalDataSize; ++i)
+ assert(a[i] == i);
+
+ // Call mmap with bad params so that an error value is
+ // set in errno. Since errno is implemented using a thread
+ // local var, this helps us test setting of errno and
+ // reading it back.
+ assert(llvmlibc_errno == 0);
+ void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ assert(addr == MAP_FAILED);
+ assert(llvmlibc_errno == EINVAL);
+
+ return 0;
+}