18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci# 38c2ecf20Sopenharmony_ci# Building vDSO images for x86. 48c2ecf20Sopenharmony_ci# 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before 78c2ecf20Sopenharmony_ci# the inclusion of generic Makefile. 88c2ecf20Sopenharmony_ciARCH_REL_TYPE_ABS := R_X86_64_JUMP_SLOT|R_X86_64_GLOB_DAT|R_X86_64_RELATIVE| 98c2ecf20Sopenharmony_ciARCH_REL_TYPE_ABS += R_386_GLOB_DAT|R_386_JMP_SLOT|R_386_RELATIVE 108c2ecf20Sopenharmony_ciinclude $(srctree)/lib/vdso/Makefile 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci# Sanitizer runtimes are unavailable and cannot be linked here. 138c2ecf20Sopenharmony_ciKASAN_SANITIZE := n 148c2ecf20Sopenharmony_ciUBSAN_SANITIZE := n 158c2ecf20Sopenharmony_ciKCSAN_SANITIZE := n 168c2ecf20Sopenharmony_ciOBJECT_FILES_NON_STANDARD := y 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. 198c2ecf20Sopenharmony_ciKCOV_INSTRUMENT := n 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciVDSO64-$(CONFIG_X86_64) := y 228c2ecf20Sopenharmony_ciVDSOX32-$(CONFIG_X86_X32_ABI) := y 238c2ecf20Sopenharmony_ciVDSO32-$(CONFIG_X86_32) := y 248c2ecf20Sopenharmony_ciVDSO32-$(CONFIG_IA32_EMULATION) := y 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci# files to link into the vdso 278c2ecf20Sopenharmony_civobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o 288c2ecf20Sopenharmony_civobjs32-y := vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o 298c2ecf20Sopenharmony_civobjs32-y += vdso32/vclock_gettime.o 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci# files to link into kernel 328c2ecf20Sopenharmony_ciobj-y += vma.o 338c2ecf20Sopenharmony_ciKASAN_SANITIZE_vma.o := y 348c2ecf20Sopenharmony_ciUBSAN_SANITIZE_vma.o := y 358c2ecf20Sopenharmony_ciKCSAN_SANITIZE_vma.o := y 368c2ecf20Sopenharmony_ciOBJECT_FILES_NON_STANDARD_vma.o := n 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci# vDSO images to build 398c2ecf20Sopenharmony_civdso_img-$(VDSO64-y) += 64 408c2ecf20Sopenharmony_civdso_img-$(VDSOX32-y) += x32 418c2ecf20Sopenharmony_civdso_img-$(VDSO32-y) += 32 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciobj-$(VDSO32-y) += vdso32-setup.o 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_civobjs := $(foreach F,$(vobjs-y),$(obj)/$F) 468c2ecf20Sopenharmony_civobjs32 := $(foreach F,$(vobjs32-y),$(obj)/$F) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci$(obj)/vdso.o: $(obj)/vdso.so 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_citargets += vdso.lds $(vobjs-y) 518c2ecf20Sopenharmony_citargets += vdso32/vdso32.lds $(vobjs32-y) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci# Build the vDSO image C files and link them in. 548c2ecf20Sopenharmony_civdso_img_objs := $(vdso_img-y:%=vdso-image-%.o) 558c2ecf20Sopenharmony_civdso_img_cfiles := $(vdso_img-y:%=vdso-image-%.c) 568c2ecf20Sopenharmony_civdso_img_sodbg := $(vdso_img-y:%=vdso%.so.dbg) 578c2ecf20Sopenharmony_ciobj-y += $(vdso_img_objs) 588c2ecf20Sopenharmony_citargets += $(vdso_img_cfiles) 598c2ecf20Sopenharmony_citargets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciCPPFLAGS_vdso.lds += -P -C 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciVDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \ 648c2ecf20Sopenharmony_ci -z max-page-size=4096 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE 678c2ecf20Sopenharmony_ci $(call if_changed,vdso_and_check) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciHOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi 708c2ecf20Sopenharmony_cihostprogs += vdso2c 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciquiet_cmd_vdso2c = VDSO2C $@ 738c2ecf20Sopenharmony_ci cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@ 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE 768c2ecf20Sopenharmony_ci $(call if_changed,vdso2c) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci# 798c2ecf20Sopenharmony_ci# Don't omit frame pointers for ease of userspace debugging, but do 808c2ecf20Sopenharmony_ci# optimize sibling calls. 818c2ecf20Sopenharmony_ci# 828c2ecf20Sopenharmony_ciCFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ 838c2ecf20Sopenharmony_ci $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ 848c2ecf20Sopenharmony_ci -fno-omit-frame-pointer -foptimize-sibling-calls \ 858c2ecf20Sopenharmony_ci -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciifdef CONFIG_RETPOLINE 888c2ecf20Sopenharmony_ciifneq ($(RETPOLINE_VDSO_CFLAGS),) 898c2ecf20Sopenharmony_ci CFL += $(RETPOLINE_VDSO_CFLAGS) 908c2ecf20Sopenharmony_ciendif 918c2ecf20Sopenharmony_ciendif 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) 948c2ecf20Sopenharmony_ci$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci# 978c2ecf20Sopenharmony_ci# vDSO code runs in userspace and -pg doesn't help with profiling anyway. 988c2ecf20Sopenharmony_ci# 998c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vclock_gettime.o = -pg 1008c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg 1018c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vgetcpu.o = -pg 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci# 1048c2ecf20Sopenharmony_ci# X32 processes use x32 vDSO to access 64bit kernel data. 1058c2ecf20Sopenharmony_ci# 1068c2ecf20Sopenharmony_ci# Build x32 vDSO image: 1078c2ecf20Sopenharmony_ci# 1. Compile x32 vDSO as 64bit. 1088c2ecf20Sopenharmony_ci# 2. Convert object files to x32. 1098c2ecf20Sopenharmony_ci# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes 1108c2ecf20Sopenharmony_ci# so that it can reach 64bit address space with 64bit pointers. 1118c2ecf20Sopenharmony_ci# 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciCPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds) 1148c2ecf20Sopenharmony_ciVDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \ 1158c2ecf20Sopenharmony_ci -z max-page-size=4096 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci# x32-rebranded versions 1188c2ecf20Sopenharmony_civobjx32s-y := $(vobjs-y:.o=-x32.o) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci# same thing, but in the output directory 1218c2ecf20Sopenharmony_civobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci# Convert 64bit object file to x32 for x32 vDSO. 1248c2ecf20Sopenharmony_ciquiet_cmd_x32 = X32 $@ 1258c2ecf20Sopenharmony_ci cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@ 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci$(obj)/%-x32.o: $(obj)/%.o FORCE 1288c2ecf20Sopenharmony_ci $(call if_changed,x32) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_citargets += vdsox32.lds $(vobjx32s-y) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci$(obj)/%.so: OBJCOPYFLAGS := -S 1338c2ecf20Sopenharmony_ci$(obj)/%.so: $(obj)/%.so.dbg FORCE 1348c2ecf20Sopenharmony_ci $(call if_changed,objcopy) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci$(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE 1378c2ecf20Sopenharmony_ci $(call if_changed,vdso_and_check) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ciCPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds) 1408c2ecf20Sopenharmony_ciVDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ciKBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO 1438c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) 1448c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) 1478c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) 1488c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) 1498c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) 1508c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) 1518c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) 1528c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic 1538c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -fno-stack-protector 1548c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) 1558c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -fno-omit-frame-pointer 1568c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ciifdef CONFIG_RETPOLINE 1598c2ecf20Sopenharmony_ciifneq ($(RETPOLINE_VDSO_CFLAGS),) 1608c2ecf20Sopenharmony_ci KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS) 1618c2ecf20Sopenharmony_ciendif 1628c2ecf20Sopenharmony_ciendif 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE 1678c2ecf20Sopenharmony_ci $(call if_changed,vdso_and_check) 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci# 1708c2ecf20Sopenharmony_ci# The DSO images are built using a special linker script. 1718c2ecf20Sopenharmony_ci# 1728c2ecf20Sopenharmony_ciquiet_cmd_vdso = VDSO $@ 1738c2ecf20Sopenharmony_ci cmd_vdso = $(LD) -nostdlib -o $@ \ 1748c2ecf20Sopenharmony_ci $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ 1758c2ecf20Sopenharmony_ci -T $(filter %.lds,$^) $(filter %.o,$^) && \ 1768c2ecf20Sopenharmony_ci sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ciVDSO_LDFLAGS = -shared --hash-style=both --build-id=sha1 \ 1798c2ecf20Sopenharmony_ci $(call ld-option, --eh-frame-hdr) -Bsymbolic -z noexecstack 1808c2ecf20Sopenharmony_ciGCOV_PROFILE := n 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ciquiet_cmd_vdso_and_check = VDSO $@ 1838c2ecf20Sopenharmony_ci cmd_vdso_and_check = $(cmd_vdso); $(cmd_vdso_check) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci# 1868c2ecf20Sopenharmony_ci# Install the unstripped copies of vdso*.so. If our toolchain supports 1878c2ecf20Sopenharmony_ci# build-id, install .build-id links as well. 1888c2ecf20Sopenharmony_ci# 1898c2ecf20Sopenharmony_ciquiet_cmd_vdso_install = INSTALL $(@:install_%=%) 1908c2ecf20Sopenharmony_cidefine cmd_vdso_install 1918c2ecf20Sopenharmony_ci cp $< "$(MODLIB)/vdso/$(@:install_%=%)"; \ 1928c2ecf20Sopenharmony_ci if readelf -n $< |grep -q 'Build ID'; then \ 1938c2ecf20Sopenharmony_ci buildid=`readelf -n $< |grep 'Build ID' |sed -e 's/^.*Build ID: \(.*\)$$/\1/'`; \ 1948c2ecf20Sopenharmony_ci first=`echo $$buildid | cut -b-2`; \ 1958c2ecf20Sopenharmony_ci last=`echo $$buildid | cut -b3-`; \ 1968c2ecf20Sopenharmony_ci mkdir -p "$(MODLIB)/vdso/.build-id/$$first"; \ 1978c2ecf20Sopenharmony_ci ln -sf "../../$(@:install_%=%)" "$(MODLIB)/vdso/.build-id/$$first/$$last.debug"; \ 1988c2ecf20Sopenharmony_ci fi 1998c2ecf20Sopenharmony_ciendef 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_civdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci$(MODLIB)/vdso: FORCE 2048c2ecf20Sopenharmony_ci @mkdir -p $(MODLIB)/vdso 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci$(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso 2078c2ecf20Sopenharmony_ci $(call cmd,vdso_install) 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ciPHONY += vdso_install $(vdso_img_insttargets) 2108c2ecf20Sopenharmony_civdso_install: $(vdso_img_insttargets) 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ciclean-files := vdso32.so vdso32.so.dbg vdso64* vdso-image-*.c vdsox32.so* 213