Skip to content

Commit

Permalink
fix(libso): include headers from RTL simulators
Browse files Browse the repository at this point in the history
Since libso requires some headers from RTL simulators, this commit
adds the corresponding include flags. As we are not sure whether
the headers are simulator-dependent, we include VCS headers with a
higher priority than Verilator.

We also add a CI test for difftest-so on XiangShan
  • Loading branch information
poemonsense committed Dec 29, 2024
1 parent 8cfb992 commit 91ec35e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,34 @@ jobs:
make simv VCS=verilator -j2
./build/simv +workload=$WORKLOAD +b=0 +e=-1 +diff=$REF_SO +max-instrs=5000 +warmup_instr=1000
make clean
test-difftest-xiangshan:
# ubuntu 22.04 has the same version of libc as our VCS machines
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Prepare environment
run: |
cd $GITHUB_WORKSPACE/..
wget https://github.com/OpenXiangShan/xs-env/raw/refs/heads/master/install-verilator.sh
wget https://github.com/OpenXiangShan/xs-env/raw/refs/heads/master/setup-tools.sh
sudo bash setup-tools.sh
- name: Prepare XiangShan
run: |
cd $GITHUB_WORKSPACE/..
git clone --depth 1 https://github.com/OpenXiangShan/XiangShan.git
cd XiangShan && make init && rm -rf difftest && cp -r $GITHUB_WORKSPACE .
echo "NOOP_HOME=$(pwd)" >> $GITHUB_ENV
- name: Chisel Elaboration
run: |
cd $NOOP_HOME
make sim-verilog CHISEL_TARGET=chirrtl JVM_XMX=10G
- name: Build difftest-so
run: |
cd $NOOP_HOME
make -C difftest difftest-so
16 changes: 16 additions & 0 deletions libso.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@ ifeq ($(WITH_DRAMSIM3),1)
LD_LIB = -L $(DRAMSIM3_HOME)/ -ldramsim3 -Wl,-rpath-link=$(DRAMSIM3_HOME)/libdramsim3.so
endif

# Include headers that are implicitly included by RTL simulators
# Priority: (1) VCS, (2) Verilator
ifneq ($(VCS_HOME),)
LIB_CXXFLAGS += -I$(VCS_HOME)/include
else
VERILATOR_ROOT = $(shell verilator -V 2>/dev/null | awk '/VERILATOR_ROOT/ {print $$3; exit}')
ifneq ($(VERILATOR_ROOT),)
LIB_CXXFLAGS += -I$(VERILATOR_ROOT)/include/vltstd
else
LIBSO_WARNING_MISSING_HEADERS = 1
endif
endif

$(CC_OBJ_DIR):
mkdir -p $(CC_OBJ_DIR)

difftest-so: $(CC_OBJ_DIR)
ifeq ($(LIBSO_WARNING_MISSING_HEADERS),1)
@echo "No available RTL simulators. Headers may be missing. Still try to build it."
endif
cd $(CC_OBJ_DIR) && \
$(CC) $(LIB_CXXFLAGS) $(LIB_CXXFILES) && \
$(CC) -o $(LIBDIFFTEST_SO) -m64 -shared *.o $(LD_LIB)

0 comments on commit 91ec35e

Please sign in to comment.