Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musl libc compatibility #241

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .prebuilt_tools_shasums
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ad8c0e3357579ae8b9c6f8adb76aae5ac9155134304e11e429b81111283a4718 riscv-toolchai
ed41a452ba736d40de73b847777ad9cedd54e528f5d8930c44a6eb937e4d36d9 riscv-toolchain-lp64d-rv64gc-2021.01.xenial.7z
7e232c2030cc8ab8dab169a4e9dac1cc75c41ea1da8cbe1a70ba416a6d6b971f riscv-toolchain-ilp32d-rv32gc-2021.01.bionic.7z
2c37fa700f5ecf7ab8c1e5aeddd018fc15e0c187721b769a1d1318ed58228685 riscv-toolchain-lp64d-rv64gc-2021.01.bionic.7z
135c42498f685fffad5fc86a9b4d9258763710ca34eb190aae8999a4335678dd riscv-musl-toolchain-lp64d-rv64gc-2021.04.xenial.7z
6 changes: 6 additions & 0 deletions docs/source/Keystone-Applications/Compiling-Applications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Toolchain

All compilation will need to be done using the riscv64- toolchain.

For libc-based applications, the hello CMakeLists.txt in sdk/examples/hello has a workaround for using
musl libc instead of GNU libc because of the requirement of thread-local storage in GNU libc. Keystone
currently does not support this functionality, but it will in a later release.

GitHub Issue Reference: https://github.com/keystone-enclave/keystone/issues/229

Libraries
---------

Expand Down
39 changes: 38 additions & 1 deletion fast-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fi

if [ "$BITS" = "64" ]; then
TOOLCHAIN_7Z_FILE=riscv-toolchain-lp64d-rv64gc-2021.01.$DIST.7z
TOOLCHAIN_MUSL_7Z_FILE=riscv-musl-toolchain-lp64d-rv64gc-2021.04.xenial.7z
else
TOOLCHAIN_7Z_FILE=riscv-toolchain-ilp32d-rv32gc-2021.01.$DIST.7z
SDK_FLAGS="-DRISCV32=y"
Expand Down Expand Up @@ -56,6 +57,39 @@ else
rm $TOOLCHAIN_7Z_FILE
fi

if ( $(command -v riscv$BITS-unknown-linux-musl-gcc > /dev/null) )
then
echo "RISCV MUSL tools are already installed"
else
echo "Downloading Prebuilt RISC-V MUSL Toolchain... "

export RISCV_MUSL=$(pwd)/riscv$BITS-musl
export PATH=$PATH:$RISCV_MUSL/bin

if [ -f $TOOLCHAIN_MUSL_7Z_FILE ]; then
rm $TOOLCHAIN_MUSL_7Z_FILE;
fi

wget https://keystone-enclave.eecs.berkeley.edu/files/$TOOLCHAIN_MUSL_7Z_FILE

# Check tool integrity
echo "Verifying prebuilt toolchain integrity..."

sha256sum -c .prebuilt_tools_shasums --status --ignore-missing

if [[ $? != 0 ]]; then
echo "Toolchain binary download incomplete or corrupted. You can build the toolchain locally or try again."
exit 1
fi

echo "Extracting Toolchain"
7za x -y $TOOLCHAIN_MUSL_7Z_FILE -o./riscv$BITS-musl

echo "Toolchain has been installed in $RISCV_MUSL"

rm $TOOLCHAIN_MUSL_7Z_FILE
fi

echo "Updating and cloning submodules, this may take a long time"
git config submodule.riscv-gnu-toolchain.update none

Expand Down Expand Up @@ -89,9 +123,12 @@ fi

# update source.sh
GCC_PATH=$(which riscv$BITS-unknown-linux-gnu-gcc)
GCC_MUSL_PATH=$(which riscv$BITS-unknown-linux-musl-gcc)
RISCV_DIR=$(dirname $(dirname $GCC_PATH))
RISCV_MUSL_DIR=$(dirname $(dirname $GCC_MUSL_PATH))
echo "export RISCV=$RISCV_DIR" > ./source.sh
echo "export PATH=$RISCV/bin:\$PATH" >> ./source.sh
echo "export RISCV_MUSL=$RISCV_MUSL_DIR" >> ./source.sh
echo "export PATH=$RISCV/bin:$RISCV_MUSL/bin:\$PATH" >> ./source.sh
echo "export KEYSTONE_SDK_DIR=$KEYSTONE_SDK_DIR" >> ./source.sh

echo "RISC-V toolchain and Keystone SDK have been fully setup"
Expand Down