Skip to content

Commit faa2a72

Browse files
committed
feat: add CFI support
1 parent 9469bca commit faa2a72

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ 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
2120
- name: Fix llvm-ar path
2221
run: |
23-
sudo ln -s $(which llvm-ar-18) /usr/bin/llvm-ar || true
22+
sudo ln -s $(which llvm-ar-21) /usr/bin/llvm-ar || true
2423
- name: Build
2524
run: make
25+
- name: Build with CFI enabled
26+
run: make clean && make CFI=unlabeled

Makefile

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

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

0 commit comments

Comments
 (0)