1# SPDX-License-Identifier: GPL-2.0 2# 3# Building vDSO images for x86. 4# 5 6# Include the generic Makefile to check the built vDSO: 7include $(srctree)/lib/vdso/Makefile.include 8 9obj-y += $(foreach x,$(vdsos-y),vdso$(x)-image.o) 10 11targets += $(foreach x,$(vdsos-y),vdso$(x)-image.c vdso$(x).so vdso$(x).so.dbg vdso$(x).lds) 12targets += $(vobjs-y) 13 14# vobjs-y with $(obj)/ prepended 15vobjs := $(addprefix $(obj)/,$(vobjs-y)) 16 17# Options for vdso*.lds 18CPPFLAGS_VDSO_LDS := -P -C -I$(src)/.. 19$(obj)/%.lds : KBUILD_CPPFLAGS += $(CPPFLAGS_VDSO_LDS) 20 21# 22# Options from KBUILD_[AC]FLAGS that should *NOT* be kept 23# 24flags-remove-y += \ 25 -D__KERNEL__ -mcmodel=kernel -mregparm=3 \ 26 -fno-pic -fno-PIC -fno-pie -fno-PIE \ 27 -mfentry -pg \ 28 $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ 29 $(RETPOLINE_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ 30 $(PADDING_CFLAGS) 31 32# 33# Don't omit frame pointers for ease of userspace debugging, but do 34# optimize sibling calls. 35# 36flags-y += -D__DISABLE_EXPORTS 37flags-y += -DDISABLE_BRANCH_PROFILING 38flags-y += -DBUILD_VDSO 39flags-y += -I$(src)/.. -I$(srctree) 40flags-y += -O2 -fpic 41flags-y += -fno-stack-protector 42flags-y += -fno-omit-frame-pointer 43flags-y += -foptimize-sibling-calls 44flags-y += -fasynchronous-unwind-tables 45 46# Reset cf protections enabled by compiler default 47flags-y += $(call cc-option, -fcf-protection=none) 48flags-$(X86_USER_SHADOW_STACK) += $(call cc-option, -fcf-protection=return) 49# When user space IBT is supported, enable this. 50# flags-$(CONFIG_USER_IBT) += $(call cc-option, -fcf-protection=branch) 51 52flags-$(CONFIG_MITIGATION_RETPOLINE) += $(RETPOLINE_VDSO_CFLAGS) 53 54# These need to be conditional on $(vobjs) as they do not apply to 55# the output vdso*-image.o files which are standard kernel objects. 56$(vobjs) : KBUILD_AFLAGS := \ 57 $(filter-out $(flags-remove-y),$(KBUILD_AFLAGS)) $(flags-y) 58$(vobjs) : KBUILD_CFLAGS := \ 59 $(filter-out $(flags-remove-y),$(KBUILD_CFLAGS)) $(flags-y) 60 61# 62# The VDSO images are built using a special linker script. 63# 64VDSO_LDFLAGS := -shared --hash-style=both --build-id=sha1 --no-undefined \ 65 $(call ld-option, --eh-frame-hdr) -Bsymbolic -z noexecstack 66 67quiet_cmd_vdso = VDSO $@ 68 cmd_vdso = $(LD) -o $@ \ 69 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$*) \ 70 -T $(filter %.lds,$^) $(filter %.o,$^) 71quiet_cmd_vdso_and_check = VDSO $@ 72 cmd_vdso_and_check = $(cmd_vdso); $(cmd_vdso_check) 73 74$(obj)/vdso%.so.dbg: $(obj)/vdso%.lds FORCE 75 $(call if_changed,vdso_and_check) 76 77$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section __ex_table 78$(obj)/%.so: $(obj)/%.so.dbg FORCE 79 $(call if_changed,objcopy) 80 81VDSO2C = $(objtree)/arch/x86/tools/vdso2c 82 83quiet_cmd_vdso2c = VDSO2C $@ 84 cmd_vdso2c = $(VDSO2C) $< $(<:%.dbg=%) $@ 85 86$(obj)/%-image.c: $(obj)/%.so.dbg $(obj)/%.so $(VDSO2C) FORCE 87 $(call if_changed,vdso2c) 88 89$(obj)/%-image.o: $(obj)/%-image.c 90