From e8b4d74a6e52f9bad0a210cda79535a58a5fa42d Mon Sep 17 00:00:00 2001 From: Kyle Zeng Date: Tue, 30 Apr 2024 13:55:25 -0700 Subject: [PATCH] refactor Makefile, write it in the real Makefile syntax --- Makefile | 64 +++++++++++++++++----------------------------- ci/test/action.yml | 2 +- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 9d2786d..df0d393 100644 --- a/Makefile +++ b/Makefile @@ -1,41 +1,30 @@ -BASE = malloc_playground first_fit calc_tcache_idx -V2.23 = fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack house_of_einherjar house_of_force house_of_gods house_of_lore house_of_mind_fastbin house_of_orange house_of_roman house_of_spirit house_of_storm large_bin_attack mmap_overlapping_chunks overlapping_chunks overlapping_chunks_2 poison_null_byte unsafe_unlink unsorted_bin_attack unsorted_bin_into_stack sysmalloc_int_free -V2.24 = fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack house_of_einherjar house_of_force house_of_gods house_of_lore house_of_mind_fastbin house_of_roman house_of_spirit house_of_storm large_bin_attack mmap_overlapping_chunks overlapping_chunks overlapping_chunks_2 poison_null_byte unsafe_unlink unsorted_bin_attack unsorted_bin_into_stack sysmalloc_int_free -V2.27 = fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_force house_of_lore house_of_mind_fastbin house_of_spirit house_of_storm large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink unsorted_bin_attack unsorted_bin_into_stack sysmalloc_int_free house_of_tangerine -V2.31 = fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink sysmalloc_int_free house_of_tangerine -V2.32 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.33 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.34 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.35 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.36 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.37 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.38 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine -V2.39 = decrypt_safe_linking fastbin_dup fastbin_dup_consolidate fastbin_dup_into_stack fastbin_reverse_into_tcache house_of_botcake house_of_einherjar house_of_lore house_of_mind_fastbin house_of_spirit large_bin_attack mmap_overlapping_chunks overlapping_chunks poison_null_byte tcache_house_of_spirit tcache_poisoning tcache_stashing_unlink_attack unsafe_unlink safe_link_double_protect house_of_water sysmalloc_int_free house_of_tangerine - -# turn technique names into paths -VV2.23 = $(addprefix glibc_2.23/, $(V2.23)) -VV2.24 = $(addprefix glibc_2.24/, $(V2.24)) -VV2.27 = $(addprefix glibc_2.27/, $(V2.27)) -VV2.31 = $(addprefix glibc_2.31/, $(V2.31)) -VV2.32 = $(addprefix glibc_2.32/, $(V2.32)) -VV2.33 = $(addprefix glibc_2.33/, $(V2.33)) -VV2.34 = $(addprefix glibc_2.34/, $(V2.34)) -VV2.35 = $(addprefix glibc_2.35/, $(V2.35)) -VV2.36 = $(addprefix glibc_2.36/, $(V2.36)) -VV2.37 = $(addprefix glibc_2.37/, $(V2.37)) -VV2.38 = $(addprefix glibc_2.38/, $(V2.38)) -VV2.39 = $(addprefix glibc_2.39/, $(V2.39)) - -PROGRAMS = $(BASE) $(VV2.23) $(VV2.24) $(VV2.27) $(VV2.31) $(VV2.32) $(VV2.33) $(VV2.34) $(VV2.35) $(VV2.36) $(VV2.37) $(VV2.38) $(VV2.39) +.PHONY: help clean all test + +VERSIONS := 2.23 2.24 2.27 2.31 2.32 2.33 2.34 2.35 2.36 2.37 2.38 2.39 +TECH_BINS := $(patsubst %.c,%,$(wildcard glibc_*/*.c)) +BASE_BINS := $(patsubst %.c,%,$(wildcard *.c)) +BINS := $(TECH_BINS) $(BASE_BINS) + +help: + @echo 'make help - show this message' + @echo 'make base - build all base binaries, namely `malloc_playground`, `first_fit`, `calc_tcache_idx`' + @echo 'make - build all the techniques for the specific version. e.g. `make v2.39`' + @echo 'make clean - remove all built binaries' + @echo 'make all - build all binaries' + @echo 'make test version= - test run all techniques for the specific version. e.g. `make test version=2.39`' + CFLAGS += -std=c99 -g -Wno-unused-result -Wno-free-nonheap-object LDLIBS += -ldl -# Convenience to auto-call mcheck before the first malloc() -#CFLAGS += -lmcheck +base: $(BASE_BINS) + +$(foreach version,$(VERSIONS),$(eval v$(version): $(patsubst %.c,%,$(wildcard glibc_$(version)/*.c)))) + +all: $(BINS) -all: $(PROGRAMS) clean: - rm -f $(PROGRAMS) + @rm -f $(BINS) + @echo "all the built binaries are removed." define test_poc = echo $(poc) @@ -48,10 +37,5 @@ done echo "success" endef -#if [ "$$i" == "5" ]; then exit 1; fi;\ - -test: $(PROGRAMS) - @if [ -z "$(target)" ] || [ -z "$(VV$(target))" ];\ - then echo "run 'make test target=' to test existing techniques"; exit 1; fi; - - @$(foreach poc,$(VV$(target)),$(call test_poc,$(poc));) +test: v$(version) + @$(foreach poc,$(patsubst %.c,%,$(wildcard glibc_$(version)/*.c)),$(call test_poc,$(poc));) diff --git a/ci/test/action.yml b/ci/test/action.yml index 0dc032b..9e1c8e7 100644 --- a/ci/test/action.yml +++ b/ci/test/action.yml @@ -18,5 +18,5 @@ runs: - name: test how2heap inside the raw container run: | - docker run -v /tmp/how2heap:/how2heap ubuntu_test bash -c 'cd /how2heap; ./make test target=${{ inputs.glibc }}' + docker run -v /tmp/how2heap:/how2heap ubuntu_test bash -c 'cd /how2heap; ./make test version=${{ inputs.glibc }}' shell: bash