162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci# 362306a36Sopenharmony_ci# Building vDSO images for sparc. 462306a36Sopenharmony_ci# 562306a36Sopenharmony_ci 662306a36Sopenharmony_ciVDSO64-$(CONFIG_SPARC64) := y 762306a36Sopenharmony_ciVDSOCOMPAT-$(CONFIG_COMPAT) := y 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci# files to link into the vdso 1062306a36Sopenharmony_civobjs-y := vdso-note.o vclock_gettime.o 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci# files to link into kernel 1362306a36Sopenharmony_ciobj-y += vma.o 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci# vDSO images to build 1662306a36Sopenharmony_civdso_img-$(VDSO64-y) += 64 1762306a36Sopenharmony_civdso_img-$(VDSOCOMPAT-y) += 32 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_civobjs := $(foreach F,$(vobjs-y),$(obj)/$F) 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci$(obj)/vdso.o: $(obj)/vdso.so 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_citargets += vdso.lds $(vobjs-y) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci# Build the vDSO image C files and link them in. 2662306a36Sopenharmony_civdso_img_objs := $(vdso_img-y:%=vdso-image-%.o) 2762306a36Sopenharmony_civdso_img_cfiles := $(vdso_img-y:%=vdso-image-%.c) 2862306a36Sopenharmony_civdso_img_sodbg := $(vdso_img-y:%=vdso%.so.dbg) 2962306a36Sopenharmony_ciobj-y += $(vdso_img_objs) 3062306a36Sopenharmony_citargets += $(vdso_img_cfiles) 3162306a36Sopenharmony_citargets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciCPPFLAGS_vdso.lds += -P -C 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciVDSO_LDFLAGS_vdso.lds = -m elf64_sparc -soname linux-vdso.so.1 --no-undefined \ 3662306a36Sopenharmony_ci -z max-page-size=8192 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE 3962306a36Sopenharmony_ci $(call if_changed,vdso) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciHOST_EXTRACFLAGS += -I$(srctree)/tools/include 4262306a36Sopenharmony_cihostprogs += vdso2c 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciquiet_cmd_vdso2c = VDSO2C $@ 4562306a36Sopenharmony_ci cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@ 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE 4862306a36Sopenharmony_ci $(call if_changed,vdso2c) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci# 5162306a36Sopenharmony_ci# Don't omit frame pointers for ease of userspace debugging, but do 5262306a36Sopenharmony_ci# optimize sibling calls. 5362306a36Sopenharmony_ci# 5462306a36Sopenharmony_ciCFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ 5562306a36Sopenharmony_ci $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ 5662306a36Sopenharmony_ci -fno-omit-frame-pointer -foptimize-sibling-calls \ 5762306a36Sopenharmony_ci -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ciSPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci$(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci# 6462306a36Sopenharmony_ci# vDSO code runs in userspace and -pg doesn't help with profiling anyway. 6562306a36Sopenharmony_ci# 6662306a36Sopenharmony_ciCFLAGS_REMOVE_vclock_gettime.o = -pg 6762306a36Sopenharmony_ciCFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci$(obj)/%.so: OBJCOPYFLAGS := -S 7062306a36Sopenharmony_ci$(obj)/%.so: $(obj)/%.so.dbg FORCE 7162306a36Sopenharmony_ci $(call if_changed,objcopy) 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciCPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds) 7462306a36Sopenharmony_ciVDSO_LDFLAGS_vdso32.lds = -m elf32_sparc -soname linux-gate.so.1 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#This makes sure the $(obj) subdirectory exists even though vdso32/ 7762306a36Sopenharmony_ci#is not a kbuild sub-make subdirectory 7862306a36Sopenharmony_cioverride obj-dirs = $(dir $(obj)) $(obj)/vdso32/ 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_citargets += vdso32/vdso32.lds 8162306a36Sopenharmony_citargets += vdso32/vdso-note.o 8262306a36Sopenharmony_citargets += vdso32/vclock_gettime.o 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciKBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO 8562306a36Sopenharmony_ci$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) 8662306a36Sopenharmony_ci$(obj)/vdso32.so.dbg: asflags-$(CONFIG_SPARC64) += -m32 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) 8962306a36Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -mcmodel=medlow,$(KBUILD_CFLAGS_32)) 9062306a36Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) 9162306a36Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32)) 9262306a36Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) 9362306a36Sopenharmony_ciKBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) 9462306a36Sopenharmony_ciKBUILD_CFLAGS_32 += -m32 -msoft-float -fpic 9562306a36Sopenharmony_ciKBUILD_CFLAGS_32 += -fno-stack-protector 9662306a36Sopenharmony_ciKBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) 9762306a36Sopenharmony_ciKBUILD_CFLAGS_32 += -fno-omit-frame-pointer 9862306a36Sopenharmony_ciKBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING 9962306a36Sopenharmony_ciKBUILD_CFLAGS_32 += -mv8plus 10062306a36Sopenharmony_ci$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci$(obj)/vdso32.so.dbg: FORCE \ 10362306a36Sopenharmony_ci $(obj)/vdso32/vdso32.lds \ 10462306a36Sopenharmony_ci $(obj)/vdso32/vclock_gettime.o \ 10562306a36Sopenharmony_ci $(obj)/vdso32/vdso-note.o 10662306a36Sopenharmony_ci $(call if_changed,vdso) 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci# 10962306a36Sopenharmony_ci# The DSO images are built using a special linker script. 11062306a36Sopenharmony_ci# 11162306a36Sopenharmony_ciquiet_cmd_vdso = VDSO $@ 11262306a36Sopenharmony_ci cmd_vdso = $(LD) -nostdlib -o $@ \ 11362306a36Sopenharmony_ci $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ 11462306a36Sopenharmony_ci -T $(filter %.lds,$^) $(filter %.o,$^) && \ 11562306a36Sopenharmony_ci sh $(srctree)/$(src)/checkundef.sh '$(OBJDUMP)' '$@' 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ciVDSO_LDFLAGS = -shared --hash-style=both --build-id=sha1 -Bsymbolic 11862306a36Sopenharmony_ciGCOV_PROFILE := n 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci# 12162306a36Sopenharmony_ci# Install the unstripped copies of vdso*.so. If our toolchain supports 12262306a36Sopenharmony_ci# build-id, install .build-id links as well. 12362306a36Sopenharmony_ci# 12462306a36Sopenharmony_ciquiet_cmd_vdso_install = INSTALL $(@:install_%=%) 12562306a36Sopenharmony_cidefine cmd_vdso_install 12662306a36Sopenharmony_ci cp $< "$(MODLIB)/vdso/$(@:install_%=%)"; \ 12762306a36Sopenharmony_ci if readelf -n $< |grep -q 'Build ID'; then \ 12862306a36Sopenharmony_ci buildid=`readelf -n $< |grep 'Build ID' |sed -e 's/^.*Build ID: \(.*\)$$/\1/'`; \ 12962306a36Sopenharmony_ci first=`echo $$buildid | cut -b-2`; \ 13062306a36Sopenharmony_ci last=`echo $$buildid | cut -b3-`; \ 13162306a36Sopenharmony_ci mkdir -p "$(MODLIB)/vdso/.build-id/$$first"; \ 13262306a36Sopenharmony_ci ln -sf "../../$(@:install_%=%)" "$(MODLIB)/vdso/.build-id/$$first/$$last.debug"; \ 13362306a36Sopenharmony_ci fi 13462306a36Sopenharmony_ciendef 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_civdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%) 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci$(MODLIB)/vdso: FORCE 13962306a36Sopenharmony_ci @mkdir -p $(MODLIB)/vdso 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci$(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso FORCE 14262306a36Sopenharmony_ci $(call cmd,vdso_install) 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ciPHONY += vdso_install $(vdso_img_insttargets) 14562306a36Sopenharmony_civdso_install: $(vdso_img_insttargets) FORCE 146