From ff418c617de498ce03114f9507e5bdabae7843b9 Mon Sep 17 00:00:00 2001 From: Luoyuan Xiao Date: Tue, 2 Jan 2024 15:41:54 +0800 Subject: [PATCH] Supported x86_64 musl --- Makefile | 30 ++++++++++++++++++------------ README.md | 8 ++++++++ UnixBench/Makefile | 8 +++++--- libc-test/Makefile | 9 +++++---- rt-tests/Makefile | 7 +++++-- true/Makefile | 5 ++++- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index f72f1e6b..7701e294 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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/ @@ -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 diff --git a/README.md b/README.md index 616d6c97..96d070b7 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/UnixBench/Makefile b/UnixBench/Makefile index 19715e02..6d83272d 100644 --- a/UnixBench/Makefile +++ b/UnixBench/Makefile @@ -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". @@ -87,7 +88,7 @@ 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.. @@ -95,7 +96,8 @@ else 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 diff --git a/libc-test/Makefile b/libc-test/Makefile index 0b89081f..fe7874d1 100644 --- a/libc-test/Makefile +++ b/libc-test/Makefile @@ -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) @@ -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 diff --git a/rt-tests/Makefile b/rt-tests/Makefile index c2ef61f0..4a204647 100644 --- a/rt-tests/Makefile +++ b/rt-tests/Makefile @@ -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 @@ -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 diff --git a/true/Makefile b/true/Makefile index f69ed6be..930ed929 100644 --- a/true/Makefile +++ b/true/Makefile @@ -1,3 +1,6 @@ all: - $(CC) main.c -static -Os -o true \ No newline at end of file + $(CC) main.c -static -Os -o true + +clean: + rm true