Skip to content

Commit 107fb7f

Browse files
committed
Modify make sysroot script
Add debug patch.
1 parent e28d437 commit 107fb7f

File tree

2 files changed

+15
-34
lines changed

2 files changed

+15
-34
lines changed

.github/workflows/libcpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
env:
1515
OUTPUT_LOCAL_DIR: libcpp-output
1616
STATUS_FILE: libcpp_status
17-
WASM_FILE_NAME: hello.wasm
17+
WASM_FILE_NAME: hello.cpp.wasm
1818

1919
steps:
2020
- name: Set up Docker Buildx

scripts/make_glibc_and_sysroot.sh

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# - expects `clang` and other llvm binaries on $PATH
88
# - expects GLIBC source in $PWD/src/glibc
99
#
10-
set -x
10+
set -euxo pipefail
1111

1212
CC="clang"
1313
GLIBC="$PWD/src/glibc"
@@ -61,91 +61,80 @@ INCLUDE_PATHS="
6161
-I.
6262
"
6363

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

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

72-
# Check if LIND_DEBUG is defined (set by build.rs when `lind_debug` is enabled)
73-
if [ "$LIND_DEBUG" ]; then
70+
if [ "${LIND_DEBUG:-}" ]; then
7471
DEFINES="$DEFINES -DLIND_DEBUG"
7572
fi
7673

77-
# Build glibc
78-
rm -rf $BUILD
79-
mkdir -p $BUILD
80-
cd $BUILD
74+
rm -rf "$BUILD"
75+
mkdir -p "$BUILD"
76+
cd "$BUILD"
8177

8278
../configure \
8379
--disable-werror \
8480
--disable-hidden-plt \
8581
--disable-profile \
8682
--disable-nscd \
8783
--with-headers=/usr/i686-linux-gnu/include \
88-
--prefix=$GLIBC/target \
84+
--prefix="$GLIBC/target" \
8985
--host=i686-linux-gnu \
9086
--build=i686-linux-gnu \
9187
libc_cv_complocaledir='/usr/lib/locale' \
9288
CFLAGS=" -matomics -mbulk-memory -O2 -g" \
9389
CC="clang --target=wasm32-unknown-wasi -v -Wno-int-conversion"
9490

95-
make -j$(($(nproc) * 2)) --keep-going 2>&1 THREAD_MODEL=posix | tee check.log
91+
make -j1 THREAD_MODEL=posix 2>&1 | tee check.log
92+
93+
[ -f "$BUILD/libc-modules.h" ] || { echo "ERROR: $BUILD/libc-modules.h missing after glibc build"; exit 1; }
9694

97-
# Build extra
9895
cd ../nptl
9996
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
10097
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
10198
-o $BUILD/nptl/pthread_create.o \
10299
-c pthread_create.c -MD -MP -MF $BUILD/nptl/pthread_create.o.dt \
103100
-MT $BUILD/nptl/pthread_create.o
104101

105-
# Compile lind_syscall.c, which contains the make_threei, register_handler,
106-
# and copy_data_between_cages functions
107102
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
108103
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
109104
-o $BUILD/lind_syscall.o \
110105
-c $GLIBC/lind_syscall/lind_syscall.c
111106

112-
# Compile address translation module
113107
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
114108
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
115109
-o $BUILD/addr_translation.o \
116110
-c $GLIBC/lind_syscall/addr_translation.c
117-
118-
# Compile lind debug module
111+
119112
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
120113
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
121114
-o $BUILD/lind_debug.o \
122115
-c $GLIBC/lind_syscall/lind_debug.c
123116

124-
# Compile crt1.c
125117
$CC $CFLAGS $WARNINGS $EXTRA_FLAGS \
126118
$INCLUDE_PATHS $SYS_INCLUDE $DEFINES $EXTRA_DEFINES \
127119
-o $GLIBC/lind_syscall/crt1.o \
128-
-c $GLIBC/lind_syscall/crt1/crt1.c \
129-
|| { echo "ERROR: clang failed compiling crt1.c"; exit 1; }
130-
[ -f "$GLIBC/lind_syscall/crt1.o" ] || { echo "ERROR: $GLIBC/lind_syscall/crt1.o not produced"; exit 1; }
120+
-c $GLIBC/lind_syscall/crt1/crt1.c
121+
122+
[ -f "$GLIBC/lind_syscall/crt1.o" ] || { echo "ERROR: $GLIBC/lind_syscall/crt1.o not produced"; exit 1; }
131123

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

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

148-
# Compile assembly files
149138
cd ../
150139
$CC --target=wasm32-wasi-threads -matomics \
151140
-o $BUILD/csu/wasi_thread_start.o \
@@ -155,19 +144,11 @@ $CC --target=wasm32-wasi-threads -matomics \
155144
-o $BUILD/csu/set_stack_pointer.o \
156145
-c $GLIBC/csu/wasm32/set_stack_pointer.s
157146

158-
# Generate sysroot
159-
# First, remove the existing sysroot directory to start cleanly
160147
rm -rf "$SYSROOT"
161-
162-
163-
# Create the sysroot directory structure
164148
mkdir -p "$SYSROOT/include/wasm32-wasi" "$SYSROOT/lib/wasm32-wasi"
165149

166150
"$SCRIPT_DIR/make_archive.sh"
167151

168-
# Copy all files from the external include directory to the new sysroot include directory
169152
cp -r "$GLIBC/target/include/"* "$SYSROOT/include/wasm32-wasi/"
170-
171-
# Copy the crt1.o file into the new sysroot lib directory
172153
cp "$GLIBC/lind_syscall/crt1.o" "$SYSROOT/lib/wasm32-wasi/"
173-
cp "$GLIBC/lind_syscall/lind_syscall.h" "$SYSROOT/include/wasm32-wasi/"
154+
cp "$GLIBC/lind_syscall/lind_syscall.h" "$SYSROOT/include/wasm32-wasi/"

0 commit comments

Comments
 (0)