1# SPDX-License-Identifier: GPL-2.0 2# 3# Building vDSO images for x86. 4# 5 6# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before 7# the inclusion of generic Makefile. 8ARCH_REL_TYPE_ABS := R_X86_64_JUMP_SLOT|R_X86_64_GLOB_DAT|R_X86_64_RELATIVE| 9ARCH_REL_TYPE_ABS += R_386_GLOB_DAT|R_386_JMP_SLOT|R_386_RELATIVE 10include $(srctree)/lib/vdso/Makefile 11 12KBUILD_CFLAGS += $(DISABLE_LTO) 13 14# Sanitizer runtimes are unavailable and cannot be linked here. 15KASAN_SANITIZE := n 16UBSAN_SANITIZE := n 17KCSAN_SANITIZE := n 18OBJECT_FILES_NON_STANDARD := y 19 20# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. 21KCOV_INSTRUMENT := n 22 23VDSO64-$(CONFIG_X86_64) := y 24VDSOX32-$(CONFIG_X86_X32_ABI) := y 25VDSO32-$(CONFIG_X86_32) := y 26VDSO32-$(CONFIG_IA32_EMULATION) := y 27 28# files to link into the vdso 29vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o 30 31# files to link into kernel 32obj-y += vma.o 33OBJECT_FILES_NON_STANDARD_vma.o := n 34 35# vDSO images to build 36vdso_img-$(VDSO64-y) += 64 37vdso_img-$(VDSOX32-y) += x32 38vdso_img-$(VDSO32-y) += 32 39 40obj-$(VDSO32-y) += vdso32-setup.o 41 42vobjs := $(foreach F,$(vobjs-y),$(obj)/$F) 43 44$(obj)/vdso.o: $(obj)/vdso.so 45 46targets += vdso.lds $(vobjs-y) 47 48# Build the vDSO image C files and link them in. 49vdso_img_objs := $(vdso_img-y:%=vdso-image-%.o) 50vdso_img_cfiles := $(vdso_img-y:%=vdso-image-%.c) 51vdso_img_sodbg := $(vdso_img-y:%=vdso%.so.dbg) 52obj-y += $(vdso_img_objs) 53targets += $(vdso_img_cfiles) 54targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so) 55 56CPPFLAGS_vdso.lds += -P -C 57 58VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \ 59 -z max-page-size=4096 60 61$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE 62 $(call if_changed,vdso_and_check) 63 64HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi 65hostprogs-y += vdso2c 66 67quiet_cmd_vdso2c = VDSO2C $@ 68 cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@ 69 70$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE 71 $(call if_changed,vdso2c) 72 73# 74# Don't omit frame pointers for ease of userspace debugging, but do 75# optimize sibling calls. 76# 77CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ 78 $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ 79 -fno-omit-frame-pointer -foptimize-sibling-calls \ 80 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 81 82ifdef CONFIG_RETPOLINE 83ifneq ($(RETPOLINE_VDSO_CFLAGS),) 84 CFL += $(RETPOLINE_VDSO_CFLAGS) 85endif 86endif 87 88$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) 89 90# 91# vDSO code runs in userspace and -pg doesn't help with profiling anyway. 92# 93CFLAGS_REMOVE_vdso-note.o = -pg 94CFLAGS_REMOVE_vclock_gettime.o = -pg 95CFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg 96CFLAGS_REMOVE_vgetcpu.o = -pg 97CFLAGS_REMOVE_vvar.o = -pg 98 99# 100# X32 processes use x32 vDSO to access 64bit kernel data. 101# 102# Build x32 vDSO image: 103# 1. Compile x32 vDSO as 64bit. 104# 2. Convert object files to x32. 105# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes 106# so that it can reach 64bit address space with 64bit pointers. 107# 108 109CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds) 110VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \ 111 -z max-page-size=4096 112 113# x32-rebranded versions 114vobjx32s-y := $(vobjs-y:.o=-x32.o) 115 116# same thing, but in the output directory 117vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F) 118 119# Convert 64bit object file to x32 for x32 vDSO. 120quiet_cmd_x32 = X32 $@ 121 cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@ 122 123$(obj)/%-x32.o: $(obj)/%.o FORCE 124 $(call if_changed,x32) 125 126targets += vdsox32.lds $(vobjx32s-y) 127 128$(obj)/%.so: OBJCOPYFLAGS := -S 129$(obj)/%.so: $(obj)/%.so.dbg FORCE 130 $(call if_changed,objcopy) 131 132$(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE 133 $(call if_changed,vdso_and_check) 134 135CPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds) 136VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1 137 138targets += vdso32/vdso32.lds 139targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o 140targets += vdso32/vclock_gettime.o 141 142KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO 143$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) 144$(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32 145 146KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) 147KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) 148KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) 149KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) 150KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) 151KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) 152KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic 153KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) 154KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) 155KBUILD_CFLAGS_32 += -fno-omit-frame-pointer 156KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING 157 158ifdef CONFIG_RETPOLINE 159ifneq ($(RETPOLINE_VDSO_CFLAGS),) 160 KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS) 161endif 162endif 163 164$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) 165 166$(obj)/vdso32.so.dbg: FORCE \ 167 $(obj)/vdso32/vdso32.lds \ 168 $(obj)/vdso32/vclock_gettime.o \ 169 $(obj)/vdso32/note.o \ 170 $(obj)/vdso32/system_call.o \ 171 $(obj)/vdso32/sigreturn.o 172 $(call if_changed,vdso_and_check) 173 174# 175# The DSO images are built using a special linker script. 176# 177quiet_cmd_vdso = VDSO $@ 178 cmd_vdso = $(LD) -nostdlib -o $@ \ 179 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ 180 -T $(filter %.lds,$^) $(filter %.o,$^) && \ 181 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' 182 183VDSO_LDFLAGS = -shared --hash-style=both --build-id \ 184 $(call ld-option, --eh-frame-hdr) -Bsymbolic 185GCOV_PROFILE := n 186 187quiet_cmd_vdso_and_check = VDSO $@ 188 cmd_vdso_and_check = $(cmd_vdso); $(cmd_vdso_check) 189 190# 191# Install the unstripped copies of vdso*.so. If our toolchain supports 192# build-id, install .build-id links as well. 193# 194quiet_cmd_vdso_install = INSTALL $(@:install_%=%) 195define cmd_vdso_install 196 cp $< "$(MODLIB)/vdso/$(@:install_%=%)"; \ 197 if readelf -n $< |grep -q 'Build ID'; then \ 198 buildid=`readelf -n $< |grep 'Build ID' |sed -e 's/^.*Build ID: \(.*\)$$/\1/'`; \ 199 first=`echo $$buildid | cut -b-2`; \ 200 last=`echo $$buildid | cut -b3-`; \ 201 mkdir -p "$(MODLIB)/vdso/.build-id/$$first"; \ 202 ln -sf "../../$(@:install_%=%)" "$(MODLIB)/vdso/.build-id/$$first/$$last.debug"; \ 203 fi 204endef 205 206vdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%) 207 208$(MODLIB)/vdso: FORCE 209 @mkdir -p $(MODLIB)/vdso 210 211$(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso 212 $(call cmd,vdso_install) 213 214PHONY += vdso_install $(vdso_img_insttargets) 215vdso_install: $(vdso_img_insttargets) 216 217clean-files := vdso32.so vdso32.so.dbg vdso64* vdso-image-*.c vdsox32.so* 218