Skip to content

Commit 90cf7f6

Browse files
authored
Latest wasi-libc (#109)
* gh: bump code version * llvm: bump wasi-libc to latest commit * wasi-libc: rebase to latest commit cross-compiling all functions * makefile: update toolchain file to use ldflags w/out quotes in clapack * cmake: add linker flags in wasi toolchain * faasmtools: set the compilationflags and linking flags required to use wasi with emulation * func: set wasi emulated libs in toolchain * zlib: only build static library * clapack and zlib: fix compilation with new wasi-libc * docker: tag llvm image with cpp tag as well * libc: changes to cross-compile cpython * wasi-libc: more changes * wasi-libc: more updates * libc: more changes * wasi-libc: emulated mman * libfake: fix task * func: fix calloc function by passing the right flags to mmap (as required by wasi-libc's calloc implementation * dynlink: temporarily disable one failing check * func: remove PROT_EXEC flag from mmap as it is not supported in wasi-libc * clang-format * wasi-libc: add --purge flag to clean the sysroot and apply patches * wasi-libc: fix patch * docker: make sure to re-install llvm headers after purge * py: make linter happy * wasi-libc: more cleanup * wasi-libc: remove patch-oritented style * cleanup * wasi-libc: prepare for merge * nits: self-review * dynlink: undo patch
1 parent 7198459 commit 90cf7f6

File tree

20 files changed

+81
-25
lines changed

20 files changed

+81
-25
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SYSROOT_VERSION=0.2.1
2-
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:0.2.1
1+
SYSROOT_VERSION=0.2.2
2+
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:0.2.2
33
COMPOSE_PROJECT_NAME=cpp-dev

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
if: github.event.pull_request.draft == false
2020
runs-on: ubuntu-latest
2121
container:
22-
image: faasm/cpp-sysroot:0.2.1
22+
image: faasm/cpp-sysroot:0.2.2
2323
steps:
2424
# --- Update code ---
2525
- name: "Checkout code"

LLVM.makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ default: build
2929
clean-libc:
3030
rm -rf $(BUILD_DIR)/libc.BUILT $(WASI_LIBC_DIR)/build
3131

32+
.PHONY: very-clean-libc
33+
very-clean-libc:
34+
# WARNING: this is going to remove _everything_ in FAASM_SYSROOT
35+
cd $(WASI_LIBC_DIR) && SYSROOT=$(FAASM_SYSROOT) make clean
36+
3237
.PHONY: clean-libs
3338
clean-libs: clean-libc
3439
rm -rf $(BUILD_DIR)/compiler-rt $(BUILD_DIR)/compiler-rt.BUILT
@@ -72,9 +77,9 @@ $(BUILD_DIR)/libc.BUILT: $(BUILD_DIR)/llvm.BUILT
7277
mkdir -p $(WASI_LIBC_DIR)/build
7378
cd $(WASI_LIBC_DIR); $(MAKE) \
7479
THREAD_MODEL=faasm \
75-
WASM_CC=$(PREFIX)/bin/clang \
76-
WASM_AR=$(PREFIX)/bin/llvm-ar \
77-
WASM_NM=$(PREFIX)/bin/llvm-nm \
80+
CC=$(PREFIX)/bin/clang \
81+
AR=$(PREFIX)/bin/llvm-ar \
82+
NM=$(PREFIX)/bin/llvm-nm \
7883
SYSROOT=$(FAASM_SYSROOT)
7984
touch $(BUILD_DIR)/libc.BUILT
8085

Makefile.envs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export WASM_RANLIB=${FAASM_WASM_RANLIB}
1616
export WASM_LD=${FAASM_WASM_CC}
1717
export WASM_LDSHARED=${FAASM_WASM_CC}
1818
export WASM_LDFLAGS="${FAASM_WASM_STATIC_LINKER_FLAGS}"
19+
export WASM_LDFLAGS_NO_QUOTES=${FAASM_WASM_STATIC_LINKER_FLAGS}
1920
export WASM_EXE_LDFLAGS="${FAASM_WASM_EXE_LINKER_FLAGS}"
2021
export WASM_EXE_LDFLAGS_NO_QUOTES=${FAASM_WASM_EXE_LINKER_FLAGS}
2122

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.1
1+
0.2.2

WasiToolchain.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ endif()
5858
set(CMAKE_SYSROOT ${FAASM_SYSROOT} CACHE STRING "faasm build")
5959
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FAASM_COMPILER_FLAGS}" CACHE STRING "faasm build")
6060
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FAASM_COMPILER_FLAGS}" CACHE STRING "faasm build")
61+
set(CMAKE_LINKER_FLAGS $ENV{FAASM_WASM_LINKER_FLAGS} CACHE STRING "faasm build")
6162
set(CMAKE_SHARED_LINKER_FLAGS $ENV{FAASM_WASM_SHARED_LINKER_FLAGS} CACHE STRING "faasm build")
6263
set(CMAKE_EXE_LINKER_FLAGS $ENV{FAASM_WASM_EXE_LINKER_FLAGS} CACHE STRING "faasm build")
6364

docker/cpp-sysroot.dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM faasm/llvm:13.0.1 as llvm
1+
# llvm image is not re-built often, so the tag may be behind
2+
FROM faasm/llvm:0.2.2 as llvm
23

34
# faabric-base image is not re-built often, so tag may be behind
45
FROM faasm/faabric-base:0.4.1
@@ -44,8 +45,9 @@ RUN cd /code/cpp \
4445
libfaasmpi --native --shared \
4546
# Install toolchain files
4647
&& inv install \
47-
# First build libc
48-
&& inv llvm.libc \
48+
# Build wasi-libc and reset the sysroot. The second call to LLVM just
49+
# installs some headers that are purged
50+
&& inv llvm.libc --purge llvm \
4951
# Build Faasm WASM libraries
5052
&& inv \
5153
libemscripten \

faasmtools/build.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@
8181
"-D__faasm",
8282
]
8383

84+
# Wasi-libc specific flags that are needed to include certain emulation headers
85+
WASM_WASI_LIBC_CFLAGS = [
86+
"-D_WASI_EMULATED_GETPID",
87+
"-D_WASI_EMULATED_PROCESS_CLOCKS",
88+
"-D_WASI_EMULATED_SIGNAL",
89+
]
90+
91+
WASM_CFLAGS += WASM_WASI_LIBC_CFLAGS
92+
8493
WASM_CXXFLAGS = WASM_CFLAGS
8594

8695
# Flags for shared libraries
@@ -112,6 +121,17 @@
112121
"-Xlinker --no-check-features",
113122
]
114123

124+
# Wasi-libc specific libraries we need to link with to enable certain emulated
125+
# functionalities
126+
WASM_WASI_LIBC_LDFLAGS = [
127+
"-lc-printscan-long-double",
128+
"-lwasi-emulated-getpid",
129+
"-lwasi-emulated-process-clocks",
130+
"-lwasi-emulated-signal",
131+
]
132+
133+
WASM_LDFLAGS += WASM_WASI_LIBC_LDFLAGS
134+
115135
# Flags for executables
116136
WASM_EXE_LDFLAGS = [
117137
"-Xlinker --stack-first",
@@ -125,6 +145,8 @@
125145
"-Wl,--initial-memory={}".format(FAASM_WASM_INITIAL_MEMORY_SIZE),
126146
]
127147

148+
WASM_EXE_LDFLAGS += WASM_WASI_LIBC_LDFLAGS
149+
128150
# These are the compiler and linker flags required for functions that will also
129151
# do dynamic linking. We need to export all symbols to make them available to
130152
# the dynamically loaded modules
@@ -133,6 +155,8 @@
133155
"-Xlinker --no-gc-sections",
134156
]
135157

158+
WASM_EXE_LDFLAGS_SHARED += WASM_WASI_LIBC_LDFLAGS
159+
136160
# Flags for shared libraries
137161
# See notes in README about WebAssembly and shared libraries
138162
WASM_LDFLAGS_SHARED = [

func/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
2525
# Wasm build
2626
# ----------------------
2727

28-
set(FAASM_FUNC_LIBS faasm c-printscan-long-double)
28+
set(FAASM_FUNC_LIBS faasm)
2929

3030
function(faasm_func_c func_name file_name)
3131
add_executable(${func_name} ${file_name})

func/demo/calloc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ int main(int argc, char* argv[])
2626
strcpy(callocPtr, s.c_str());
2727

2828
// Add in a call to mmap to deliberately fragment things
29-
char* mmapPtr =
30-
(char*)mmap(nullptr, mmapLen, PROT_WRITE, MAP_ANONYMOUS, -1, 0);
29+
char* mmapPtr = (char*)mmap(
30+
nullptr, mmapLen, PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
31+
if (mmapPtr == MAP_FAILED) {
32+
printf("ERROR - mmap failed: %s\n", strerror(errno));
33+
}
3134
strcpy(mmapPtr, "mmapSpace");
3235

3336
callocPtrs[i] = callocPtr;

0 commit comments

Comments
 (0)