10715372aSGuo Ren# SPDX-License-Identifier: GPL-2.0-only 20715372aSGuo Ren# 30715372aSGuo Ren# Makefile for compat_vdso 40715372aSGuo Ren# 50715372aSGuo Ren 60715372aSGuo Ren# Symbols present in the compat_vdso 70715372aSGuo Rencompat_vdso-syms = rt_sigreturn 80715372aSGuo Rencompat_vdso-syms += getcpu 90715372aSGuo Rencompat_vdso-syms += flush_icache 100715372aSGuo Ren 110715372aSGuo RenCOMPAT_CC := $(CC) 120715372aSGuo RenCOMPAT_LD := $(LD) 130715372aSGuo Ren 14*ca09f772SMingzheng Xing# binutils 2.35 does not support the zifencei extension, but in the ISA 15*ca09f772SMingzheng Xing# spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI. 16*ca09f772SMingzheng Xingifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI 170715372aSGuo Ren COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32 18*ca09f772SMingzheng Xingelse 19*ca09f772SMingzheng Xing COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32 20*ca09f772SMingzheng Xingendif 210715372aSGuo RenCOMPAT_LD_FLAGS := -melf32lriscv 220715372aSGuo Ren 23e18048daSPalmer Dabbelt# Disable attributes, as they're useless and break the build. 24e18048daSPalmer DabbeltCOMPAT_CC_FLAGS += $(call cc-option,-mno-riscv-attribute) 25e18048daSPalmer DabbeltCOMPAT_CC_FLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 26e18048daSPalmer Dabbelt 270715372aSGuo Ren# Files to link into the compat_vdso 280715372aSGuo Renobj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o 290715372aSGuo Ren 300715372aSGuo Ren# Build rules 310715372aSGuo Rentargets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds 320715372aSGuo Renobj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso)) 330715372aSGuo Ren 340715372aSGuo Renobj-y += compat_vdso.o 35aa5af0aaSEvan GreenCPPFLAGS_compat_vdso.lds += -P -C -DCOMPAT_VDSO -U$(ARCH) 360715372aSGuo Ren 370715372aSGuo Ren# Disable profiling and instrumentation for VDSO code 380715372aSGuo RenGCOV_PROFILE := n 390715372aSGuo RenKCOV_INSTRUMENT := n 400715372aSGuo RenKASAN_SANITIZE := n 410715372aSGuo RenUBSAN_SANITIZE := n 420715372aSGuo Ren 430715372aSGuo Ren# Force dependency 440715372aSGuo Ren$(obj)/compat_vdso.o: $(obj)/compat_vdso.so 450715372aSGuo Ren 460715372aSGuo Ren# link rule for the .so file, .lds has to be first 470715372aSGuo Ren$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE 480715372aSGuo Ren $(call if_changed,compat_vdsold) 490715372aSGuo RenLDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \ 500715372aSGuo Ren --build-id=sha1 --hash-style=both --eh-frame-hdr 510715372aSGuo Ren 520715372aSGuo Ren$(obj-compat_vdso): %.o: %.S FORCE 530715372aSGuo Ren $(call if_changed_dep,compat_vdsoas) 540715372aSGuo Ren 550715372aSGuo Ren# strip rule for the .so file 560715372aSGuo Ren$(obj)/%.so: OBJCOPYFLAGS := -S 570715372aSGuo Ren$(obj)/%.so: $(obj)/%.so.dbg FORCE 580715372aSGuo Ren $(call if_changed,objcopy) 590715372aSGuo Ren 600715372aSGuo Ren# Generate VDSO offsets using helper script 610715372aSGuo Rengen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh 620715372aSGuo Renquiet_cmd_compat_vdsosym = VDSOSYM $@ 630715372aSGuo Ren cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@ 640715372aSGuo Ren 650715372aSGuo Reninclude/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE 660715372aSGuo Ren $(call if_changed,compat_vdsosym) 670715372aSGuo Ren 680715372aSGuo Ren# actual build commands 690715372aSGuo Ren# The DSO images are built using a special linker script 700715372aSGuo Ren# Make sure only to export the intended __compat_vdso_xxx symbol offsets. 710715372aSGuo Renquiet_cmd_compat_vdsold = VDSOLD $@ 720715372aSGuo Ren cmd_compat_vdsold = $(COMPAT_LD) $(ld_flags) $(COMPAT_LD_FLAGS) -T $(filter-out FORCE,$^) -o $@.tmp && \ 730715372aSGuo Ren $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \ 740715372aSGuo Ren rm $@.tmp 750715372aSGuo Ren 760715372aSGuo Ren# actual build commands 770715372aSGuo Renquiet_cmd_compat_vdsoas = VDSOAS $@ 780715372aSGuo Ren cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $< 79