Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/
#Ignore both files and folders beginning with clang+llvm
clang+llvm-*/
clang+llvm-*

#Ignore WebAssembly artifacts
*.wasm
*.cwasm

#Ignore Build artifacts
src/glibc/build/
src/RawPOSIX/tmp/
10 changes: 7 additions & 3 deletions Docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ FROM ubuntu:22.04
# --- Build arguments ---
ARG USERNAME=lind
ARG BRANCH_NAME=main
ARG LLVM_VERSION="llvmorg-16.0.4"
ARG CLANG_PACKAGE="clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04"
ARG LLVM_VERSION="llvmorg-18.1.8"
ARG CLANG_PACKAGE="clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04"

# --- System setup ---
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -54,6 +54,10 @@ RUN groupadd --gid 1000 ${USERNAME} && \
useradd --uid 1000 --gid ${USERNAME} --create-home --shell /bin/bash ${USERNAME} && \
echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# --- Install libtinfo5 as root ---
RUN wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && \
apt install ./libtinfo5_6.3-2ubuntu0.1_amd64.deb

# --- Switch to user ASAP ---
USER ${USERNAME}
WORKDIR /home/${USERNAME}
Expand All @@ -78,7 +82,7 @@ RUN curl -sL https://github.com/llvm/llvm-project/releases/download/${LLVM_VERSI

# --- Patch glibc wasi includes into clang dir and fix permissions ---
RUN cp -r /home/${USERNAME}/lind-wasm/src/glibc/wasi \
/home/${USERNAME}/lind-wasm/${CLANG_PACKAGE}/lib/clang/16/lib && \
/home/${USERNAME}/lind-wasm/${CLANG_PACKAGE}/lib/clang/18/lib && \
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/

# --- Back to user for everything else ---
Expand Down
25 changes: 19 additions & 6 deletions Docker/Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,30 @@ RUN apt-get update && \
make \
python3 \
sed \
wget \
&& rm -rf /var/lib/apt/lists/*

# Install clang
ARG LLVM="llvmorg-16.0.4"
ARG CLANG="clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04"
# NOTE: We `curl | tar` in spite of Docker best practices to save cache layers
RUN curl -sL https://github.com/llvm/llvm-project/releases/download/${LLVM}/${CLANG}.tar.xz | \
tar -xvJ
COPY src/glibc/wasi /${CLANG}/lib/clang/16/lib/wasi
ARG LLVM="llvmorg-18.1.8"
ARG CLANG="clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04"

# Add retries and robust protection to curl to prevent transient network issues
# from causing Docker build failures.
SHELL ["/bin/bash","-o","pipefail","-c"]

RUN set -euo pipefail; \
url="https://github.com/llvm/llvm-project/releases/download/${LLVM}/${CLANG}.tar.xz"; \
echo "Fetching $url"; \
curl -fL --retry 5 --retry-delay 3 "$url" | tar -xJ

COPY src/glibc/wasi /${CLANG}/lib/clang/18/lib/wasi
ENV PATH="/${CLANG}/bin:${PATH}"

# --- Install libtinfo5 ---
RUN wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && \
apt install ./libtinfo5_6.3-2ubuntu0.1_amd64.deb


# Install rust
# NOTE: pinning known-to-work nightly-2025-06-01 (see #242)
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
Expand Down
45 changes: 40 additions & 5 deletions scripts/make_glibc_and_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SYSROOT="$GLIBC/sysroot"
SYSROOT_ARCHIVE="$SYSROOT/lib/wasm32-wasi/libc.a"

# Define common flags
CFLAGS="--target=wasm32-unknown-wasi -v -Wno-int-conversion -std=gnu11 -fgnu89-inline -matomics -mbulk-memory -O2 -g"
CFLAGS="--target=wasm32-unknown-wasi -v -Wno-int-conversion -std=gnu11 -fgnu89-inline -matomics -mbulk-memory -O2 -g -fPIC"
WARNINGS="-Wall -Wwrite-strings -Wundef -Wstrict-prototypes -Wold-style-definition"
EXTRA_FLAGS="-fmerge-all-constants -ftrapping-math -fno-stack-protector -fno-common"
EXTRA_FLAGS+=" -Wp,-U_FORTIFY_SOURCE -fmath-errno -fPIE -ftls-model=local-exec"
Expand Down Expand Up @@ -59,7 +59,12 @@ INCLUDE_PATHS="
-I../libio
-I.
"
SYS_INCLUDE="-nostdinc -isystem $CLANG/lib/clang/16/include -isystem /usr/i686-linux-gnu/include"


RESOURCE_DIR="$(clang --target=wasm32-unknown-wasi -print-resource-dir)"
SYS_INCLUDE="-nostdinc -isystem ${RESOURCE_DIR}/include -isystem /usr/i686-linux-gnu/include"

#SYS_INCLUDE="-nostdinc -isystem $CLANG/lib/clang/18/include -isystem /usr/i686-linux-gnu/include"
DEFINES="-D_LIBC_REENTRANT -include $BUILD/libc-modules.h -DMODULE_NAME=libc"
EXTRA_DEFINES="-include ../include/libc-symbols.h -DPIC -DTOP_NAMESPACE=glibc"

Expand Down Expand Up @@ -95,6 +100,22 @@ $CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
-o $BUILD/lind_syscall.o \
-c $GLIBC/lind_syscall/lind_syscall.c

# Compile elision-lock.c
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
-o $GLIBC/build/nptl/elision-lock.o \
-c $GLIBC/sysdeps/unix/sysv/linux/x86/elision-lock.c \
-MD -MP -MF $GLIBC/build/nptl/elision-lock.o.dt \
-MT $GLIBC/build/nptl/elision-lock.o

# Compile elision-unlock.c
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
-o $GLIBC/build/nptl/elision-unlock.o \
-c $GLIBC/sysdeps/unix/sysv/linux/x86/elision-unlock.c \
-MD -MP -MF $GLIBC/build/nptl/elision-unlock.o.dt \
-MT $GLIBC/build/nptl/elision-unlock.o

# Compile assembly files
cd ../
$CC --target=wasm32-wasi-threads -matomics \
Expand All @@ -110,19 +131,33 @@ $CC --target=wasm32-wasi-threads -matomics \
rm -rf "$SYSROOT"

# Find all .o files recursively in the source directory, ignoring stamp.o
object_files=$(find "$BUILD" -type f -name "*.o" ! \( -name "stamp.o" -o -name "argp-pvh.o" -o -name "repertoire.o" -o -name "static-stubs.o" \))
object_files=$(find "$BUILD" -type f -name '*.o' \
! -name 'stamp.o' \
! -name 'argp-pvh.o' \
! -name 'repertoire.o' \
! -name 'static-stubs.o'\
! -name 'zic.o' \
! -name 'ldconfig.o' \
! -name 'sln.o')

# Check if object files were found
if [ -z "$object_files" ]; then
echo "No suitable .o files found in '$BUILD'."
exit 1
fi


# Create the sysroot directory structure
mkdir -p "$SYSROOT/include/wasm32-wasi" "$SYSROOT/lib/wasm32-wasi"

# Pack all found .o files into a single .a archive
llvm-ar rcs "$SYSROOT_ARCHIVE" $object_files
# Pack all found .o files into a single .a archive, filtering for no-mains.
filtered_objects=$(
for o in $object_files; do
llvm-nm --defined-only -g "$o" 2>/dev/null | grep -qE '\bT[[:space:]]+main$' || printf '%s ' "$o"
done
)
llvm-ar rcs "$SYSROOT_ARCHIVE" $filtered_objects

llvm-ar crs "$GLIBC/sysroot/lib/wasm32-wasi/libpthread.a"

# Check if llvm-ar succeeded
Expand Down