Rework the build system to be more modular
Split most of the work off into make/base.mk and allow for easy wrappers to be created around that that can build with different instrumentation in their own build directory. Create wrappers for the following: - release build - debug build - afl++ fuzzing build - static analysis with clang - clang memory sanitizer - clang address/undefined sanitizer
This commit is contained in:
parent
0d3881f680
commit
0f9ced8eb1
70
Makefile
70
Makefile
@ -1,54 +1,42 @@
|
|||||||
.PHONY: all clean clean-objects clean-reports run sanitize validate fuzz
|
.PHONY: all clean distclean release debug afl asan msan validate analyze fuzz
|
||||||
|
|
||||||
CC=clang
|
debug:
|
||||||
LD=clang
|
make -rRf make/debug.mk all
|
||||||
CFLAGS=-Wall -Wextra -Wpedantic -O0 -g3 -std=c23 -fno-omit-frame-pointer -fno-optimize-sibling-calls -D_POSIX_C_SOURCE=200809L
|
|
||||||
LDFLAGS?=
|
|
||||||
|
|
||||||
SOURCES = $(shell find src/ -type f -name '*.c')
|
all: debug release afl asan msan
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
|
||||||
DEPENDENCIES = $(SOURCES:.c=.d)
|
|
||||||
TARGET?=oas
|
|
||||||
OUTPUTS=oas oas-asan oas-msan oas-afl
|
|
||||||
RUNARGUMENTS?=ast tests/input/valid.asm
|
|
||||||
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
|
|
||||||
run: $(TARGET)
|
release:
|
||||||
./$(TARGET) $(RUNARGUMENTS)
|
make -rRf make/release.mk all
|
||||||
|
|
||||||
|
afl:
|
||||||
|
make -rRf make/afl.mk all
|
||||||
|
|
||||||
fuzz:
|
fuzz:
|
||||||
make CC="afl-clang-fast" LD="afl-clang-fast" TARGET="oas-afl" clean-objects all
|
make -rRf make/afl.mk fuzz
|
||||||
make clean-objects
|
|
||||||
mkdir -p reports/afl
|
|
||||||
afl-fuzz -i tests/input -o reports/afl -m none -- ./oas-afl -tokens @@
|
|
||||||
|
|
||||||
sanitize:
|
asan:
|
||||||
make CFLAGS="$(CFLAGS) -fsanitize=address,undefined" \
|
make -rRf make/asan.mk all
|
||||||
LDFLAGS="-fsanitize=address,undefined" \
|
|
||||||
TARGET="oas-asan" clean-objects all
|
|
||||||
make CFLAGS="$(CFLAGS) -fsanitize=memory -fsanitize-memory-track-origins=2" \
|
|
||||||
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2" \
|
|
||||||
TARGET="oas-msan" clean-objects all
|
|
||||||
make clean-objects
|
|
||||||
|
|
||||||
validate:
|
msan:
|
||||||
|
make -rRf make/msan.mk all
|
||||||
|
|
||||||
|
validate: asan msan debug
|
||||||
./validate.sh
|
./validate.sh
|
||||||
|
|
||||||
$(TARGET): $(OBJECTS)
|
analyze:
|
||||||
$(LD) $(LDFLAGS) -o $@ $^
|
make -rRf make/analyze.mk clean all
|
||||||
|
|
||||||
%.o: %.c
|
clean:
|
||||||
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
make -rRf make/release.mk clean
|
||||||
|
make -rRf make/debug.mk clean
|
||||||
|
make -rRf make/afl.mk clean
|
||||||
|
make -rRf make/msan.mk clean
|
||||||
|
make -rRf make/asan.mk clean
|
||||||
|
make -rRf make/analyze.mk clean
|
||||||
|
rm -rf build/
|
||||||
|
|
||||||
-include $(DEPENDENCIES)
|
distclean: clean
|
||||||
|
make -rRf make/afl.mk distclean
|
||||||
clean-objects:
|
make -rRf make/analyze.mk distclean
|
||||||
rm -f $(OBJECTS) $(DEPENDENCIES)
|
|
||||||
|
|
||||||
clean-reports:
|
|
||||||
rm -rf reports/
|
rm -rf reports/
|
||||||
|
|
||||||
clean: clean-objects
|
|
||||||
rm -f $(TARGET) $(OUTPUTS)
|
|
||||||
|
14
make/afl.mk
Normal file
14
make/afl.mk
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.PHONY: fuzz distclean
|
||||||
|
|
||||||
|
CC=afl-clang-fast
|
||||||
|
LD=afl-clang-fast
|
||||||
|
BUILD_DIR=build/afl/
|
||||||
|
|
||||||
|
-include make/base.mk
|
||||||
|
|
||||||
|
fuzz: $(BUILD_DIR)$(TARGET)
|
||||||
|
mkdir -p reports/afl
|
||||||
|
afl-fuzz -i tests/input -o reports/afl -m none -- ./$< -tokens @@
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -rf reports/afl
|
9
make/analyze.mk
Normal file
9
make/analyze.mk
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
BUILD_DIR=build/analyze/
|
||||||
|
-include make/base.mk
|
||||||
|
|
||||||
|
analyze:
|
||||||
|
mkdir -p reports/static-analysis
|
||||||
|
scan-build -o reports/static-analysis/ -plist-html --status-bugs make -rRf make/analyze.mk all
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -rf reports/static-analysis
|
5
make/asan.mk
Normal file
5
make/asan.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CFLAGS=-Wall -Wextra -Wpedantic -O0 -g3 -std=c23 -fno-omit-frame-pointer -fno-optimize-sibling-calls -D_POSIX_C_SOURCE=200809L -fsanitize=address,undefined
|
||||||
|
LDFLAGS=-fsanitize=address,undefined
|
||||||
|
BUILD_DIR=build/asan/
|
||||||
|
|
||||||
|
-include make/base.mk
|
27
make/base.mk
Normal file
27
make/base.mk
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
CC?=clang
|
||||||
|
LD?=clang
|
||||||
|
CFLAGS?=-Wall -Wextra -Wpedantic -O0 -g3 -std=c23 -fno-omit-frame-pointer -fno-optimize-sibling-calls -D_POSIX_C_SOURCE=200809L
|
||||||
|
LDFLAGS?=
|
||||||
|
BUILD_DIR?=build/debug/
|
||||||
|
|
||||||
|
SOURCES?=$(shell find src/ -type f -name '*.c')
|
||||||
|
OBJECTS=$(patsubst %.c,$(BUILD_DIR)%.o,$(SOURCES))
|
||||||
|
DEPENDENCIES=$(OBJECTS:.o=.d)
|
||||||
|
TARGET?=oas
|
||||||
|
|
||||||
|
all: $(BUILD_DIR)$(TARGET)
|
||||||
|
|
||||||
|
|
||||||
|
$(BUILD_DIR)$(TARGET): $(OBJECTS)
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
$(BUILD_DIR)%.o: %.c
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
-include $(DEPENDENCIES)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(BUILD_DIR)
|
1
make/debug.mk
Normal file
1
make/debug.mk
Normal file
@ -0,0 +1 @@
|
|||||||
|
-include make/base.mk
|
5
make/msan.mk
Normal file
5
make/msan.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CFLAGS=-Wall -Wextra -Wpedantic -O0 -g3 -std=c23 -fno-omit-frame-pointer -fno-optimize-sibling-calls -D_POSIX_C_SOURCE=200809L -fsanitize=memory
|
||||||
|
LDFLAGS=-fsanitize=memory
|
||||||
|
BUILD_DIR=build/msan/
|
||||||
|
|
||||||
|
-include make/base.mk
|
5
make/release.mk
Normal file
5
make/release.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CFLAGS?=-Wall -Wextra -Wpedantic -O2 -std=c23 -flto -fomit-frame-pointer -DNDEBUG -D_POSIX_C_SOURCE=200809L
|
||||||
|
LDFLAGS?=-flto -s -Wl,--gc-sections
|
||||||
|
BUILD_DIR?=build/release/
|
||||||
|
|
||||||
|
-include make/base.mk
|
16
validate.sh
16
validate.sh
@ -2,19 +2,17 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Start with static analysis
|
make analyze debug asan msan
|
||||||
make clean all
|
|
||||||
mkdir -p reports/static-analysis
|
|
||||||
scan-build -o reports/static-analysis/ -plist-html --status-bugs make all
|
|
||||||
|
|
||||||
# Run the sanitizer builds and valgrind
|
ASAN=build/asan/oas
|
||||||
make clean sanitize all
|
MSAN=build/msan/oas
|
||||||
|
DEBUG=build/debug/oas
|
||||||
|
|
||||||
ARGUMENTS=("tokens" "text" "ast")
|
ARGUMENTS=("tokens" "text" "ast")
|
||||||
while IFS= read -r INPUT_FILE; do
|
while IFS= read -r INPUT_FILE; do
|
||||||
for ARGS in ${ARGUMENTS[@]}; do
|
for ARGS in ${ARGUMENTS[@]}; do
|
||||||
./oas-asan $ARGS $INPUT_FILE > /dev/null
|
$ASAN $ARGS $INPUT_FILE > /dev/null
|
||||||
./oas-msan $ARGS $INPUT_FILE > /dev/null
|
$MSAN $ARGS $INPUT_FILE > /dev/null
|
||||||
valgrind --leak-check=full --error-exitcode=1 ./oas $ARGS $INPUT_FILE >/dev/null
|
valgrind --leak-check=full --error-exitcode=1 $DEBUG $ARGS $INPUT_FILE >/dev/null
|
||||||
done
|
done
|
||||||
done < <(find tests/input/ -type f -name '*.asm')
|
done < <(find tests/input/ -type f -name '*.asm')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user