diff --git a/Makefile b/Makefile index 5ee9c2d7d..a1d0a315b 100644 --- a/Makefile +++ b/Makefile @@ -12,21 +12,13 @@ INSTALL_DIR ?= /usr/local THREAD_MODEL ?= single # yes or no BUILD_DLMALLOC ?= yes -BUILD_LIBC_BOTTOM_HALF ?= yes BUILD_LIBC_TOP_HALF ?= yes # The directory where we're store intermediate artifacts. OBJDIR ?= $(CURDIR)/build # Check dependencies. -ifeq ($(BUILD_LIBC_TOP_HALF),yes) -ifneq ($(BUILD_LIBC_BOTTOM_HALF),yes) -$(error BUILD_LIBC_TOP_HALF=yes depends on BUILD_LIBC_BOTTOM_HALF=yes) -endif -endif -ifeq ($(BUILD_LIBC_BOTTOM_HALF),yes) ifneq ($(BUILD_DLMALLOC),yes) -$(error BUILD_LIBC_BOTTOM_HALF=yes depends on BUILD_DLMALLOC=yes) -endif +$(error build currently depends on BUILD_DLMALLOC=yes) endif # Variables from this point on are not meant to be overridable via the @@ -39,12 +31,6 @@ MULTIARCH_TRIPLE = wasm32-wasi # These variables describe the locations of various files and directories in # the source tree. -BASICS_DIR = $(CURDIR)/basics -BASICS_INC = $(BASICS_DIR)/include -BASICS_CRT_SOURCES = $(wildcard $(BASICS_DIR)/crt/*.c) -BASICS_SOURCES = \ - $(wildcard $(BASICS_DIR)/sources/*.c) \ - $(wildcard $(BASICS_DIR)/sources/math/*.c) DLMALLOC_DIR = $(CURDIR)/dlmalloc DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/dlmalloc.c @@ -209,25 +195,15 @@ WASM_CFLAGS += --sysroot="$(SYSROOT)" # These variables describe the locations of various files and directories in # the build tree. objs = $(patsubst $(CURDIR)/%.c,$(OBJDIR)/%.o,$(1)) -BASICS_OBJS = $(call objs,$(BASICS_SOURCES)) DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) LIBC_TOP_HALF_ALL_OBJS = $(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)) -LIBC_OBJS := $(BASICS_OBJS) ifeq ($(BUILD_DLMALLOC),yes) LIBC_OBJS += $(DLMALLOC_OBJS) endif -ifeq ($(BUILD_LIBC_BOTTOM_HALF),yes) -# Override basics' string.o with libc-bottom-half's. -LIBC_OBJS := $(filter-out %/string.o,$(LIBC_OBJS)) # Add libc-bottom-half's objects. LIBC_OBJS += $(LIBC_BOTTOM_HALF_ALL_OBJS) -endif ifeq ($(BUILD_LIBC_TOP_HALF),yes) -# Override libc-bottom-half's string.o with libc-top-half's. -LIBC_OBJS := $(filter-out %/string.o,$(LIBC_OBJS)) -# Override libc-bottom-half's qsort.o with libc-top-half's. -LIBC_OBJS := $(filter-out %/qsort.o,$(LIBC_OBJS)) # libc-top-half is musl. LIBC_OBJS += $(LIBC_TOP_HALF_ALL_OBJS) endif @@ -405,7 +381,6 @@ include_dirs: # Install the include files. # mkdir -p "$(SYSROOT_INC)" - cp -r "$(BASICS_INC)" "$(SYSROOT)" cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)" # Generate musl's bits/alltypes.h header. @@ -424,19 +399,13 @@ include_dirs: # Remove selected header files. $(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS)) -ifeq ($(BUILD_LIBC_BOTTOM_HALF),no) -CRT_SOURCES = $(BASICS_CRT_SOURCES) -else -CRT_SOURCES = $(LIBC_BOTTOM_HALF_CRT_SOURCES) -endif - startup_files: include_dirs # # Build the startup files. # @mkdir -p "$(OBJDIR)" cd "$(OBJDIR)" && \ - "$(WASM_CC)" $(WASM_CFLAGS) -c $(CRT_SOURCES) -MD -MP && \ + "$(WASM_CC)" $(WASM_CFLAGS) -c $(LIBC_BOTTOM_HALF_CRT_SOURCES) -MD -MP && \ mkdir -p "$(SYSROOT_LIB)" && \ mv *.o "$(SYSROOT_LIB)" diff --git a/basics/crt/crt1.c b/basics/crt/crt1.c deleted file mode 100644 index dc0009f9b..000000000 --- a/basics/crt/crt1.c +++ /dev/null @@ -1,23 +0,0 @@ -extern void __wasm_call_ctors(void); -extern int __original_main(void); -extern void __prepare_for_exit(void); -void _Exit(int) __attribute__((noreturn)); - -__attribute__((export_name("_start"))) -void _start(void) { - // The linker synthesizes this to call constructors. - __wasm_call_ctors(); - - // Call `__original_main` which will either be the application's zero-argument - // `__original_main` function or a libc routine which calls `__main_void`. - // TODO: Call `main` directly once we no longer have to support old compilers. - int r = __original_main(); - - // Call atexit functions, destructors, stdio cleanup, etc. - __prepare_for_exit(); - - // If main exited successfully, just return, otherwise call _Exit. - if (r != 0) { - _Exit(r); - } -} diff --git a/basics/include/__typedef_blksize_t.h b/basics/include/__typedef_blksize_t.h deleted file mode 100644 index 958fe4a5c..000000000 --- a/basics/include/__typedef_blksize_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasm_basics___typedef_blksize_t_h -#define __wasm_basics___typedef_blksize_t_h - -typedef long blksize_t; - -#endif diff --git a/basics/include/__typedef_gid_t.h b/basics/include/__typedef_gid_t.h deleted file mode 100644 index 84dff908f..000000000 --- a/basics/include/__typedef_gid_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasm_basics___typedef_gid_t_h -#define __wasm_basics___typedef_gid_t_h - -typedef unsigned gid_t; - -#endif diff --git a/basics/include/__typedef_mode_t.h b/basics/include/__typedef_mode_t.h deleted file mode 100644 index 398f64cc8..000000000 --- a/basics/include/__typedef_mode_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasm_basics___typedef_mode_t_h -#define __wasm_basics___typedef_mode_t_h - -typedef unsigned mode_t; - -#endif diff --git a/basics/include/__typedef_uid_t.h b/basics/include/__typedef_uid_t.h deleted file mode 100644 index 89583f9fa..000000000 --- a/basics/include/__typedef_uid_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasm_basics___typedef_uid_t_h -#define __wasm_basics___typedef_uid_t_h - -typedef unsigned uid_t; - -#endif diff --git a/basics/include/errno.h b/basics/include/errno.h deleted file mode 100644 index 2d1b29aff..000000000 --- a/basics/include/errno.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasm_basics_errno_h -#define __wasm_basics_errno_h - -#include <__errno.h> - -#endif diff --git a/basics/include/stdlib.h b/basics/include/stdlib.h deleted file mode 100644 index 170efe90a..000000000 --- a/basics/include/stdlib.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasm_basics_stdlib_h -#define __wasm_basics_stdlib_h - -/* - * Include the real implementation, which is factored into a separate file so - * that it can be reused by other libc stdlib implementations. - */ -#include <__functions_malloc.h> - -#endif diff --git a/basics/include/string.h b/basics/include/string.h deleted file mode 100644 index 54dd84195..000000000 --- a/basics/include/string.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasm_basics_string_h -#define __wasm_basics_string_h - -/* - * Include the real implementation, which is factored into a separate file so - * that it can be reused by other libc string implementations. - */ -#include <__functions_memcpy.h> - -#endif diff --git a/basics/include/sys/stat.h b/basics/include/sys/stat.h deleted file mode 100644 index dac5b861d..000000000 --- a/basics/include/sys/stat.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasm_basics_sys_stat_h -#define __wasm_basics_sys_stat_h - -#include <__struct_stat.h> - -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - -#endif diff --git a/basics/include/sys/types.h b/basics/include/sys/types.h deleted file mode 100644 index a7ce94561..000000000 --- a/basics/include/sys/types.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __wasm_basics_sys_types_h -#define __wasm_basics_sys_types_h - -#define __need_size_t -#include - -#include <__typedef_clock_t.h> -#include <__typedef_time_t.h> -#include <__typedef_blksize_t.h> -#include <__typedef_off_t.h> -#include <__typedef_ssize_t.h> -#include <__typedef_suseconds_t.h> -#include <__typedef_nlink_t.h> - -#endif diff --git a/basics/include/time.h b/basics/include/time.h deleted file mode 100644 index 0341a4e70..000000000 --- a/basics/include/time.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __wasm_basics_time_h -#define __wasm_basics_time_h - -#define __need_size_t -#define __need_NULL -#include - -#include <__typedef_time_t.h> -#include <__struct_timespec.h> - -#endif diff --git a/basics/sources/string.c b/basics/sources/string.c deleted file mode 100644 index 77d72019c..000000000 --- a/basics/sources/string.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -static void *copy_forward(void *restrict dst, const void *restrict src, size_t n) { - char *d = (char *)dst; - const char *s = (const char *)src; - while (n-- != 0) { - *d++ = *s++; - } - return dst; -} - -static void *copy_backward(void *restrict dst, const void *restrict src, size_t n) { - char *d = (char *)dst; - const char *s = (const char *)src; - d += n; - s += n; - while (n-- != 0) { - *--d = *--s; - } - return dst; -} - -void *memcpy(void *restrict dst, const void *restrict src, size_t n) { - return copy_forward(dst, src, n); -} - -void *memmove(void *dst, const void *src, size_t n) { - if ((uintptr_t)dst - (uintptr_t)src >= n) { - return copy_forward(dst, src, n); - } - return copy_backward(dst, src, n); -} - -void *memset(void *restrict dst, int c, size_t n) { - char *d = (char *)dst; - while (n-- != 0) { - *d++ = c; - } - return dst; -} diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt index 3962db950..f858b752f 100644 --- a/expected/wasm32-wasi/predefined-macros.txt +++ b/expected/wasm32-wasi/predefined-macros.txt @@ -3021,9 +3021,12 @@ #define __wasi_libc_environ_h #define __wasi_libc_find_relpath_h #define __wasi_libc_h +#define __wasilibc___errno_h #define __wasilibc___errno_values_h #define __wasilibc___fd_set_h #define __wasilibc___function___isatty_h +#define __wasilibc___functions_malloc_h +#define __wasilibc___functions_memcpy_h #define __wasilibc___header_dirent_h #define __wasilibc___header_fcntl_h #define __wasilibc___header_netinet_in_h @@ -3036,7 +3039,9 @@ #define __wasilibc___header_sys_stat_h #define __wasilibc___header_time_h #define __wasilibc___header_unistd_h +#define __wasilibc___include_inttypes_h #define __wasilibc___macro_FD_SETSIZE_h +#define __wasilibc___macro_PAGESIZE_h #define __wasilibc___mode_t_h #define __wasilibc___seek_h #define __wasilibc___struct_dirent_h @@ -3051,42 +3056,37 @@ #define __wasilibc___struct_sockaddr_in_h #define __wasilibc___struct_sockaddr_storage_h #define __wasilibc___struct_sockaddr_un_h +#define __wasilibc___struct_stat_h +#define __wasilibc___struct_timespec_h #define __wasilibc___struct_timeval_h #define __wasilibc___struct_tm_h #define __wasilibc___struct_tms_h #define __wasilibc___typedef_DIR_h +#define __wasilibc___typedef_blkcnt_t_h +#define __wasilibc___typedef_blksize_t_h +#define __wasilibc___typedef_clock_t_h #define __wasilibc___typedef_clockid_t_h +#define __wasilibc___typedef_dev_t_h #define __wasilibc___typedef_fd_set_h +#define __wasilibc___typedef_gid_t_h #define __wasilibc___typedef_in_addr_t_h #define __wasilibc___typedef_in_port_t_h +#define __wasilibc___typedef_ino_t_h +#define __wasilibc___typedef_mode_t_h #define __wasilibc___typedef_nfds_t_h +#define __wasilibc___typedef_nlink_t_h +#define __wasilibc___typedef_off_t_h #define __wasilibc___typedef_sa_family_t_h #define __wasilibc___typedef_sigset_t_h #define __wasilibc___typedef_socklen_t_h +#define __wasilibc___typedef_ssize_t_h +#define __wasilibc___typedef_suseconds_t_h +#define __wasilibc___typedef_time_t_h +#define __wasilibc___typedef_uid_t_h #define __wasm 1 #define __wasm32 1 #define __wasm32__ 1 #define __wasm__ 1 -#define __wasm_basics___errno_h -#define __wasm_basics___functions_malloc_h -#define __wasm_basics___functions_memcpy_h -#define __wasm_basics___include_inttypes_h -#define __wasm_basics___macro_PAGESIZE_h -#define __wasm_basics___struct_stat_h -#define __wasm_basics___struct_timespec_h -#define __wasm_basics___typedef_blkcnt_t_h -#define __wasm_basics___typedef_blksize_t_h -#define __wasm_basics___typedef_clock_t_h -#define __wasm_basics___typedef_dev_t_h -#define __wasm_basics___typedef_gid_t_h -#define __wasm_basics___typedef_ino_t_h -#define __wasm_basics___typedef_mode_t_h -#define __wasm_basics___typedef_nlink_t_h -#define __wasm_basics___typedef_off_t_h -#define __wasm_basics___typedef_ssize_t_h -#define __wasm_basics___typedef_suseconds_t_h -#define __wasm_basics___typedef_time_t_h -#define __wasm_basics___typedef_uid_t_h #define _tolower(a) ((a)|0x20) #define _toupper(a) ((a)&0x5f) #define acos(x) __tg_real_complex(acos, (x)) diff --git a/libc-bottom-half/README.md b/libc-bottom-half/README.md index 383defe90..1e5401cdd 100644 --- a/libc-bottom-half/README.md +++ b/libc-bottom-half/README.md @@ -16,5 +16,4 @@ libc rather than to be a layer on top of libc. [libpreopen]: https://github.com/musec/libpreopen -The WASI libc "bottom half" depends on the basics and dlmalloc components of -wasi-libc. +The WASI libc lower half currently depends on the dlmalloc component. diff --git a/libc-bottom-half/cloudlibc/src/libc/stdlib/qsort.c b/libc-bottom-half/cloudlibc/src/libc/stdlib/qsort.c deleted file mode 100644 index ec21038dc..000000000 --- a/libc-bottom-half/cloudlibc/src/libc/stdlib/qsort.c +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#ifndef qsort -#error "qsort is supposed to be a macro as well" -#endif - -// clang-format off -void (qsort)(void *base, size_t nel, size_t width, - int (*compar)(const void *, const void *)) { - return qsort(base, nel, width, compar); -} diff --git a/basics/include/__errno.h b/libc-bottom-half/headers/public/__errno.h similarity index 75% rename from basics/include/__errno.h rename to libc-bottom-half/headers/public/__errno.h index 5e90f2950..4fd983ad7 100644 --- a/basics/include/__errno.h +++ b/libc-bottom-half/headers/public/__errno.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___errno_h -#define __wasm_basics___errno_h +#ifndef __wasilibc___errno_h +#define __wasilibc___errno_h #ifdef __cplusplus extern "C" { diff --git a/basics/include/__functions_malloc.h b/libc-bottom-half/headers/public/__functions_malloc.h similarity index 87% rename from basics/include/__functions_malloc.h rename to libc-bottom-half/headers/public/__functions_malloc.h index 2b01669ca..d516bc348 100644 --- a/basics/include/__functions_malloc.h +++ b/libc-bottom-half/headers/public/__functions_malloc.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___functions_malloc_h -#define __wasm_basics___functions_malloc_h +#ifndef __wasilibc___functions_malloc_h +#define __wasilibc___functions_malloc_h #define __need_size_t #define __need_wchar_t diff --git a/basics/include/__functions_memcpy.h b/libc-bottom-half/headers/public/__functions_memcpy.h similarity index 85% rename from basics/include/__functions_memcpy.h rename to libc-bottom-half/headers/public/__functions_memcpy.h index ed3df0f40..253b06586 100644 --- a/basics/include/__functions_memcpy.h +++ b/libc-bottom-half/headers/public/__functions_memcpy.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___functions_memcpy_h -#define __wasm_basics___functions_memcpy_h +#ifndef __wasilibc___functions_memcpy_h +#define __wasilibc___functions_memcpy_h #define __need_size_t #define __need_NULL diff --git a/basics/include/__header_inttypes.h b/libc-bottom-half/headers/public/__header_inttypes.h similarity index 98% rename from basics/include/__header_inttypes.h rename to libc-bottom-half/headers/public/__header_inttypes.h index b64e2f28f..47c5c9b63 100644 --- a/basics/include/__header_inttypes.h +++ b/libc-bottom-half/headers/public/__header_inttypes.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___include_inttypes_h -#define __wasm_basics___include_inttypes_h +#ifndef __wasilibc___include_inttypes_h +#define __wasilibc___include_inttypes_h #include diff --git a/basics/include/__macro_PAGESIZE.h b/libc-bottom-half/headers/public/__macro_PAGESIZE.h similarity index 70% rename from basics/include/__macro_PAGESIZE.h rename to libc-bottom-half/headers/public/__macro_PAGESIZE.h index efd7b3aba..0243c98c9 100644 --- a/basics/include/__macro_PAGESIZE.h +++ b/libc-bottom-half/headers/public/__macro_PAGESIZE.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___macro_PAGESIZE_h -#define __wasm_basics___macro_PAGESIZE_h +#ifndef __wasilibc___macro_PAGESIZE_h +#define __wasilibc___macro_PAGESIZE_h /* * The page size in WebAssembly is fixed at 64 KiB. If this ever changes, diff --git a/basics/include/__struct_stat.h b/libc-bottom-half/headers/public/__struct_stat.h similarity index 89% rename from basics/include/__struct_stat.h rename to libc-bottom-half/headers/public/__struct_stat.h index 204387af9..5e345da12 100644 --- a/basics/include/__struct_stat.h +++ b/libc-bottom-half/headers/public/__struct_stat.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___struct_stat_h -#define __wasm_basics___struct_stat_h +#ifndef __wasilibc___struct_stat_h +#define __wasilibc___struct_stat_h #include <__typedef_dev_t.h> #include <__typedef_ino_t.h> diff --git a/basics/include/__struct_timespec.h b/libc-bottom-half/headers/public/__struct_timespec.h similarity index 60% rename from basics/include/__struct_timespec.h rename to libc-bottom-half/headers/public/__struct_timespec.h index 695d89a77..10d83f990 100644 --- a/basics/include/__struct_timespec.h +++ b/libc-bottom-half/headers/public/__struct_timespec.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___struct_timespec_h -#define __wasm_basics___struct_timespec_h +#ifndef __wasilibc___struct_timespec_h +#define __wasilibc___struct_timespec_h #include <__typedef_time_t.h> diff --git a/basics/include/__typedef_blkcnt_t.h b/libc-bottom-half/headers/public/__typedef_blkcnt_t.h similarity index 57% rename from basics/include/__typedef_blkcnt_t.h rename to libc-bottom-half/headers/public/__typedef_blkcnt_t.h index 12807e657..e8d7b3dce 100644 --- a/basics/include/__typedef_blkcnt_t.h +++ b/libc-bottom-half/headers/public/__typedef_blkcnt_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_blkcnt_t_h -#define __wasm_basics___typedef_blkcnt_t_h +#ifndef __wasilibc___typedef_blkcnt_t_h +#define __wasilibc___typedef_blkcnt_t_h /* Define these as 64-bit signed integers to support files larger than 2 GiB. */ typedef long long blkcnt_t; diff --git a/libc-bottom-half/headers/public/__typedef_blksize_t.h b/libc-bottom-half/headers/public/__typedef_blksize_t.h new file mode 100644 index 000000000..8816e0a2e --- /dev/null +++ b/libc-bottom-half/headers/public/__typedef_blksize_t.h @@ -0,0 +1,6 @@ +#ifndef __wasilibc___typedef_blksize_t_h +#define __wasilibc___typedef_blksize_t_h + +typedef long blksize_t; + +#endif diff --git a/basics/include/__typedef_clock_t.h b/libc-bottom-half/headers/public/__typedef_clock_t.h similarity index 55% rename from basics/include/__typedef_clock_t.h rename to libc-bottom-half/headers/public/__typedef_clock_t.h index cb2ce36b9..68cb58849 100644 --- a/basics/include/__typedef_clock_t.h +++ b/libc-bottom-half/headers/public/__typedef_clock_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_clock_t_h -#define __wasm_basics___typedef_clock_t_h +#ifndef __wasilibc___typedef_clock_t_h +#define __wasilibc___typedef_clock_t_h /* Define this as a 64-bit signed integer to avoid wraparounds. */ typedef long long clock_t; diff --git a/basics/include/__typedef_dev_t.h b/libc-bottom-half/headers/public/__typedef_dev_t.h similarity index 58% rename from basics/include/__typedef_dev_t.h rename to libc-bottom-half/headers/public/__typedef_dev_t.h index a1b2f6f42..353e94f55 100644 --- a/basics/include/__typedef_dev_t.h +++ b/libc-bottom-half/headers/public/__typedef_dev_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_dev_t_h -#define __wasm_basics___typedef_dev_t_h +#ifndef __wasilibc___typedef_dev_t_h +#define __wasilibc___typedef_dev_t_h /* Define these as 64-bit integers to support billions of devices. */ typedef unsigned long long dev_t; diff --git a/libc-bottom-half/headers/public/__typedef_gid_t.h b/libc-bottom-half/headers/public/__typedef_gid_t.h new file mode 100644 index 000000000..6eb82f274 --- /dev/null +++ b/libc-bottom-half/headers/public/__typedef_gid_t.h @@ -0,0 +1,6 @@ +#ifndef __wasilibc___typedef_gid_t_h +#define __wasilibc___typedef_gid_t_h + +typedef unsigned gid_t; + +#endif diff --git a/basics/include/__typedef_ino_t.h b/libc-bottom-half/headers/public/__typedef_ino_t.h similarity index 58% rename from basics/include/__typedef_ino_t.h rename to libc-bottom-half/headers/public/__typedef_ino_t.h index 1b3ed4cfb..f3e11e43e 100644 --- a/basics/include/__typedef_ino_t.h +++ b/libc-bottom-half/headers/public/__typedef_ino_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_ino_t_h -#define __wasm_basics___typedef_ino_t_h +#ifndef __wasilibc___typedef_ino_t_h +#define __wasilibc___typedef_ino_t_h /* Define these as 64-bit integers to support billions of inodes. */ typedef unsigned long long ino_t; diff --git a/libc-bottom-half/headers/public/__typedef_mode_t.h b/libc-bottom-half/headers/public/__typedef_mode_t.h new file mode 100644 index 000000000..51b927d9d --- /dev/null +++ b/libc-bottom-half/headers/public/__typedef_mode_t.h @@ -0,0 +1,6 @@ +#ifndef __wasilibc___typedef_mode_t_h +#define __wasilibc___typedef_mode_t_h + +typedef unsigned mode_t; + +#endif diff --git a/basics/include/__typedef_nlink_t.h b/libc-bottom-half/headers/public/__typedef_nlink_t.h similarity index 59% rename from basics/include/__typedef_nlink_t.h rename to libc-bottom-half/headers/public/__typedef_nlink_t.h index b31ac620a..ae34c79f1 100644 --- a/basics/include/__typedef_nlink_t.h +++ b/libc-bottom-half/headers/public/__typedef_nlink_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_nlink_t_h -#define __wasm_basics___typedef_nlink_t_h +#ifndef __wasilibc___typedef_nlink_t_h +#define __wasilibc___typedef_nlink_t_h /* Define these as 64-bit unsigned integers to support billions of links. */ typedef unsigned long long nlink_t; diff --git a/basics/include/__typedef_off_t.h b/libc-bottom-half/headers/public/__typedef_off_t.h similarity index 58% rename from basics/include/__typedef_off_t.h rename to libc-bottom-half/headers/public/__typedef_off_t.h index 49fe7d4a7..115ffdd95 100644 --- a/basics/include/__typedef_off_t.h +++ b/libc-bottom-half/headers/public/__typedef_off_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_off_t_h -#define __wasm_basics___typedef_off_t_h +#ifndef __wasilibc___typedef_off_t_h +#define __wasilibc___typedef_off_t_h /* Define these as 64-bit signed integers to support files larger than 2 GiB. */ typedef long long off_t; diff --git a/basics/include/__typedef_ssize_t.h b/libc-bottom-half/headers/public/__typedef_ssize_t.h similarity index 50% rename from basics/include/__typedef_ssize_t.h rename to libc-bottom-half/headers/public/__typedef_ssize_t.h index c53de9115..25dc15a83 100644 --- a/basics/include/__typedef_ssize_t.h +++ b/libc-bottom-half/headers/public/__typedef_ssize_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_ssize_t_h -#define __wasm_basics___typedef_ssize_t_h +#ifndef __wasilibc___typedef_ssize_t_h +#define __wasilibc___typedef_ssize_t_h /* This is defined to be the same size as size_t. */ typedef long ssize_t; diff --git a/basics/include/__typedef_suseconds_t.h b/libc-bottom-half/headers/public/__typedef_suseconds_t.h similarity index 63% rename from basics/include/__typedef_suseconds_t.h rename to libc-bottom-half/headers/public/__typedef_suseconds_t.h index 0531fbe43..92667e2aa 100644 --- a/basics/include/__typedef_suseconds_t.h +++ b/libc-bottom-half/headers/public/__typedef_suseconds_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_suseconds_t_h -#define __wasm_basics___typedef_suseconds_t_h +#ifndef __wasilibc___typedef_suseconds_t_h +#define __wasilibc___typedef_suseconds_t_h /* Define this to be 64-bit as its main use is in struct timeval where the extra space would otherwise be padding. */ diff --git a/basics/include/__typedef_time_t.h b/libc-bottom-half/headers/public/__typedef_time_t.h similarity index 55% rename from basics/include/__typedef_time_t.h rename to libc-bottom-half/headers/public/__typedef_time_t.h index b6725d224..6ee0f86bf 100644 --- a/basics/include/__typedef_time_t.h +++ b/libc-bottom-half/headers/public/__typedef_time_t.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics___typedef_time_t_h -#define __wasm_basics___typedef_time_t_h +#ifndef __wasilibc___typedef_time_t_h +#define __wasilibc___typedef_time_t_h /* Define this as a 64-bit signed integer to avoid the 2038 bug. */ typedef long long time_t; diff --git a/libc-bottom-half/headers/public/__typedef_uid_t.h b/libc-bottom-half/headers/public/__typedef_uid_t.h new file mode 100644 index 000000000..c9da30036 --- /dev/null +++ b/libc-bottom-half/headers/public/__typedef_uid_t.h @@ -0,0 +1,6 @@ +#ifndef __wasilibc___typedef_uid_t_h +#define __wasilibc___typedef_uid_t_h + +typedef unsigned uid_t; + +#endif diff --git a/basics/include/inttypes.h b/libc-bottom-half/headers/public/inttypes.h similarity index 74% rename from basics/include/inttypes.h rename to libc-bottom-half/headers/public/inttypes.h index 1c8a19d2c..a2378579a 100644 --- a/basics/include/inttypes.h +++ b/libc-bottom-half/headers/public/inttypes.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics_inttypes_h -#define __wasm_basics_inttypes_h +#ifndef __wasilibc_inttypes_h +#define __wasilibc_inttypes_h /* * Include the real implementation, which is factored into a separate file so diff --git a/libc-bottom-half/headers/public/stdlib.h b/libc-bottom-half/headers/public/stdlib.h index 7ff8236e4..8425cb80a 100644 --- a/libc-bottom-half/headers/public/stdlib.h +++ b/libc-bottom-half/headers/public/stdlib.h @@ -5,6 +5,6 @@ * Include the real implementation, which is factored into a separate file so * that it can be reused by other libc stdlib implementations. */ -#include <__header_stdlib.h> +#include <__functions_malloc.h> #endif diff --git a/basics/include/wchar.h b/libc-bottom-half/headers/public/wchar.h similarity index 61% rename from basics/include/wchar.h rename to libc-bottom-half/headers/public/wchar.h index b8220c80f..f43d72fe2 100644 --- a/basics/include/wchar.h +++ b/libc-bottom-half/headers/public/wchar.h @@ -1,5 +1,5 @@ -#ifndef __wasm_basics_wchar_h -#define __wasm_basics_wchar_h +#ifndef __wasilibc_wchar_h +#define __wasilibc_wchar_h #define __need_size_t #define __need_wchar_t diff --git a/basics/sources/abort.c b/libc-bottom-half/sources/abort.c similarity index 100% rename from basics/sources/abort.c rename to libc-bottom-half/sources/abort.c diff --git a/basics/sources/complex-builtins.c b/libc-bottom-half/sources/complex-builtins.c similarity index 100% rename from basics/sources/complex-builtins.c rename to libc-bottom-half/sources/complex-builtins.c diff --git a/libc-bottom-half/sources/errno.c b/libc-bottom-half/sources/errno.c index 32dadd574..4e98a5b84 100644 --- a/libc-bottom-half/sources/errno.c +++ b/libc-bottom-half/sources/errno.c @@ -1,5 +1,4 @@ #include -#include // These values are used by reference-sysroot's dlmalloc. const int __EINVAL = EINVAL; diff --git a/basics/sources/math/fmin-fmax.c b/libc-bottom-half/sources/math/fmin-fmax.c similarity index 100% rename from basics/sources/math/fmin-fmax.c rename to libc-bottom-half/sources/math/fmin-fmax.c diff --git a/basics/sources/math/math-builtins.c b/libc-bottom-half/sources/math/math-builtins.c similarity index 100% rename from basics/sources/math/math-builtins.c rename to libc-bottom-half/sources/math/math-builtins.c diff --git a/basics/sources/reallocarray.c b/libc-bottom-half/sources/reallocarray.c similarity index 100% rename from basics/sources/reallocarray.c rename to libc-bottom-half/sources/reallocarray.c diff --git a/libc-bottom-half/sources/string.c b/libc-bottom-half/sources/string.c deleted file mode 100644 index 205546514..000000000 --- a/libc-bottom-half/sources/string.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include - -size_t strlen(const char *str) { - const char *s = str; - while (*s) { - ++s; - } - return s - str; -} - -char *strdup(const char *str) { - size_t buf_len = strlen(str) + 1; - void *ptr = malloc(buf_len); - if (ptr == NULL) { - return NULL; - } - return memcpy(ptr, str, buf_len); -} - -int strcmp(const char *a, const char *b) { - while (*a != '\0' && (*a == *b)) { - ++a; - ++b; - } - return *(const unsigned char*)a - *(const unsigned char*)b; -} - -void *memchr(const void *ptr, int c, size_t len) { - const unsigned char *p = ptr; - while (len != 0 && *p != (unsigned char)c) { - ++p; - --len; - } - if (len == 0) { - return NULL; - } - return (void *)p; -}