aboutgitcodebugslistschat
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile325
1 files changed, 123 insertions, 202 deletions
diff --git a/Makefile b/Makefile
index b6329e3..c4af57b 100644
--- a/Makefile
+++ b/Makefile
@@ -15,78 +15,63 @@ VERSION ?= $(shell git describe --tags HEAD 2>/dev/null || echo "unknown\ versio
# the IPv6 socket API? (Linux does)
DUAL_STACK_SOCKETS := 1
-RLIMIT_STACK_VAL := $(shell /bin/sh -c 'ulimit -s')
-ifeq ($(RLIMIT_STACK_VAL),unlimited)
-RLIMIT_STACK_VAL := 1024
-endif
-
TARGET ?= $(shell $(CC) -dumpmachine)
+$(if $(TARGET),,$(error Failed to get target architecture))
# Get 'uname -m'-like architecture description for target
-TARGET_ARCH := $(shell echo $(TARGET) | cut -f1 -d- | tr [A-Z] [a-z])
-TARGET_ARCH := $(shell echo $(TARGET_ARCH) | sed 's/powerpc/ppc/')
-
-AUDIT_ARCH := $(shell echo $(TARGET_ARCH) | tr [a-z] [A-Z] | sed 's/^ARM.*/ARM/')
-AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/I[456]86/I386/')
-AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPC64/PPC/')
-AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPCLE/PPC64LE/')
-AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/MIPS64EL/MIPSEL64/')
-AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/HPPA/PARISC/')
-AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/SH4/SH/')
-
-FLAGS := -Wall -Wextra -Wno-format-zero-length
-FLAGS += -pedantic -std=c11 -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
-FLAGS += -D_FORTIFY_SOURCE=2 -O2 -pie -fPIE
-FLAGS += -DPAGE_SIZE=$(shell getconf PAGE_SIZE)
-FLAGS += -DNETNS_RUN_DIR=\"/run/netns\"
-FLAGS += -DPASST_AUDIT_ARCH=AUDIT_ARCH_$(AUDIT_ARCH)
-FLAGS += -DRLIMIT_STACK_VAL=$(RLIMIT_STACK_VAL)
-FLAGS += -DARCH=\"$(TARGET_ARCH)\"
-FLAGS += -DVERSION=\"$(VERSION)\"
-FLAGS += -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)
-
-PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c flow.c fwd.c \
- icmp.c igmp.c inany.c iov.c ip.c isolation.c lineread.c log.c mld.c \
- ndp.c netlink.c packet.c passt.c pasta.c pcap.c pif.c tap.c tcp.c \
- tcp_buf.c tcp_splice.c udp.c udp_flow.c util.c
+TARGET_ARCH := $(firstword $(subst -, ,$(TARGET)))
+TARGET_ARCH := $(patsubst [:upper:],[:lower:],$(TARGET_ARCH))
+TARGET_ARCH := $(patsubst arm%,arm,$(TARGET_ARCH))
+TARGET_ARCH := $(subst powerpc,ppc,$(TARGET_ARCH))
+
+# On some systems enabling optimization also enables source fortification,
+# automagically. Do not override it.
+FORTIFY_FLAG :=
+ifeq ($(shell $(CC) -O2 -dM -E - < /dev/null 2>&1 | grep ' _FORTIFY_SOURCE ' > /dev/null; echo $$?),1)
+FORTIFY_FLAG := -D_FORTIFY_SOURCE=2
+endif
+
+# Mandatory preprocessor flags that won't be overridden with $(CPPFLAGS)
+# FIXME: Could some of these be default, rather than required?
+BASE_CPPFLAGS := -D_XOPEN_SOURCE=700 -D_GNU_SOURCE $(FORTIFY_FLAG)
+BASE_CPPFLAGS += -DPAGE_SIZE=$(shell getconf PAGE_SIZE)
+BASE_CPPFLAGS += -DVERSION=\"$(VERSION)\"
+BASE_CPPFLAGS += -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)
+
+# Mandatory compiler flags that won't be overridden with $(CFLAGS)
+# FIXME: Could some of these be default, rather than required?
+BASE_CFLAGS := -std=c11 -pie -fPIE -O2
+BASE_CFLAGS += -pedantic -Wall -Wextra -Wno-format-zero-length -Wformat-security
+
+PASST_SRCS = arch.c arp.c bitmap.c checksum.c conf.c dhcp.c dhcpv6.c \
+ epoll_ctl.c flow.c fwd.c fwd_rule.c icmp.c igmp.c inany.c iov.c ip.c \
+ isolation.c lineread.c log.c mld.c ndp.c netlink.c migrate.c packet.c \
+ passt.c pasta.c pcap.c pif.c repair.c serialise.c tap.c tcp.c \
+ tcp_buf.c tcp_splice.c tcp_vu.c udp.c udp_flow.c udp_vu.c util.c \
+ vhost_user.c virtio.c vu_common.c
QRAP_SRCS = qrap.c
-SRCS = $(PASST_SRCS) $(QRAP_SRCS)
+PASST_REPAIR_SRCS = passt-repair.c
+PESTO_SRCS = pesto.c bitmap.c fwd_rule.c inany.c ip.c lineread.c serialise.c
+SRCS = $(PASST_SRCS) $(QRAP_SRCS) $(PASST_REPAIR_SRCS) $(PESTO_SRCS)
-MANPAGES = passt.1 pasta.1 qrap.1
+MANPAGES = passt.1 pasta.1 pesto.1 qrap.1 passt-repair.1
-PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h flow.h fwd.h \
- flow_table.h icmp.h icmp_flow.h inany.h iov.h ip.h isolation.h \
- lineread.h log.h ndp.h netlink.h packet.h passt.h pasta.h pcap.h pif.h \
+PASST_HEADERS = arch.h arp.h bitmap.h checksum.h conf.h dhcp.h dhcpv6.h \
+ epoll_ctl.h flow.h fwd.h fwd_rule.h flow_table.h icmp.h icmp_flow.h \
+ inany.h iov.h ip.h isolation.h lineread.h log.h migrate.h ndp.h \
+ netlink.h packet.h passt.h pasta.h pcap.h pif.h repair.h serialise.h \
siphash.h tap.h tcp.h tcp_buf.h tcp_conn.h tcp_internal.h tcp_splice.h \
- udp.h udp_flow.h util.h
-HEADERS = $(PASST_HEADERS) seccomp.h
-
-C := \#include <linux/tcp.h>\nstruct tcp_info x = { .tcpi_snd_wnd = 0 };
-ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
- FLAGS += -DHAS_SND_WND
-endif
-
-C := \#include <linux/tcp.h>\nstruct tcp_info x = { .tcpi_bytes_acked = 0 };
-ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
- FLAGS += -DHAS_BYTES_ACKED
-endif
-
-C := \#include <linux/tcp.h>\nstruct tcp_info x = { .tcpi_min_rtt = 0 };
-ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
- FLAGS += -DHAS_MIN_RTT
-endif
+ tcp_vu.h udp.h udp_flow.h udp_internal.h udp_vu.h util.h vhost_user.h \
+ virtio.h vu_common.h
+QRAP_HEADERS = arp.h ip.h passt.h util.h
+PASST_REPAIR_HEADERS = linux_dep.h
C := \#include <sys/random.h>\nint main(){int a=getrandom(0, 0, 0);}
ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
- FLAGS += -DHAS_GETRANDOM
+ BASE_CPPFLAGS += -DHAS_GETRANDOM
endif
ifeq ($(shell :|$(CC) -fstack-protector-strong -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
- FLAGS += -fstack-protector-strong
-endif
-
-C := \#define _GNU_SOURCE\n\#include <fcntl.h>\nint x = FALLOC_FL_COLLAPSE_RANGE;
-ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
- EXTRA_SYSCALLS += fallocate
+ BASE_CFLAGS += -fstack-protector-strong
endif
prefix ?= /usr/local
@@ -97,45 +82,61 @@ docdir ?= $(datarootdir)/doc/passt
mandir ?= $(datarootdir)/man
man1dir ?= $(mandir)/man1
+BASEBIN := passt qrap passt-repair pesto
+ifeq ($(TARGET_ARCH),x86_64)
+BASEBIN += passt.avx2
+endif
+
+BIN = $(BASEBIN) pasta
ifeq ($(TARGET_ARCH),x86_64)
-BIN := passt passt.avx2 pasta pasta.avx2 qrap
-else
-BIN := passt pasta qrap
+BIN += pasta.avx2
endif
all: $(BIN) $(MANPAGES) docs
-static: FLAGS += -static -DGLIBC_NO_STATIC_NSS
+static: BASE_CPPFLAGS += -DGLIBC_NO_STATIC_NSS
+static: BASE_CFLAGS += -static
static: clean all
seccomp.h: seccomp.sh $(PASST_SRCS) $(PASST_HEADERS)
- @ EXTRA_SYSCALLS="$(EXTRA_SYSCALLS)" ARCH="$(TARGET_ARCH)" CC="$(CC)" ./seccomp.sh $(PASST_SRCS) $(PASST_HEADERS)
+ @ EXTRA_SYSCALLS="$(EXTRA_SYSCALLS)" ARCH="$(TARGET_ARCH)" CC="$(CC)" ./seccomp.sh seccomp.h $(PASST_SRCS) $(PASST_HEADERS)
-passt: $(PASST_SRCS) $(HEADERS)
- $(CC) $(FLAGS) $(CFLAGS) $(CPPFLAGS) $(PASST_SRCS) -o passt $(LDFLAGS)
+seccomp_repair.h: seccomp.sh $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS)
+ @ ARCH="$(TARGET_ARCH)" CC="$(CC)" ./seccomp.sh seccomp_repair.h $(PASST_REPAIR_SRCS)
-passt.avx2: FLAGS += -Ofast -mavx2 -ftree-vectorize -funroll-loops
-passt.avx2: $(PASST_SRCS) $(HEADERS)
- $(CC) $(filter-out -O2,$(FLAGS)) $(CFLAGS) $(CPPFLAGS) \
- $(PASST_SRCS) -o passt.avx2 $(LDFLAGS)
+seccomp_pesto.h: seccomp.sh $(PESTO_SRCS)
+ @ ARCH="$(TARGET_ARCH)" CC="$(CC)" ./seccomp.sh seccomp_pesto.h $(PESTO_SRCS)
-passt.avx2: passt
+$(BASEBIN): %:
+ $(CC) $(BASE_CPPFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(CFLAGS) $(LDFLAGS) $(filter %.c,$^) -o $@
+
+passt: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
+
+passt.avx2: BASE_CFLAGS += -Ofast -mavx2 -ftree-vectorize -funroll-loops
+passt.avx2: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
pasta.avx2 pasta.1 pasta: pasta%: passt%
ln -sf $< $@
-qrap: $(QRAP_SRCS) passt.h
- $(CC) $(FLAGS) $(CFLAGS) $(CPPFLAGS) $(QRAP_SRCS) -o qrap $(LDFLAGS)
+qrap: BASE_CPPFLAGS += -DARCH=\"$(TARGET_ARCH)\"
+qrap: $(QRAP_SRCS) $(QRAP_HEADERS)
+
+passt-repair: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
+
+pesto: BASE_CPPFLAGS += -DPESTO
+pesto: $(PESTO_SRCS) $(PESTO_HEADERS) seccomp_pesto.h
valgrind: EXTRA_SYSCALLS += rt_sigprocmask rt_sigtimedwait rt_sigaction \
- rt_sigreturn getpid gettid kill clock_gettime mmap \
- munmap open unlink gettimeofday futex
-valgrind: FLAGS += -g -DVALGRIND
+ rt_sigreturn getpid gettid kill clock_gettime \
+ mmap|mmap2 munmap open unlink gettimeofday futex \
+ statx readlink
+valgrind: BASE_CPPFLAGS += -DVALGRIND
+valgrind: BASE_CFLAGS += -g
valgrind: all
.PHONY: clean
clean:
- $(RM) $(BIN) *~ *.o seccomp.h pasta.1 \
+ $(RM) $(BIN) *~ *.o seccomp.h seccomp_repair.h seccomp_pesto.h pasta.1 \
passt.tar passt.tar.gz *.deb *.rpm \
passt.pid README.plain.md
@@ -189,129 +190,49 @@ docs: README.md
done < README.md; \
) > README.plain.md
-# Checkers currently disabled for clang-tidy:
-# - llvmlibc-restrict-system-libc-headers
-# TODO: this is Linux-only for the moment, nice to fix eventually
-#
-# - google-readability-braces-around-statements
-# - hicpp-braces-around-statements
-# - readability-braces-around-statements
-# Debatable whether that improves readability, right now it would look
-# like a mess
-#
-# - readability-magic-numbers
-# - cppcoreguidelines-avoid-magic-numbers
-# TODO: in most cases they are justified, but probably not everywhere
-#
-# - clang-analyzer-valist.Uninitialized
-# TODO: enable once https://bugs.llvm.org/show_bug.cgi?id=41311 is fixed
-#
-# - clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
-# Probably not doable to impement this without plain memcpy(), memset()
-#
-# - cppcoreguidelines-init-variables
-# Dubious value, would kill readability
-#
-# - hicpp-signed-bitwise
-# Those are needed for syscalls, epoll_wait flags, etc.
-#
-# - llvm-include-order
-# TODO: not really important, but nice to fix eventually
-#
-# - readability-isolate-declaration
-# Dubious value, would kill readability
-#
-# - bugprone-narrowing-conversions
-# - cppcoreguidelines-narrowing-conversions
-# TODO: nice to fix eventually
-#
-# - cppcoreguidelines-avoid-non-const-global-variables
-# TODO: check, fix, and more in general constify wherever possible
-#
-# - altera-unroll-loops
-# - altera-id-dependent-backward-branch
-# TODO: check paths where it might make sense to improve performance
-#
-# - bugprone-easily-swappable-parameters
-# Not much can be done about them other than being careful
-#
-# - readability-function-cognitive-complexity
-# TODO: split reported functions
-#
-# - altera-struct-pack-align
-# "Poor" alignment needed for structs reflecting message formats/headers
-#
-# - concurrency-mt-unsafe
-# TODO: check again if multithreading is implemented
-#
-# - readability-identifier-length
-# Complains about any identifier <3 characters, reasonable for
-# globals, pointlessly verbose for locals and parameters.
-#
-# - bugprone-assignment-in-if-condition
-# Dubious value over the compiler's built-in warning. Would
-# increase verbosity.
-#
-# - misc-include-cleaner
-# Wants to include headers which *directly* provide the things
-# we use. That sounds nice, but means it will often want a OS
-# specific header instead of a mostly standard one, such as
-# <linux/limits.h> instead of <limits.h>.
-#
-# - cppcoreguidelines-macro-to-enum
-# Want to replace all #defines of integers with enums. Kind of
-# makes sense when those defines form an enum-like set, but
-# weird for cases like standalone constants, and causes other
-# awkwardness for a bunch of cases we use
-
-clang-tidy: $(SRCS) $(HEADERS)
- clang-tidy -checks=*,-modernize-*,\
- -clang-analyzer-valist.Uninitialized,\
- -cppcoreguidelines-init-variables,\
- -bugprone-assignment-in-if-condition,\
- -google-readability-braces-around-statements,\
- -hicpp-braces-around-statements,\
- -readability-braces-around-statements,\
- -readability-magic-numbers,\
- -llvmlibc-restrict-system-libc-headers,\
- -hicpp-signed-bitwise,\
- -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,\
- -llvm-include-order,\
- -cppcoreguidelines-avoid-magic-numbers,\
- -readability-isolate-declaration,\
- -bugprone-narrowing-conversions,\
- -cppcoreguidelines-narrowing-conversions,\
- -cppcoreguidelines-avoid-non-const-global-variables,\
- -altera-unroll-loops,-altera-id-dependent-backward-branch,\
- -bugprone-easily-swappable-parameters,\
- -readability-function-cognitive-complexity,\
- -altera-struct-pack-align,\
- -concurrency-mt-unsafe,\
- -readability-identifier-length,\
- -misc-include-cleaner,\
- -cppcoreguidelines-macro-to-enum \
- -config='{CheckOptions: [{key: bugprone-suspicious-string-compare.WarnOnImplicitComparison, value: "false"}]}' \
- --warnings-as-errors=* $(SRCS) -- $(filter-out -pie,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) -DCLANG_TIDY_58992
-
-SYSTEM_INCLUDES := /usr/include $(wildcard /usr/include/$(TARGET))
-ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"),1)
-VER := $(shell $(CC) -dumpversion)
-SYSTEM_INCLUDES += /usr/lib/gcc/$(TARGET)/$(VER)/include
-endif
-cppcheck: $(SRCS) $(HEADERS)
- if cppcheck --check-level=exhaustive /dev/null > /dev/null 2>&1; then \
- CPPCHECK_EXHAUSTIVE="--check-level=exhaustive"; \
- else \
- CPPCHECK_EXHAUSTIVE=; \
- fi; \
- cppcheck --std=c11 --error-exitcode=1 --enable=all --force \
+CLANG_TIDY = clang-tidy
+CLANG_TIDY_FLAGS = -DCLANG_TIDY_58992
+
+clang-tidy: passt.clang-tidy passt-repair.clang-tidy pesto.clang-tidy
+
+.PHONY: %.clang-tidy
+%.clang-tidy:
+ $(CLANG_TIDY) $(filter %.c,$^) -- $(BASE_CPPFLAGS) $(CPPFLAGS) $(CLANG_TIDY_FLAGS)
+
+passt.clang-tidy: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
+passt-repair.clang-tidy: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
+pesto.clang-tidy: $(PESTO_SRCS) $(PESTO_HEADERS) seccomp_pesto.h
+
+CPPCHECK = cppcheck
+CPPCHECK_FLAGS = --std=c11 --error-exitcode=1 --enable=all --force \
--inconclusive --library=posix --quiet \
- $${CPPCHECK_EXHAUSTIVE} \
- $(SYSTEM_INCLUDES:%=-I%) \
- $(SYSTEM_INCLUDES:%=--config-exclude=%) \
- $(SYSTEM_INCLUDES:%=--suppress=*:%/*) \
- $(SYSTEM_INCLUDES:%=--suppress=unmatchedSuppression:%/*) \
--inline-suppr \
- --suppress=unusedStructMember \
- $(filter -D%,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) \
- $(SRCS) $(HEADERS)
+ $(shell if $(CPPCHECK) --quiet --check-level=exhaustive /dev/null; then \
+ echo "--check-level=exhaustive"; \
+ else \
+ echo ""; \
+ fi) \
+ --suppress=missingIncludeSystem \
+ -D CPPCHECK_6936
+
+cppcheck: passt.cppcheck passt-repair.cppcheck pesto.cppcheck
+
+.PHONY: %.cppcheck
+%.cppcheck:
+ $(CPPCHECK) $(CPPCHECK_FLAGS) $(BASE_CPPFLAGS) $^
+
+passt.cppcheck: BASE_CPPFLAGS += -UPESTO
+passt.cppcheck: CPPCHECK_FLAGS += --suppress=unusedStructMember
+passt.cppcheck: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
+
+passt-repair.cppcheck: CPPCHECK_FLAGS += --suppress=unusedStructMember
+passt-repair.cppcheck: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
+
+pesto.cppcheck: BASE_CPPFLAGS += -DPESTO
+pesto.cppcheck: CPPCHECK_FLAGS += --suppress=unusedFunction:bitmap.c
+pesto.cppcheck: CPPCHECK_FLAGS += --suppress=unusedFunction:inany.h
+pesto.cppcheck: CPPCHECK_FLAGS += --suppress=unusedFunction:inany.c
+pesto.cppcheck: CPPCHECK_FLAGS += --suppress=unusedFunction:ip.h
+pesto.cppcheck: CPPCHECK_FLAGS += --suppress=unusedFunction:serialise.c
+pesto.cppcheck: CPPCHECK_FLAGS += --suppress=staticFunction:fwd_rule.c
+pesto.cppcheck: $(PESTO_SRCS) $(PESTO_HEADERS) seccomp_pesto.h