-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MUSL: Adding a new lightweight math library to Snitch (#25)
* musl: add library as new submodule with README * musl: add musl library to toolchain * ci: add musl build --------- Co-authored-by: Viviane Potocnik <[email protected]>
- Loading branch information
Showing
7 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
[submodule "sw/deps/printf"] | ||
path = sw/deps/printf | ||
url = https://github.com/mpaland/printf.git | ||
[submodule "sw/deps/musl"] | ||
path = sw/deps/musl | ||
url = [email protected]:kraj/musl.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# musl Guide | ||
|
||
In this guide, we show you how to set up `Snitch` with the `musl` library. | ||
|
||
## Prerequisites | ||
Make sure that you update this `musl` submodule to the latest version. | ||
``` | ||
git submodule update --init --recursive | ||
``` | ||
Afterward, we need to set the correct compiler so that `Snitch` can compile the `musl` library. | ||
``` | ||
export CC=clang | ||
``` | ||
Where `clang` is the compiler that you want to use. At IIS, please use `/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin/riscv32-unknown-elf-clang`. | ||
Next, we create the installation directory and configure the build and installation process. | ||
``` | ||
mkdir install | ||
cd musl | ||
./configure --disable-shared --prefix=../install/ --with-boost-libdir=<path_to_boost_dir> --enable-wrapper=all CFLAGS="-mcpu=snitch -menable-experimental-extensions" | ||
``` | ||
Where `<path_to_boost_dir>` is the path to the `boost` library. At IIS, if you are using Alma Linux you might have to install the `boost-devel` package. | ||
You can do this by retrieviing the `rpm` package and updating your `LD_LIBRARY_PATH` variable. | ||
``` | ||
wget https://repo.almalinux.org/almalinux/8/AppStream/aarch64/os/Packages/boost-regex-1.66.0-13.el8.aarch64.rpm | ||
rpm2cpio boost-regex-1.66.0-13.el8.aarch64.rpm | cpio -idmv | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib64 | ||
``` | ||
Afterward, we can build and install the `musl` library. | ||
``` | ||
make -j$(nproc) | ||
make install | ||
``` | ||
You might have to change the permissions of the `./tools/install.sh` script. This can be done by running `chmod +x ./tools/install.sh`. | ||
Finally, we need to set the `LD_LIBRARY_PATH` variable so that `Snitch` can find the `musl` library. | ||
``` | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<home>/snitch_cluster/sw/deps/install/lib | ||
``` | ||
where `<home>` is the path to the location where you cloned the `snitch_cluster` repository. | ||
|
||
**Important** : Whenever you change the source code of the `musl` library, you need to recompile it. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Luca Colagrande <[email protected]> | ||
# Viviane Potocnik <[email protected]> | ||
|
||
###################### | ||
# Invocation options # | ||
|
@@ -14,6 +15,10 @@ DEBUG ?= OFF # ON to turn on debugging symbols | |
# Build variables # | ||
################### | ||
|
||
# Directory to the MUSL installation | ||
MUSL_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
SW_INSTALL_DIR ?= $(abspath $(MUSL_DIR)/../../../sw/deps/install/) | ||
|
||
# Compiler toolchain | ||
LLVM_BINROOT ?= $(dir $(shell which riscv32-unknown-elf-clang)) | ||
RISCV_CC ?= $(LLVM_BINROOT)/clang | ||
|
@@ -25,6 +30,11 @@ RISCV_DWARFDUMP ?= $(LLVM_BINROOT)/llvm-dwarfdump | |
|
||
# Compiler flags | ||
RISCV_CFLAGS += $(addprefix -I,$(INCDIRS)) | ||
|
||
# musl specific flags | ||
RISCV_CFLAGS += -I$(SW_INSTALL_DIR)/include | ||
RISCV_CFLAGS += -B$(SW_INSTALL_DIR)/bin | ||
|
||
RISCV_CFLAGS += -mcpu=snitch | ||
RISCV_CFLAGS += -menable-experimental-extensions | ||
RISCV_CFLAGS += -mabi=ilp32d | ||
|
@@ -33,6 +43,13 @@ RISCV_CFLAGS += -ffast-math | |
RISCV_CFLAGS += -fno-builtin-printf | ||
RISCV_CFLAGS += -fno-common | ||
RISCV_CFLAGS += -fopenmp | ||
|
||
# TODO: check why the LTO flags optimizes the CBSS section away | ||
# RISCV_CFLAGS += -flto=thin | ||
|
||
RISCV_CFLAGS += -ftls-model=local-exec | ||
RISCV_CFLAGS += -nostdinc | ||
|
||
RISCV_CFLAGS += -O3 | ||
ifeq ($(DEBUG), ON) | ||
RISCV_CFLAGS += -g | ||
|
@@ -42,6 +59,10 @@ endif | |
RISCV_LDFLAGS += -fuse-ld=$(RISCV_LD) | ||
RISCV_LDFLAGS += -nostartfiles | ||
RISCV_LDFLAGS += -lm | ||
# musl specific flags | ||
RISCV_LDFLAGS += -L$(SW_INSTALL_DIR)/lib | ||
RISCV_LDFLAGS += -nostdinc | ||
# RISCV_LDFLAGS += -flto=thin | ||
|
||
# Archiver flags | ||
RISCV_ARFLAGS = rcs |