18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci#
38c2ecf20Sopenharmony_ci# Building vDSO images for sparc.
48c2ecf20Sopenharmony_ci#
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciVDSO64-$(CONFIG_SPARC64)	:= y
78c2ecf20Sopenharmony_ciVDSOCOMPAT-$(CONFIG_COMPAT)	:= y
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci# files to link into the vdso
108c2ecf20Sopenharmony_civobjs-y := vdso-note.o vclock_gettime.o
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci# files to link into kernel
138c2ecf20Sopenharmony_ciobj-y				+= vma.o
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci# vDSO images to build
168c2ecf20Sopenharmony_civdso_img-$(VDSO64-y)		+= 64
178c2ecf20Sopenharmony_civdso_img-$(VDSOCOMPAT-y)	+= 32
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_civobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci$(obj)/vdso.o: $(obj)/vdso.so
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_citargets += vdso.lds $(vobjs-y)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci# Build the vDSO image C files and link them in.
268c2ecf20Sopenharmony_civdso_img_objs := $(vdso_img-y:%=vdso-image-%.o)
278c2ecf20Sopenharmony_civdso_img_cfiles := $(vdso_img-y:%=vdso-image-%.c)
288c2ecf20Sopenharmony_civdso_img_sodbg := $(vdso_img-y:%=vdso%.so.dbg)
298c2ecf20Sopenharmony_ciobj-y += $(vdso_img_objs)
308c2ecf20Sopenharmony_citargets += $(vdso_img_cfiles)
318c2ecf20Sopenharmony_citargets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciCPPFLAGS_vdso.lds += -P -C
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciVDSO_LDFLAGS_vdso.lds = -m elf64_sparc -soname linux-vdso.so.1 --no-undefined \
368c2ecf20Sopenharmony_ci			-z max-page-size=8192
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
398c2ecf20Sopenharmony_ci	$(call if_changed,vdso)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciHOST_EXTRACFLAGS += -I$(srctree)/tools/include
428c2ecf20Sopenharmony_cihostprogs += vdso2c
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciquiet_cmd_vdso2c = VDSO2C  $@
458c2ecf20Sopenharmony_ci      cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
488c2ecf20Sopenharmony_ci	$(call if_changed,vdso2c)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#
518c2ecf20Sopenharmony_ci# Don't omit frame pointers for ease of userspace debugging, but do
528c2ecf20Sopenharmony_ci# optimize sibling calls.
538c2ecf20Sopenharmony_ci#
548c2ecf20Sopenharmony_ciCFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \
558c2ecf20Sopenharmony_ci       $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
568c2ecf20Sopenharmony_ci       -fno-omit-frame-pointer -foptimize-sibling-calls \
578c2ecf20Sopenharmony_ci       -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciSPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#
648c2ecf20Sopenharmony_ci# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
658c2ecf20Sopenharmony_ci#
668c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vclock_gettime.o = -pg
678c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci$(obj)/%.so: OBJCOPYFLAGS := -S
708c2ecf20Sopenharmony_ci$(obj)/%.so: $(obj)/%.so.dbg FORCE
718c2ecf20Sopenharmony_ci	$(call if_changed,objcopy)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciCPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds)
748c2ecf20Sopenharmony_ciVDSO_LDFLAGS_vdso32.lds = -m elf32_sparc -soname linux-gate.so.1
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#This makes sure the $(obj) subdirectory exists even though vdso32/
778c2ecf20Sopenharmony_ci#is not a kbuild sub-make subdirectory
788c2ecf20Sopenharmony_cioverride obj-dirs = $(dir $(obj)) $(obj)/vdso32/
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_citargets += vdso32/vdso32.lds
818c2ecf20Sopenharmony_citargets += vdso32/vdso-note.o
828c2ecf20Sopenharmony_citargets += vdso32/vclock_gettime.o
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciKBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO
858c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
868c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: asflags-$(CONFIG_SPARC64) += -m32
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
898c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -mcmodel=medlow,$(KBUILD_CFLAGS_32))
908c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
918c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
928c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32))
938c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -m32 -msoft-float -fpic
948c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -fno-stack-protector
958c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
968c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -fno-omit-frame-pointer
978c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
988c2ecf20Sopenharmony_ciKBUILD_CFLAGS_32 += -mv8plus
998c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci$(obj)/vdso32.so.dbg: FORCE \
1028c2ecf20Sopenharmony_ci			$(obj)/vdso32/vdso32.lds \
1038c2ecf20Sopenharmony_ci			$(obj)/vdso32/vclock_gettime.o \
1048c2ecf20Sopenharmony_ci			$(obj)/vdso32/vdso-note.o
1058c2ecf20Sopenharmony_ci		$(call	if_changed,vdso)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#
1088c2ecf20Sopenharmony_ci# The DSO images are built using a special linker script.
1098c2ecf20Sopenharmony_ci#
1108c2ecf20Sopenharmony_ciquiet_cmd_vdso = VDSO    $@
1118c2ecf20Sopenharmony_ci      cmd_vdso = $(LD) -nostdlib -o $@ \
1128c2ecf20Sopenharmony_ci		       $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
1138c2ecf20Sopenharmony_ci		       -T $(filter %.lds,$^) $(filter %.o,$^) && \
1148c2ecf20Sopenharmony_ci		sh $(srctree)/$(src)/checkundef.sh '$(OBJDUMP)' '$@'
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ciVDSO_LDFLAGS = -shared --hash-style=both --build-id=sha1 -Bsymbolic
1178c2ecf20Sopenharmony_ciGCOV_PROFILE := n
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#
1208c2ecf20Sopenharmony_ci# Install the unstripped copies of vdso*.so.  If our toolchain supports
1218c2ecf20Sopenharmony_ci# build-id, install .build-id links as well.
1228c2ecf20Sopenharmony_ci#
1238c2ecf20Sopenharmony_ciquiet_cmd_vdso_install = INSTALL $(@:install_%=%)
1248c2ecf20Sopenharmony_cidefine cmd_vdso_install
1258c2ecf20Sopenharmony_ci	cp $< "$(MODLIB)/vdso/$(@:install_%=%)"; \
1268c2ecf20Sopenharmony_ci	if readelf -n $< |grep -q 'Build ID'; then \
1278c2ecf20Sopenharmony_ci	  buildid=`readelf -n $< |grep 'Build ID' |sed -e 's/^.*Build ID: \(.*\)$$/\1/'`; \
1288c2ecf20Sopenharmony_ci	  first=`echo $$buildid | cut -b-2`; \
1298c2ecf20Sopenharmony_ci	  last=`echo $$buildid | cut -b3-`; \
1308c2ecf20Sopenharmony_ci	  mkdir -p "$(MODLIB)/vdso/.build-id/$$first"; \
1318c2ecf20Sopenharmony_ci	  ln -sf "../../$(@:install_%=%)" "$(MODLIB)/vdso/.build-id/$$first/$$last.debug"; \
1328c2ecf20Sopenharmony_ci	fi
1338c2ecf20Sopenharmony_ciendef
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_civdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci$(MODLIB)/vdso: FORCE
1388c2ecf20Sopenharmony_ci	@mkdir -p $(MODLIB)/vdso
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci$(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso FORCE
1418c2ecf20Sopenharmony_ci	$(call cmd,vdso_install)
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciPHONY += vdso_install $(vdso_img_insttargets)
1448c2ecf20Sopenharmony_civdso_install: $(vdso_img_insttargets) FORCE
145