Skip to content

Commit 7d2a8d7

Browse files
authored
Merge pull request #5 from XuJiandong/cfi
Add CFI support
2 parents 9469bca + af7750f commit 7d2a8d7

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ jobs:
1111
- uses: actions/checkout@v4
1212
with:
1313
submodules: recursive
14-
- name: Install llvm 18
14+
- name: Install llvm 21
1515
run: |
16-
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
1716
wget https://apt.llvm.org/llvm.sh
1817
chmod +x llvm.sh
19-
sudo ./llvm.sh 18
18+
sudo ./llvm.sh 21
2019
rm llvm.sh
21-
- name: Fix llvm-ar path
20+
- name: Fix llvm path
2221
run: |
23-
sudo ln -s $(which llvm-ar-18) /usr/bin/llvm-ar || true
22+
sudo ln -sf $(which llvm-ar-21) /usr/bin/llvm-ar
23+
sudo ln -sf $(which clang-21) /usr/bin/clang
2424
- name: Build
2525
run: make
26+
- name: Build with CFI enabled
27+
run: make clean && make CFI=unlabeled

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
CC := clang
22
AR := llvm-ar
33

4-
CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs -mabi=lp64
4+
define get_cfi_cflags
5+
$(if $(1),\
6+
$(info Info: build with CFI enabled)\
7+
$(eval _CLANG_VERSION := $(shell $(CC) --version | head -n1 | sed -n 's/.*version \([0-9]*\)\..*/\1/p'))\
8+
$(if $(shell test $(_CLANG_VERSION) -ge 21 && echo 1),\
9+
--target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs_zicfiss1p0_zicfilp1p0 -mabi=lp64 \
10+
-menable-experimental-extensions -fcf-protection=full \
11+
$(if $(filter unlabeled,$(1)),\
12+
-mcf-branch-label-scheme=unlabeled,\
13+
$(if $(filter func-sig,$(1)),\
14+
-mcf-branch-label-scheme=func-sig,\
15+
$(error Error: CFI is set to '$(1)' but expected 'unlabeled' or 'func-sig'))),\
16+
$(error Error: CFI requires clang version 21 or above, but found version $(_CLANG_VERSION))),\
17+
--target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs -mabi=lp64)
18+
endef
19+
20+
CFLAGS := $(call get_cfi_cflags,$(CFI))
21+
522
CFLAGS += -Os
623
CFLAGS += -fdata-sections -ffunction-sections -fno-builtin -fvisibility=hidden -fomit-frame-pointer
724
CFLAGS += -I compiler-rt/lib/builtins

0 commit comments

Comments
 (0)