Skip to content
Open
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 .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ run/
bin
cpu2006_build/
Makefile.spec

.cache/
*/logs/*
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ make ARCH=riscv64 \
build-all -j 29
```

# Use Nix to build
this repo can be built with nix, you do not need to warry about the dependencies.

```shell
// install nix
sh <(curl -L https://nixos.org/nix/install) --no-daemon

// prepare spec source
export SPEC=/spec2006_path
pushd $SPEC && source shrc && popd
make copy-all-src

// enter nix shell
nix-shell

// build
make build-all -j 29
```
shell.nix is prepared to build with jemalloc, if you do not want to use jemalloc,
you can use shell_no_jemalloc.nix

```shell
nix-shell shell_no_jemalloc.nix
// build
make build-all -j 29
```

# Note for GCC >= 14

The old version of xerces-c in 483.xalancbmk [contains a bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111544) that will cause compile errors in GCC 14 and later. You may need to apply the following patch to SPEC CPU 2006 source code to get this fixed:
Expand Down
90 changes: 90 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
let
nixpkgs = fetchTarball {
url = "https://github.com/NixOS/nixpkgs/tarball/release-23.11";
sha256 = "sha256:1f5d2g1p6nfwycpmrnnmc2xmcszp804adp16knjvdkj8nz36y1fg";
};
pkgs = import nixpkgs {};
riscv64Pkgs = pkgs.pkgsCross.riscv64;

# Custom jemalloc with static libraries
customJemalloc = riscv64Pkgs.jemalloc.overrideAttrs (oldAttrs: {
configureFlags = (oldAttrs.configureFlags or []) ++ [
"--enable-static"
"--disable-shared"
];
preBuild = ''
# Add weak attribute to C++ operators, 作用和jemalloc_cpp.patch效果一样
sed -i 's/void \*operator new(size_t)/void *operator new(size_t) __attribute__((weak))/g' src/jemalloc_cpp.cpp
sed -i 's/void operator delete(void \*)/void operator delete(void *) __attribute__((weak))/g' src/jemalloc_cpp.cpp
'';
# Ensure static libraries are installed
postInstall = ''
${oldAttrs.postInstall or ""}
cp -v lib/libjemalloc.a $out/lib/
'';
});
riscv64Fortran = riscv64Pkgs.wrapCCWith {
cc = riscv64Pkgs.stdenv.cc.cc.override {
name = "gfortran";
langFortran = true;
langCC = false;
langC = false;
profiledCompiler = false;
};
# fixup wrapped prefix, which only appear if hostPlatform!=targetPlatform
# for more details see <nixpkgs>/pkgs/build-support/cc-wrapper/default.nix
stdenvNoCC = riscv64Pkgs.stdenvNoCC.override {
hostPlatform = pkgs.stdenv.hostPlatform;
};
};
patchSPEC = let
rpath = pkgs.lib.makeLibraryPath [
pkgs.libxcrypt-legacy
];
in pkgs.writeScriptBin "patchSPEC" ''
echo patching ''${SPEC:?env SPEC is not specified, fixupELFs aborted!}/bin

for file in $(find $SPEC/bin -type f \( -perm /0111 -o -name \*.so\* \) ); do
patchelf --set-interpreter "$(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker)" "$file" || true
patchelf --set-rpath ${rpath} $file || true
done

echo patchSPEC: done!
'';
in

pkgs.mkShell {
nativeBuildInputs = with pkgs; [
pkg-config
file
riscv64Pkgs.buildPackages.gcc
riscv64Pkgs.buildPackages.binutils
riscv64Fortran
patchSPEC
];

buildInputs = with riscv64Pkgs; [
glibc
glibc.static
customJemalloc
];

shellHook = ''
echo "Cross-compilation environment for RISC-V 64-bit (GNU) Linux with jemalloc ready"
echo "Use 'qemu-riscv64' to run the compiled program"

export SPEC_LITE=$PWD
export ARCH=riscv64
export CROSS_COMPILE=riscv64-unknown-linux-gnu-
export OPTIMIZE="-O3 -flto"
export SUBPROCESS_NUM=5

export CC=${riscv64Pkgs.stdenv.cc}/bin/riscv64-unknown-linux-gnu-gcc
export CXX=${riscv64Pkgs.stdenv.cc}/bin/riscv64-unknown-linux-gnu-g++
export LD=${riscv64Pkgs.stdenv.cc}/bin/riscv64-unknown-linux-gnu-ld

export CFLAGS="$CFLAGS -static -Wno-format-security -I${customJemalloc}/include "
export CXXFLAGS="$CXXFLAGS -static -Wno-format-security -I${customJemalloc}/include"
export LDFLAGS="$LDFLAGS -static -ljemalloc -L${customJemalloc}/lib"
'';
}
41 changes: 41 additions & 0 deletions shell_no_jemalloc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
let
nixpkgs = fetchTarball {
url = "https://github.com/NixOS/nixpkgs/tarball/release-23.11";
sha256 = "sha256:1f5d2g1p6nfwycpmrnnmc2xmcszp804adp16knjvdkj8nz36y1fg";
};
pkgs = import nixpkgs {};
riscv64Pkgs = pkgs.pkgsCross.riscv64;
in

pkgs.mkShell {
nativeBuildInputs = with pkgs; [
pkg-config
file
riscv64Pkgs.buildPackages.gcc
riscv64Pkgs.buildPackages.binutils
];

buildInputs = with riscv64Pkgs; [
glibc
glibc.static
];

shellHook = ''
echo "Cross-compilation environment for RISC-V 64-bit (GNU) Linux ready"
echo "Use 'qemu-riscv64' to run the compiled program"

export SPEC_LITE=$PWD
export ARCH=riscv64
export CROSS_COMPILE=riscv64-unknown-linux-gnu-
export OPTIMIZE="-O3 -flto"
export SUBPROCESS_NUM=5

export CC=${riscv64Pkgs.stdenv.cc}/bin/riscv64-unknown-linux-gnu-gcc
export CXX=${riscv64Pkgs.stdenv.cc}/bin/riscv64-unknown-linux-gnu-g++
export LD=${riscv64Pkgs.stdenv.cc}/bin/riscv64-unknown-linux-gnu-ld

export CFLAGS="$CFLAGS -static -Wno-format-security"
export CXXFLAGS="$CXXFLAGS -static -Wno-format-security"
export LDFLAGS="$LDFLAGS -static"
'';
}