|
1 |
| -.PHONY: help clean all test |
| 1 | +.PHONY: help clean distclean all test |
2 | 2 |
|
3 | 3 | 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
|
4 | 4 | TECH_BINS := $(patsubst %.c,%,$(wildcard glibc_*/*.c))
|
5 | 5 | BASE_BINS := $(patsubst %.c,%,$(wildcard *.c))
|
| 6 | +DOWNLOADED := glibc-all-in-one/libs glibc-all-in-one/debs |
6 | 7 | BINS := $(TECH_BINS) $(BASE_BINS)
|
| 8 | +ARCH := amd64 |
| 9 | + |
| 10 | +ifeq ($(H2H_USE_SYSTEM_LIBC),) |
| 11 | +H2H_USE_SYSTEM_LIBC := Y |
| 12 | +endif |
7 | 13 |
|
8 | 14 | help:
|
9 | 15 | @echo 'make help - show this message'
|
10 | 16 | @echo 'make base - build all base binaries, namely `malloc_playground`, `first_fit`, `calc_tcache_idx`'
|
11 |
| - @echo 'make <version> - build all the techniques for the specific version. e.g. `make v2.39`' |
| 17 | + @echo 'make <version> - build all the techniques for a specific version. e.g. `make v2.39`' |
12 | 18 | @echo 'make clean - remove all built binaries'
|
| 19 | + @echo 'make distclean - remove all built binaries and downloaded libcs' |
13 | 20 | @echo 'make all - build all binaries'
|
14 |
| - @echo 'make test version=<version> - test run all techniques for the specific version. e.g. `make test version=2.39`' |
| 21 | + @echo 'make test version=<version> - test run all techniques for a specific version. e.g. `make test version=2.39`' |
15 | 22 |
|
16 | 23 | CFLAGS += -std=c99 -g -Wno-unused-result -Wno-free-nonheap-object
|
17 | 24 | LDLIBS += -ldl
|
18 | 25 |
|
19 | 26 | base: $(BASE_BINS)
|
20 | 27 |
|
| 28 | +# populate the download_glibc_<version> rules |
| 29 | +$(addprefix download_glibc_, $(VERSIONS)): |
| 30 | + @echo $@ |
| 31 | + |
| 32 | + version=$(patsubst download_glibc_%,%,$@); \ |
| 33 | + libc=$$(cat glibc-all-in-one/list | grep "$$version" | grep "$(ARCH)" | head -n 1); \ |
| 34 | + old_libc=$$(cat glibc-all-in-one/old_list | grep "$(version)" | grep "$(ARCH)" | head -n 1); \ |
| 35 | + if [ -z $$libc ]; then libc=$$old_libc; script="download_old"; else libc=$$libc; script="download"; fi; \ |
| 36 | + cd glibc-all-in-one; \ |
| 37 | + rm -rf libs/$$libc; \ |
| 38 | + ./$$script $$libc |
| 39 | + |
| 40 | +# populate the make <version> rules |
| 41 | +ifeq ($(H2H_USE_SYSTEM_LIBC),Y) |
21 | 42 | $(foreach version,$(VERSIONS),$(eval v$(version): $(patsubst %.c,%,$(wildcard glibc_$(version)/*.c))))
|
| 43 | +else |
| 44 | +$(foreach version,$(VERSIONS),$(eval v$(version): download_glibc_$(version) $(patsubst %.c,%,$(wildcard glibc_$(version)/*.c)) )) |
| 45 | +endif |
| 46 | + |
| 47 | +# the compilation rules |
| 48 | +%: %.c |
| 49 | + version=$(word 1, $(subst /, ,$(patsubst glibc_%,%,$@))); \ |
| 50 | + if [ "$(H2H_USE_SYSTEM_LIBC)" = "Y" ]; \ |
| 51 | + then \ |
| 52 | + $(CC) $(CFLAGS) $(DIR_CFLAGS_$(@D)) $^ -o $@ $(LDLIBS); \ |
| 53 | + else \ |
| 54 | + $(CC) $(CFLAGS) $(DIR_CFLAGS_$(@D)) $^ -o $@ $(LDLIBS) -Xlinker -rpath=$$(realpath glibc-all-in-one/libs/$$version*) -Xlinker -I$$(realpath glibc-all-in-one/libs/$$version*/ld-linux-x86-64.so.2) -Xlinker $$(realpath glibc-all-in-one/libs/$$version*/libc.so.6) -Xlinker $$(realpath glibc-all-in-one/libs/$$version*/libdl.so.2) -include ./utils/wrapper.h -Wl,--wrap=__libc_start_main -Wl,--wrap=dlsym; \ |
| 55 | + fi |
22 | 56 |
|
23 | 57 | all: $(BINS)
|
24 | 58 |
|
25 | 59 | clean:
|
26 | 60 | @rm -f $(BINS)
|
27 | 61 | @echo "all the built binaries are removed."
|
28 | 62 |
|
| 63 | +distclean: |
| 64 | + @rm -f $(BINS) |
| 65 | + @rm -rf $(DOWNLOADED) |
| 66 | + @echo "all the built binaries and all downloaded libcs are removed." |
| 67 | + |
29 | 68 | define test_poc =
|
30 | 69 | echo $(poc)
|
31 | 70 | for i in $$(seq 0 20);\
|
|
0 commit comments