Skip to content

Commit

Permalink
Supported x86_64 musl
Browse files Browse the repository at this point in the history
  • Loading branch information
elliott10 committed Jan 2, 2024
1 parent e8d502c commit ff418c6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
30 changes: 18 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
NPROC = 16
MUSL_PREFIX = riscv64-linux
NPROC ?= 8
ARCH ?= x86_64
MUSL_PREFIX ?= $(ARCH)-linux-musl
MUSL_GCC = $(MUSL_PREFIX)-gcc
MUSL_STRIP = $(MUSL_PREFIX)-strip

# CC="musl-gcc -static" ./configure --prefix=$HOME/musl
# ./configure --host=x86_64-linux-musl --with-sysroot=/path/to/sysroot
# make TARGET=x86_64-linux-musl install

build_all: busybox lua lmbench libctest iozone libc-bench netperf iperf unix-bench cyclictest time-test test_all true copy-file-range-test interrupts-test

busybox: .PHONY
Expand All @@ -19,15 +24,15 @@ lua: .PHONY
cp scripts/lua/* sdcard/

lmbench: .PHONY
make -C lmbench build CC="riscv64-linux-gnu-gcc -static" OS=riscv64 -j $(NPROC)
riscv64-linux-gnu-strip lmbench/bin/riscv64/lmbench_all
make -C lmbench build CC="$(ARCH)-linux-gnu-gcc -static" OS=$(ARCH) -j $(NPROC)
$(ARCH)-linux-gnu-strip lmbench/bin/$(ARCH)/lmbench_all
# riscv64-linux-gnu-strip lmbench/bin/riscv64/hello
cp lmbench/bin/riscv64/lmbench_all sdcard/
cp lmbench/bin/riscv64/hello sdcard/
cp lmbench/bin/$(ARCH)/lmbench_all sdcard/
cp lmbench/bin/$(ARCH)/hello sdcard/
cp scripts/lmbench/* sdcard/

libctest: .PHONY
make -C libc-test disk -j $(NPROC)
make -C libc-test PREFIX=$(MUSL_PREFIX) disk -j $(NPROC)
cp libc-test/disk/* sdcard/
mv sdcard/run-all.sh sdcard/libctest_testcode.sh

Expand All @@ -43,24 +48,24 @@ libc-bench: .PHONY
cp libc-bench/libc-bench sdcard/libc-bench

unix-bench: .PHONY
make -C UnixBench -j $(NPROC) all
make -C UnixBench CC=$(MUSL_GCC) ARCH=$(ARCH) -j $(NPROC) all
cp UnixBench/pgms/* sdcard
cp scripts/unixbench/*.sh sdcard

netperf: .PHONY
cd netperf && ./autogen.sh
cd netperf && ac_cv_func_setpgrp_void=yes ./configure --host riscv64 CC=$(MUSL_GCC) CFLAGS="-static"
cd netperf && ac_cv_func_setpgrp_void=yes ./configure --host=$(MUSL_PREFIX) CC=$(MUSL_GCC) CFLAGS="-static"
cd netperf && make -j $(NPROC)
cp netperf/src/netperf netperf/src/netserver sdcard/
cp scripts/netperf/* sdcard/

iperf: .PHONY
cd iperf && ./configure --host=riscv64-linux-musl CC=$(MUSL_GCC) --enable-static-bin --without-sctp && make
cd iperf && ./configure --host=$(MUSL_PREFIX) CC=$(MUSL_GCC) --enable-static-bin --without-sctp --without-openssl && make
cp iperf/src/iperf3 sdcard/
cp scripts/iperf/iperf_testcode.sh sdcard/

cyclictest: .PHONY
make -C rt-tests cyclictest hackbench
make -C rt-tests PREFIX=$(MUSL_PREFIX) NUMA=0 cyclictest hackbench
cp rt-tests/cyclictest rt-tests/hackbench sdcard/
cp scripts/cyclictest/cyclictest_testcode.sh sdcard/

Expand Down Expand Up @@ -116,9 +121,10 @@ clean: .PHONY
make -C UnixBench clean
make -C time-test clean
make -C rt-tests clean
make -C true clean
make -C copy-file-range-test clean
make -C interrupts-test clean
- rm sdcard/*
- rm -rf sdcard/*
- rm sdcard.img
- rm sdcard.img.gz

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ time-test 为测试Kernel的time函数是否准确,其结果只作为专家评

## 构建测试用例

```
docker run --rm -it -v $(pwd):/code --privileged --entrypoint make alphamj/os-contest:v7.7 -C /code sdcard
```

OR

```
make sdcard ARCH=x86_64
```
8 changes: 5 additions & 3 deletions UnixBench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ SHELL = /bin/sh
# COMPILER CONFIGURATION: Set "CC" to the name of the compiler to use
# to build the binary benchmarks. You should also set "$cCompiler" in the
# Run script to the name of the compiler you want to test.
CC=riscv64-linux-gcc -static
CC ?= riscv64-linux-gcc
CC += " -static"

# OPTIMISATION SETTINGS:
# Use gcc option if defined UB_GCC_OPTIONS via "Environment variable" or "Command-line arguments".
Expand Down Expand Up @@ -87,15 +88,16 @@ else
## OS detection. Comment out if gmake syntax not supported by other 'make'.
OSNAME:=$(shell uname -s)
# ARCH := $(shell uname -m)
ARCH :=riscv64
ARCH ?= riscv64
ifeq ($(OSNAME),Linux)
# Not all CPU architectures support "-march" or "-march=native".
# - Supported : x86, x86_64, ARM, AARCH64, riscv64, etc..
# - Not Supported: IBM Power, etc...
ifeq ($(ARCH),$(filter $(ARCH),ppc64 ppc64le))
OPTON += -mcpu=native -mtune=native
else ifeq ($(ARCH),riscv64)
OPTON += -march=rv64g -mabi=lp64
#OPTON += -march=rv64g -mabi=lp64
OPTON += -march=rv64g -mabi=lp64d
else
OPTON += -march=native -mtune=native
endif
Expand Down
9 changes: 5 additions & 4 deletions libc-test/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MUSL_LIB?=/opt/riscv64--musl--bleeding-edge-2020.08-1/riscv64-buildroot-linux-musl/sysroot/lib64/
PREFIX?=riscv64-buildroot-linux-musl-
CC=$(PREFIX)gcc
OBJCOPY=$(PREFIX)objcopy
PREFIX ?= riscv64-buildroot-linux-musl
CC=$(PREFIX)-gcc
OBJCOPY=$(PREFIX)-objcopy
MUSL_LIB ?= $(shell $(CC) -print-sysroot)/lib/

STATIC_EXES = $(shell cat static.txt)
STATIC_OBJS = $(STATIC_EXES:%.exe=%.obj)
Expand All @@ -23,6 +23,7 @@ CFLAGS += -pipe -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wno-unused-function -W
CFLAGS += -Wno-unknown-pragmas -fno-builtin -frounding-math
CFLAGS += -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith
CFLAGS += -Os -s
CFLAGS += -fPIC
CFLAGS += -Isrc/common/
LDLIBS += -Os -s -lpthread -lm -lrt

Expand Down
7 changes: 5 additions & 2 deletions rt-tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
VERSION = 1.0
CC =riscv64-linux-gcc -static
AR =riscv64-linux-ar
PREFIX ?= riscv64-linux-musl
CC := $(PREFIX)-gcc -static
AR := $(PREFIX)-ar

OBJDIR = bld

Expand Down Expand Up @@ -30,6 +31,8 @@ CFLAGS ?= -Wall -Wno-nonnull
CPPFLAGS += -D_GNU_SOURCE -Isrc/include
LDFLAGS ?=

CFLAGS += -fPIC

PYLIB ?= $(shell python -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib()')

ifndef DEBUG
Expand Down
5 changes: 4 additions & 1 deletion true/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

all:
$(CC) main.c -static -Os -o true
$(CC) main.c -static -Os -o true

clean:
rm true

0 comments on commit ff418c6

Please sign in to comment.