1# SPDX-License-Identifier: GPL-2.0-only 2# 3# Makefile for compat_vdso 4# 5 6# Symbols present in the compat_vdso 7compat_vdso-syms = rt_sigreturn 8compat_vdso-syms += getcpu 9compat_vdso-syms += flush_icache 10 11COMPAT_CC := $(CC) 12COMPAT_LD := $(LD) 13 14# binutils 2.35 does not support the zifencei extension, but in the ISA 15# spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI. 16ifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI 17 COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32 18else 19 COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32 20endif 21COMPAT_LD_FLAGS := -melf32lriscv 22 23# Disable attributes, as they're useless and break the build. 24COMPAT_CC_FLAGS += $(call cc-option,-mno-riscv-attribute) 25COMPAT_CC_FLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 26 27# Files to link into the compat_vdso 28obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o 29 30# Build rules 31targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds 32obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso)) 33 34obj-y += compat_vdso.o 35CPPFLAGS_compat_vdso.lds += -P -C -DCOMPAT_VDSO -U$(ARCH) 36 37# Disable profiling and instrumentation for VDSO code 38GCOV_PROFILE := n 39KCOV_INSTRUMENT := n 40KASAN_SANITIZE := n 41UBSAN_SANITIZE := n 42 43# Force dependency 44$(obj)/compat_vdso.o: $(obj)/compat_vdso.so 45 46# link rule for the .so file, .lds has to be first 47$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE 48 $(call if_changed,compat_vdsold) 49LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \ 50 --build-id=sha1 --hash-style=both --eh-frame-hdr 51 52$(obj-compat_vdso): %.o: %.S FORCE 53 $(call if_changed_dep,compat_vdsoas) 54 55# strip rule for the .so file 56$(obj)/%.so: OBJCOPYFLAGS := -S 57$(obj)/%.so: $(obj)/%.so.dbg FORCE 58 $(call if_changed,objcopy) 59 60# Generate VDSO offsets using helper script 61gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh 62quiet_cmd_compat_vdsosym = VDSOSYM $@ 63 cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@ 64 65include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE 66 $(call if_changed,compat_vdsosym) 67 68# actual build commands 69# The DSO images are built using a special linker script 70# Make sure only to export the intended __compat_vdso_xxx symbol offsets. 71quiet_cmd_compat_vdsold = VDSOLD $@ 72 cmd_compat_vdsold = $(COMPAT_LD) $(ld_flags) $(COMPAT_LD_FLAGS) -T $(filter-out FORCE,$^) -o $@.tmp && \ 73 $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \ 74 rm $@.tmp 75 76# actual build commands 77quiet_cmd_compat_vdsoas = VDSOAS $@ 78 cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $< 79 80# install commands for the unstripped file 81quiet_cmd_compat_vdso_install = INSTALL $@ 82 cmd_compat_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/compat_vdso/$@ 83 84compat_vdso.so: $(obj)/compat_vdso.so.dbg 85 @mkdir -p $(MODLIB)/compat_vdso 86 $(call cmd,compat_vdso_install) 87 88compat_vdso_install: compat_vdso.so 89