)
add_subdirectory(FPUtil)
+add_subdirectory(OSUtil)
--- /dev/null
+add_subdirectory(linux)
+
+add_header_library(
+ osutil
+ HDRS
+ io.h
+ quick_exit.h
+ DEPENDS
+ libc.src.__support.OSUtil.linux.linux_util
+)
--- /dev/null
+//===---------------- Implementation of IO utils ----------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_IO_H
+#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_IO_H
+
+#ifdef __unix__
+#include "linux/io.h"
+#endif
+
+#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_IO_H
--- /dev/null
+add_header_library(
+ linux_util
+ HDRS
+ io.h
+ quick_exit.h
+ DEPENDS
+ libc.config.linux.linux_syscall_h
+ libc.include.sys_syscall
+ libc.src.string.string_utils
+)
--- /dev/null
+//===-------------- Linux implementation of IO utils ------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_IO_H
+#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_IO_H
+
+#include "config/linux/syscall.h" // For internal syscall function.
+#include "include/sys/syscall.h" // For syscall numbers.
+#include "src/string/string_utils.h"
+
+namespace __llvm_libc {
+
+static inline void write_to_stderr(const char *msg) {
+ __llvm_libc::syscall(SYS_write, 2 /* stderr */, msg,
+ internal::string_length(msg));
+}
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_IO_H
--- /dev/null
+//===---------- Linux implementation of a quick exit function ---*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_QUICK_EXIT_H
+#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_QUICK_EXIT_H
+
+#include "config/linux/syscall.h" // For internal syscall function.
+#include "include/sys/syscall.h" // For syscall numbers.
+
+namespace __llvm_libc {
+
+static inline void quick_exit(int status) {
+ for (;;) {
+ __llvm_libc::syscall(SYS_exit_group, status);
+ __llvm_libc::syscall(SYS_exit, status);
+ }
+}
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_QUICK_EXIT_H
--- /dev/null
+//===---------- Implementation of a quick exit function ---------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_QUICK_EXIT_H
+#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_QUICK_EXIT_H
+
+#ifdef __unix__
+#include "linux/quick_exit.h"
+#endif
+
+#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_QUICK_EXIT_H
return()
endif()
+add_header_library(
+ loader_test
+ HDRS
+ loader_test.h
+ DEPENDS
+ libc.src.__support.OSUtil.osutil
+)
+
add_loader_test(
loader_args_test
SRC
args_test.cpp
DEPENDS
+ .loader_test
libc.loader.linux.crt1
- libc.src.assert.__assert_fail
- libc.src.signal.raise
- libc.src.stdlib._Exit
- libc.src.stdlib.abort
ARGS
1 2 3
ENV
SRC
main_without_envp.cpp
DEPENDS
+ .loader_test
libc.loader.linux.crt1
)
SRC
main_without_args.cpp
DEPENDS
+ .loader_test
libc.loader.linux.crt1
)
//
//===----------------------------------------------------------------------===//
-#undef NDEBUG
-#include "src/assert/assert.h"
+#include "loader_test.h"
static bool my_streq(const char *lhs, const char *rhs) {
const char *l, *r;
}
int main(int argc, char **argv, char **envp) {
- assert(argc == 4 && "Unexpected argc.");
- assert(my_streq(argv[1], "1") && "Unexpected argv[1].");
- assert(my_streq(argv[2], "2") && "Unexpected argv[2].");
- assert(my_streq(argv[3], "3") && "Unexpected argv[3].");
+ ASSERT_TRUE(argc == 4);
+ ASSERT_TRUE(my_streq(argv[1], "1"));
+ ASSERT_TRUE(my_streq(argv[2], "2"));
+ ASSERT_TRUE(my_streq(argv[3], "3"));
bool found_france = false;
bool found_germany = false;
found_germany = true;
}
- assert(found_france && found_germany &&
- "Did not find whats expected in envp.");
+ ASSERT_TRUE(found_france && found_germany);
return 0;
}
--- /dev/null
+//===-- Simple checkers for loader tests ------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TEST_LOADER_LINUX_LOADER_TEST_H
+#define LLVM_LIBC_TEST_LOADER_LINUX_LOADER_TEST_H
+
+#include "src/__support/OSUtil/io.h"
+#include "src/__support/OSUtil/quick_exit.h"
+
+#define __AS_STRING(val) #val
+#define __CHECK(file, line, val, should_exit) \
+ if (!(val)) { \
+ __llvm_libc::write_to_stderr(file ":" __AS_STRING( \
+ line) ": Expected '" #val "' to be true, but is false\n"); \
+ if (should_exit) \
+ __llvm_libc::quick_exit(127); \
+ }
+
+#define EXPECT_TRUE(val) __CHECK(__FILE__, __LINE__, val, false)
+#define ASSERT_TRUE(val) __CHECK(__FILE__, __LINE__, val, true)
+
+#endif // LLVM_LIBC_TEST_LOADER_LINUX_LOADER_TEST_H