Skip to content

Commit

Permalink
Merge the basics component into libc-bottom-half. (WebAssembly#199)
Browse files Browse the repository at this point in the history
We no longer have a need to maintain basics as a separate component.
Folding it into libc-bottom-half eliminates a fair amount of redundancy.
  • Loading branch information
sunfishcode committed Jun 1, 2020
1 parent 84c0778 commit 753cc43
Show file tree
Hide file tree
Showing 46 changed files with 84 additions and 298 deletions.
35 changes: 2 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)"

Expand Down
23 changes: 0 additions & 23 deletions basics/crt/crt1.c

This file was deleted.

6 changes: 0 additions & 6 deletions basics/include/__typedef_blksize_t.h

This file was deleted.

6 changes: 0 additions & 6 deletions basics/include/__typedef_gid_t.h

This file was deleted.

6 changes: 0 additions & 6 deletions basics/include/__typedef_mode_t.h

This file was deleted.

6 changes: 0 additions & 6 deletions basics/include/__typedef_uid_t.h

This file was deleted.

6 changes: 0 additions & 6 deletions basics/include/errno.h

This file was deleted.

10 changes: 0 additions & 10 deletions basics/include/stdlib.h

This file was deleted.

10 changes: 0 additions & 10 deletions basics/include/string.h

This file was deleted.

10 changes: 0 additions & 10 deletions basics/include/sys/stat.h

This file was deleted.

15 changes: 0 additions & 15 deletions basics/include/sys/types.h

This file was deleted.

11 changes: 0 additions & 11 deletions basics/include/time.h

This file was deleted.

41 changes: 0 additions & 41 deletions basics/sources/string.c

This file was deleted.

40 changes: 20 additions & 20 deletions expected/wasm32-wasi/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions libc-bottom-half/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 0 additions & 15 deletions libc-bottom-half/cloudlibc/src/libc/stdlib/qsort.c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading

0 comments on commit 753cc43

Please sign in to comment.