criu/compel/plugins/Makefile
Kir Kolyshkin 1fe09eb358 Makefiles: move -Wa,--noexecstack out of CFLAGS
The problem is, -Wa is a flag for assembler, but CFLAGS are also used
to generate dependencies, and clang complains loudly when it is used
for deps:

> >   DEP      compel/arch/x86/plugins/std/syscalls-64.d
> >  clang-3.8: error: argument unused during compilation:
> > '-Wa,--noexecstack'

This patch moved the noexecflag from assembler to linker. I am not
100% sure but the end result seems to be the same.

This fixes dependency generation when using clang instead of gcc.

I surely have done my research before proposing this change, and
I have tested this change as good as I could.
Sorry, I should have provided more background in the commit message.
Here it goes.

There are a few ways to have non-executable stack:
1. mark the assembler source file (.S) with .section
.note.GNU-stack,"",%progbits
2. pass the -Wa,--noexecstack to compiler
3. pass the -z execstack to linker

All three ways are fine, let's see them in greater details.

Some people say (1) is the best way, but we have way too many
.S files now (23 of them, to be exact). Anyway, I can certainly do it
this way if you like, just let me know. It would look like this:

    --- a/compel/arch/aarch64/plugins/std/syscalls/syscall-aux.S
    +++ b/compel/arch/aarch64/plugins/std/syscalls/syscall-aux.S
    @@ -3,6 +3,8 @@
     * that are not implemented in the AArch64 Linux kernel
     */

    +.section .note.GNU-stack,"",%progbits
    +
     ENTRY(sys_open)
     mov x3, x2
     mov x2, x1

Way (2) is what is currently used. Unfortunately it breaks dependency
generation with clang. One way to fix it would be to filter-out the bad
flag when we're generating deps. I tried experimenting with
$(filter-out) function in Makefiles today but it's complicated and I failed
to make it work.

Way (3) is what this commit offers. It seem to work fine while being
the least intrusive.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 00:05:55 +03:00

59 lines
1.5 KiB
Makefile

.PHONY: .FORCE
CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
PLUGIN_ARCH_DIR := compel/arch/$(ARCH)/plugins
#
# CFLAGS, ASFLAGS, LDFLAGS
# General compel includes
ccflags-y += -iquote $(SRC_DIR)/compel/include
ccflags-y += -fno-stack-protector
# General compel/plugins includes
ccflags-y += -iquote $(obj)/include
ccflags-y += -iquote $(obj)/include/uapi
asflags-y += -iquote $(obj)/include
asflags-y += -iquote $(obj)/include/uapi
# Arch compel/plugins includes
ccflags-y += -iquote $(PLUGIN_ARCH_DIR)/include
asflags-y += -iquote $(PLUGIN_ARCH_DIR)/include
asflags-y += -iquote $(PLUGIN_ARCH_DIR)
# General flags for assembly
asflags-y += -fpie -Wstrict-prototypes
asflags-y += -D__ASSEMBLY__ -nostdlib -fomit-frame-pointer
asflags-y += -fno-stack-protector
ldflags-y += -z noexecstack
#
# Fds plugin
target += fds
fds-obj-y += fds/fds.o
#
# Shmem plugin
target += shmem
shmem-obj-y += shmem/shmem.o
#
# STD plugin
target += std
std-obj-y += std/std.o
std-obj-y += std/string.o
include ./$(PLUGIN_ARCH_DIR)/std/syscalls/Makefile.syscalls
define syscall-priority
$(addprefix $(obj)/,$($(1):%.o=%.d)): | $($(2))
$(addprefix $(obj)/,$($(1):%.o=%.i)): | $($(2))
$(addprefix $(obj)/,$($(1):%.o=%.s)): | $($(2))
$(addprefix $(obj)/,$($(1))): | $($(2))
endef
#
# Almost all plugins depen on syscall headers
# and definitions so we have to order their
# generation manually.
$(foreach t,$(target),$(eval $(call syscall-priority,$(t)-obj-y,std-headers-deps)))