2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00
criu/Makefile

423 lines
11 KiB
Makefile
Raw Normal View History

__nmk_dir=$(CURDIR)/scripts/nmk/scripts/
export __nmk_dir
#
# No need to try to remake our Makefiles
Makefile: ;
Makefile.%: ;
scripts/%.mak: ;
$(__nmk_dir)%.mk: ;
#
# Import the build engine
include $(__nmk_dir)include.mk
include $(__nmk_dir)macro.mk
ifeq ($(origin HOSTCFLAGS), undefined)
HOSTCFLAGS := $(CFLAGS) $(USERCFLAGS)
endif
#
# Supported Architectures
ifneq ($(filter-out x86 arm aarch64 ppc64 s390 mips,$(ARCH)),)
$(error "The architecture $(ARCH) isn't supported")
endif
# The PowerPC 64 bits architecture could be big or little endian.
# They are handled in the same way.
ifeq ($(SUBARCH),ppc64)
error := $(error ppc64 big endian is not yet supported)
endif
#
# Architecture specific options.
ifeq ($(ARCH),arm)
ARMV := $(shell echo $(SUBARCH) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7')
ifeq ($(ARMV),6)
USERCFLAGS += -march=armv6
endif
ifeq ($(ARMV),7)
USERCFLAGS += -march=armv7-a
endif
ifeq ($(ARMV),8)
# Running 'setarch linux32 uname -m' returns armv8l on travis aarch64.
# This tells CRIU to handle armv8l just as armv7hf. Right now this is
# only used for compile testing. No further verification of armv8l exists.
USERCFLAGS += -march=armv7-a
ARMV := 7
endif
DEFINES := -DCONFIG_ARMV$(ARMV) -DCONFIG_VDSO_32
PROTOUFIX := y
# For simplicity - compile code in Arm mode without interwork.
# We could choose Thumb mode as default instead - but a dirty
# experiment shows that with 90Kb PIEs Thumb code doesn't save
# even one page. So, let's stick so far to Arm mode as it's more
# universal around all different Arm variations, until someone
# will find any use for Thumb mode. -dima
CFLAGS_PIE := -marm
endif
ifeq ($(ARCH),aarch64)
DEFINES := -DCONFIG_AARCH64
endif
ifeq ($(ARCH),ppc64)
LDARCH := powerpc:common64
DEFINES := -DCONFIG_PPC64 -D__SANE_USERSPACE_TYPES__
endif
ifeq ($(ARCH),x86)
LDARCH := i386:x86-64
DEFINES := -DCONFIG_X86_64
endif
ifeq ($(ARCH),mips)
DEFINES := -DCONFIG_MIPS
endif
#
# CFLAGS_PIE:
#
compel: Save thread registers before executing parasite code For dumping threads we execute parasite code before we collect the floating point registers with get_task_regs(). The following describes the code path were this is done: dump_task_threads() for (i = 0; i < item->nr_threads; i++) dump_task_thread() parasite_dump_thread_seized() compel_prepare_thread() prepare_thread() ### Get general purpose registers ### ptrace_get_regs(ctx->regs) ### parasite code is executed in thread ### compel_run_in_thread(tctl, PARASITE_CMD_DUMP_THREAD) compel_get_thread_regs() ### Get FP and VX registers ### get_task_regs() Since on s390 gcc uses floating point registers to cache general purpose without the -msoft-float option the floating point registers would have been clobbered after compel_run_in_thread(). With this patch we first save all thread registers with task_get_regs() and then call the parasite code. We introduce a new function arch_set_thread_regs() that restores the saved registers for all threads. This is necessary for criu dump --leave-running, --check-only, and error handling. Pre-dump does not require to save the registers for the threads because because only the main thread (task) is used for parsite code execution. The above changes allow us to use all register sets in the parasite code - therefore we can remove -msoft-float on s390. Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com> Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-08-10 18:04:52 +02:00
# Ensure with -fno-optimize-sibling-calls that we don't create GOT
# (Global Offset Table) relocations with gcc compilers that don't have
# commit "S/390: Fix 64 bit sibcall".
ifeq ($(ARCH),s390)
ARCH := s390
DEFINES := -DCONFIG_S390
compel: Save thread registers before executing parasite code For dumping threads we execute parasite code before we collect the floating point registers with get_task_regs(). The following describes the code path were this is done: dump_task_threads() for (i = 0; i < item->nr_threads; i++) dump_task_thread() parasite_dump_thread_seized() compel_prepare_thread() prepare_thread() ### Get general purpose registers ### ptrace_get_regs(ctx->regs) ### parasite code is executed in thread ### compel_run_in_thread(tctl, PARASITE_CMD_DUMP_THREAD) compel_get_thread_regs() ### Get FP and VX registers ### get_task_regs() Since on s390 gcc uses floating point registers to cache general purpose without the -msoft-float option the floating point registers would have been clobbered after compel_run_in_thread(). With this patch we first save all thread registers with task_get_regs() and then call the parasite code. We introduce a new function arch_set_thread_regs() that restores the saved registers for all threads. This is necessary for criu dump --leave-running, --check-only, and error handling. Pre-dump does not require to save the registers for the threads because because only the main thread (task) is used for parsite code execution. The above changes allow us to use all register sets in the parasite code - therefore we can remove -msoft-float on s390. Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com> Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-08-10 18:04:52 +02:00
CFLAGS_PIE := -fno-optimize-sibling-calls
endif
CFLAGS_PIE += -DCR_NOGLIBC
export CFLAGS_PIE
LDARCH ?= $(ARCH)
export LDARCH
export PROTOUFIX DEFINES
#
# Independent options for all tools.
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
WARNINGS := -Wall -Wformat-security -Wdeclaration-after-statement -Wstrict-prototypes
CFLAGS-GCOV := --coverage -fno-exceptions -fno-inline -fprofile-update=atomic
export CFLAGS-GCOV
ifeq ($(ARCH),mips)
WARNINGS := -rdynamic
endif
ifneq ($(GCOV),)
LDFLAGS += -lgcov
CFLAGS += $(CFLAGS-GCOV)
endif
ifeq ($(ASAN),1)
CFLAGS-ASAN := -fsanitize=address
export CFLAGS-ASAN
CFLAGS += $(CFLAGS-ASAN)
endif
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifeq ($(DEBUG),1)
DEFINES += -DCR_DEBUG
CFLAGS += -O0 -ggdb3
else
CFLAGS += -O2 -g
endif
ifeq ($(GMON),1)
CFLAGS += -pg
GMONLDOPT += -pg
export GMON GMONLDOPT
endif
AFLAGS += -D__ASSEMBLY__
CFLAGS += $(USERCFLAGS) $(WARNINGS) $(DEFINES) -iquote include/
HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS
# Default target
all: criu lib crit
.PHONY: all
#
# Version headers.
include Makefile.versions
VERSION_HEADER := criu/include/version.h
GITID_FILE := .gitid
GITID := $(shell if [ -d ".git" ]; then git describe --always; fi)
# Git repository wasn't inited in CRIU folder
ifeq ($(GITID),)
GITID := 0
else
GITID_FILE_VALUE := $(shell if [ -f '$(GITID_FILE)' ]; then if [ `cat '$(GITID_FILE)'` = $(GITID) ]; then echo y; fi; fi)
ifneq ($(GITID_FILE_VALUE),y)
.PHONY: $(GITID_FILE)
endif
endif
$(GITID_FILE):
$(call msg-gen, $@)
$(Q) echo "$(GITID)" > $(GITID_FILE)
$(VERSION_HEADER): Makefile.versions $(GITID_FILE)
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, do not edit */" > $@
$(Q) echo "#ifndef __CR_VERSION_H__" >> $@
$(Q) echo "#define __CR_VERSION_H__" >> $@
$(Q) echo "#define CRIU_VERSION \"$(CRIU_VERSION)\"" >> $@
$(Q) echo "#define CRIU_VERSION_MAJOR " $(CRIU_VERSION_MAJOR) >> $@
$(Q) echo "#define CRIU_VERSION_MINOR " $(CRIU_VERSION_MINOR) >> $@
ifneq ($(CRIU_VERSION_SUBLEVEL),)
$(Q) echo "#define CRIU_VERSION_SUBLEVEL " $(CRIU_VERSION_SUBLEVEL) >> $@
endif
ifneq ($(CRIU_VERSION_EXTRA),)
$(Q) echo "#define CRIU_VERSION_EXTRA " $(CRIU_VERSION_EXTRA) >> $@
endif
$(Q) echo "#define CRIU_GITID \"$(GITID)\"" >> $@
$(Q) echo "#endif /* __CR_VERSION_H__ */" >> $@
criu-deps += $(VERSION_HEADER)
#
# Setup proper link for asm headers in common code.
include/common/asm: include/common/arch/$(ARCH)/asm
$(call msg-gen, $@)
$(Q) ln -s ./arch/$(ARCH)/asm $@
criu-deps += include/common/asm
#
# Configure variables.
export CONFIG_HEADER := include/common/config.h
ifeq ($(filter tags etags cscope clean mrproper,$(MAKECMDGOALS)),)
include Makefile.config
else
# To clean all files, enable make/build options here
export CONFIG_COMPAT := y
page-xfer: Add TLS support with X509 certificates This commit adds Transport Layer Security (TLS) support for remote page-server connections. The following command-line options are introduced with this commit: --tls-cacert FILE Trust certificates signed only by this CA --tls-cacrl FILE CA certificate revocation list --tls-cert FILE TLS certificate --tls-key FILE TLS private key --tls Use TLS to secure remote connections The default PKI locations are: CA certificate /etc/pki/CA/cacert.pem CA revocation list /etc/pki/CA/cacrl.pem Client/server certificate /etc/pki/criu/cert.pem Client/server private key /etc/pki/criu/private/key.pem The files cacert.pem and cacrl.pem are optional. If they are not present, and not explicitly specified with a command-line option, CRIU will use only the system's trusted CAs to verify the remote peer's identity. This implies that if a CA certificate is specified using "--tls-cacert" only this CA will be used for verification. If CA certificate (cacert.pem) is not present, certificate revocation list (cacrl.pem) will be ignored. Both (client and server) sides require a private key and certificate. When the "--tls" option is specified, a TLS handshake (key exchange) will be performed immediately after the remote TCP connection has been accepted. X.509 certificates can be generated as follows: -------------------------%<------------------------- # Generate CA key and certificate echo -ne "ca\ncert_signing_key" > temp certtool --generate-privkey > cakey.pem certtool --generate-self-signed \ --template temp \ --load-privkey cakey.pem \ --outfile cacert.pem # Generate server key and certificate echo -ne "cn=$HOSTNAME\nencryption_key\nsigning_key" > temp certtool --generate-privkey > key.pem certtool --generate-certificate \ --template temp \ --load-privkey key.pem \ --load-ca-certificate cacert.pem \ --load-ca-privkey cakey.pem \ --outfile cert.pem rm temp mkdir -p /etc/pki/CA mkdir -p /etc/pki/criu/private mv cacert.pem /etc/pki/CA/ mv cert.pem /etc/pki/criu/ mv key.pem /etc/pki/criu/private -------------------------%<------------------------- Usage Example: Page-server: [src]# criu page-server -D <PATH> --port <PORT> --tls [dst]# criu dump --page-server --address <SRC> --port <PORT> \ -t <PID> -D <PATH> --tls Lazy migration: [src]# criu dump --lazy-pages --port <PORT> -t <PID> -D <PATH> --tls [dst]# criu lazy-pages --page-server --address <SRC> --port <PORT> \ -D <PATH> --tls [dst]# criu restore -D <PATH> --lazy-pages Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2019-03-31 12:05:22 +01:00
export CONFIG_GNUTLS := y
export CONFIG_HAS_LIBBPF := y
endif
#
# Protobuf images first, they are not depending
# on anything else.
$(eval $(call gen-built-in,images))
criu-deps += images/built-in.o
compel: Reshuffle the directories structure Here we rather suffle source code into directories preparing ground for future work. Basically all this files movements should end up in the following compel/ tree structure compel/ ├── arch │ ├── aarch64 │ │ ├── plugins │ │ │ └── std │ │ └── src │ │ └── lib │ ├── arm ... │ ├── ppc64 ... │ └── x86 ... This is architectural part, where each arch consists of plugins/, and src/. src/ stands for code needed by compel cli + lib ├── include │ ├── compiler.h -> ../../criu/include/compiler.h │ ├── elf32-types.h │ ├── elf64-types.h │ ├── int.h -> ../../criu/include/asm-generic/int.h │ ├── piegen.h │ ├── shmem.h │ └── uapi │ ├── compel.h │ └── plugins.h Common includes + uapi ├── plugins │ ├── fds │ ├── shmem │ └── std Plugins source code └── src ├── lib │ ├── handle-elf-32.c -> handle-elf.c │ ├── handle-elf-32-host.c -> handle-elf-32.c │ ├── handle-elf.c │ └── handle-elf-host.c -> handle-elf.c compel library ├── main.c ├── main-host.c -> main.c compel cli └── shared └── fds.c shared code between plugins and compel cli Note: cross-compile won't work for a while. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2016-09-21 23:54:18 +03:00
#
# Compel get used by CRIU, build it earlier
compel: Reshuffle the directories structure Here we rather suffle source code into directories preparing ground for future work. Basically all this files movements should end up in the following compel/ tree structure compel/ ├── arch │ ├── aarch64 │ │ ├── plugins │ │ │ └── std │ │ └── src │ │ └── lib │ ├── arm ... │ ├── ppc64 ... │ └── x86 ... This is architectural part, where each arch consists of plugins/, and src/. src/ stands for code needed by compel cli + lib ├── include │ ├── compiler.h -> ../../criu/include/compiler.h │ ├── elf32-types.h │ ├── elf64-types.h │ ├── int.h -> ../../criu/include/asm-generic/int.h │ ├── piegen.h │ ├── shmem.h │ └── uapi │ ├── compel.h │ └── plugins.h Common includes + uapi ├── plugins │ ├── fds │ ├── shmem │ └── std Plugins source code └── src ├── lib │ ├── handle-elf-32.c -> handle-elf.c │ ├── handle-elf-32-host.c -> handle-elf-32.c │ ├── handle-elf.c │ └── handle-elf-host.c -> handle-elf.c compel library ├── main.c ├── main-host.c -> main.c compel cli └── shared └── fds.c shared code between plugins and compel cli Note: cross-compile won't work for a while. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2016-09-21 23:54:18 +03:00
include Makefile.compel
#
# Next the socket CR library
#
SOCCR_A := soccr/libsoccr.a
soccr/Makefile: ;
soccr/%: $(CONFIG_HEADER) .FORCE
$(Q) $(MAKE) $(build)=soccr $@
soccr/built-in.o: $(CONFIG_HEADER) .FORCE
$(Q) $(MAKE) $(build)=soccr all
$(SOCCR_A): |soccr/built-in.o
criu-deps += $(SOCCR_A)
#
# CRIU building done in own directory
# with slightly different rules so we
# can't use nmk engine directly (we
# build syscalls library and such).
#
# But note that we're already included
# the nmk so we can reuse it there.
criu/Makefile: ;
criu/Makefile.packages: ;
criu/Makefile.crtools: ;
criu/%: $(criu-deps) .FORCE
$(Q) $(MAKE) $(build)=criu $@
criu: $(criu-deps)
$(Q) $(MAKE) $(build)=criu all
.PHONY: criu
crit/Makefile: ;
crit/%: criu .FORCE
$(Q) $(MAKE) $(build)=crit $@
crit: criu
$(Q) $(MAKE) $(build)=crit all
.PHONY: crit
#
# Libraries next once crit it ready
# (we might generate headers and such
# when building criu itself).
lib/Makefile: ;
lib/%: crit .FORCE
$(Q) $(MAKE) $(build)=lib $@
lib: crit
$(Q) $(MAKE) $(build)=lib all
.PHONY: lib
clean mrproper:
$(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=soccr $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
.PHONY: clean mrproper
clean-top:
$(Q) $(MAKE) -C Documentation clean
$(Q) $(MAKE) $(build)=test/compel clean
$(Q) $(RM) .gitid
.PHONY: clean-top
clean: clean-top
mrproper-top: clean-top
$(Q) $(RM) $(CONFIG_HEADER)
$(Q) $(RM) $(VERSION_HEADER)
compel: Reshuffle the directories structure Here we rather suffle source code into directories preparing ground for future work. Basically all this files movements should end up in the following compel/ tree structure compel/ ├── arch │ ├── aarch64 │ │ ├── plugins │ │ │ └── std │ │ └── src │ │ └── lib │ ├── arm ... │ ├── ppc64 ... │ └── x86 ... This is architectural part, where each arch consists of plugins/, and src/. src/ stands for code needed by compel cli + lib ├── include │ ├── compiler.h -> ../../criu/include/compiler.h │ ├── elf32-types.h │ ├── elf64-types.h │ ├── int.h -> ../../criu/include/asm-generic/int.h │ ├── piegen.h │ ├── shmem.h │ └── uapi │ ├── compel.h │ └── plugins.h Common includes + uapi ├── plugins │ ├── fds │ ├── shmem │ └── std Plugins source code └── src ├── lib │ ├── handle-elf-32.c -> handle-elf.c │ ├── handle-elf-32-host.c -> handle-elf-32.c │ ├── handle-elf.c │ └── handle-elf-host.c -> handle-elf.c compel library ├── main.c ├── main-host.c -> main.c compel cli └── shared └── fds.c shared code between plugins and compel cli Note: cross-compile won't work for a while. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2016-09-21 23:54:18 +03:00
$(Q) $(RM) $(COMPEL_VERSION_HEADER)
$(Q) $(RM) include/common/asm
$(Q) $(RM) compel/include/asm
$(Q) $(RM) cscope.*
$(Q) $(RM) tags TAGS
.PHONY: mrproper-top
mrproper: mrproper-top
#
# Non-CRIU stuff.
#
docs:
$(Q) $(MAKE) -s -C Documentation all
.PHONY: docs
zdtm: all
$(Q) $(MAKE) -C test/zdtm all
.PHONY: zdtm
test: zdtm
$(Q) $(MAKE) -C test
.PHONY: test
#
# Generating tar requires tag matched CRIU_VERSION.
# If not found then simply use GIT's describe with
# "v" prefix stripped.
head-name := $(shell git tag -l v$(CRIU_VERSION))
ifeq ($(head-name),)
head-name := $(shell git describe 2>/dev/null)
endif
# If no git tag could describe current commit,
# use pre-defined CRIU_VERSION with GITID (if any).
ifeq ($(head-name),)
ifneq ($(GITID),)
head-name := $(CRIU_VERSION)-$(GITID)
else
head-name := $(CRIU_VERSION)
endif
endif
tar-name := $(shell echo $(head-name) | sed -e 's/^v//g')
criu-$(tar-name).tar.bz2:
git archive --format tar --prefix 'criu-$(tar-name)/' $(head-name) | bzip2 > $@
dist tar: criu-$(tar-name).tar.bz2 ;
.PHONY: dist tar
TAGS_FILES_REGEXP := . -name '*.[hcS]' ! -path './.*' \( ! -path './test/*' -o -path './test/zdtm/lib/*' \)
tags:
$(call msg-gen, $@)
$(Q) $(RM) tags
$(Q) $(FIND) $(TAGS_FILES_REGEXP) -print | xargs $(CTAGS) -a
.PHONY: tags
etags:
$(call msg-gen, $@)
$(Q) $(RM) TAGS
$(Q) $(FIND) $(TAGS_FILES_REGEXP) -print | xargs $(ETAGS) -a
.PHONY: etags
cscope:
$(call msg-gen, $@)
$(Q) $(FIND) $(TAGS_FILES_REGEXP) ! -type l -print > cscope.files
$(Q) $(CSCOPE) -bkqu
.PHONY: cscope
gcov:
$(E) " GCOV"
$(Q) test -d gcov || mkdir gcov && \
geninfo --output-filename gcov/criu.info --no-recursion criu/ && \
cd gcov && \
genhtml --rc lcov_branch_coverage=1 --output-directory html criu.info
@echo "Code coverage report is in `pwd`/gcov/html/ directory."
.PHONY: gcov
docker-build:
$(MAKE) -C scripts/build/ x86_64
.PHONY: docker-build
docker-test:
docker run --rm -it --privileged -v /lib/modules:/lib/modules --network=host --cgroupns=host criu-x86_64 \
./test/zdtm.py run -a -x tcp6 -x tcpbuf6 -x static/rtc -x cgroup
.PHONY: docker-test
help:
@echo ' Targets:'
@echo ' all - Build all [*] targets'
@echo ' * criu - Build criu'
@echo ' zdtm - Build zdtm test-suite'
@echo ' docs - Build documentation'
@echo ' install - Install CRIU (see INSTALL.md)'
@echo ' uninstall - Uninstall CRIU'
@echo ' dist - Create a source tarball'
@echo ' clean - Clean most, but leave enough to navigate'
@echo ' mrproper - Delete all compiled/generated files'
@echo ' tags - Generate tags file (ctags)'
@echo ' etags - Generate TAGS file (etags)'
@echo ' cscope - Generate cscope database'
@echo ' test - Run zdtm test-suite'
@echo ' gcov - Make code coverage report'
.PHONY: help
lint:
flake8 --version
flake8 --config=scripts/flake8.cfg test/zdtm.py
flake8 --config=scripts/flake8.cfg test/inhfd/*.py
flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py
flake8 --config=scripts/flake8.cfg lib/py/images/pb2dict.py
shellcheck scripts/*.sh
shellcheck scripts/ci/*.sh scripts/ci/apt-install
shellcheck test/others/crit/*.sh
codecov: SHELL := $(shell which bash)
codecov:
bash <(curl -s https://codecov.io/bash)
.PHONY: codecov
include Makefile.install
.DEFAULT_GOAL := all
# Disable implicit rules in _this_ Makefile.
.SUFFIXES:
#
# Optional local include.
-include Makefile.local