xref: /linux/arch/riscv/kernel/compat_vdso/Makefile (revision ff9a79307f89563da6d841da8b7cc4a0afceb0e2)
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
14ca09f772SMingzheng Xing# binutils 2.35 does not support the zifencei extension, but in the ISA
15ca09f772SMingzheng Xing# spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI.
16ca09f772SMingzheng Xingifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
170715372aSGuo Ren	COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
18ca09f772SMingzheng Xingelse
19ca09f772SMingzheng Xing	COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32
20ca09f772SMingzheng 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# Force dependency
380715372aSGuo Ren$(obj)/compat_vdso.o: $(obj)/compat_vdso.so
390715372aSGuo Ren
400715372aSGuo Ren# link rule for the .so file, .lds has to be first
410715372aSGuo Ren$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE
420715372aSGuo Ren	$(call if_changed,compat_vdsold)
430715372aSGuo RenLDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \
440715372aSGuo Ren	--build-id=sha1 --hash-style=both --eh-frame-hdr
450715372aSGuo Ren
460715372aSGuo Ren$(obj-compat_vdso): %.o: %.S FORCE
470715372aSGuo Ren	$(call if_changed_dep,compat_vdsoas)
480715372aSGuo Ren
490715372aSGuo Ren# strip rule for the .so file
500715372aSGuo Ren$(obj)/%.so: OBJCOPYFLAGS := -S
510715372aSGuo Ren$(obj)/%.so: $(obj)/%.so.dbg FORCE
520715372aSGuo Ren	$(call if_changed,objcopy)
530715372aSGuo Ren
540715372aSGuo Ren# Generate VDSO offsets using helper script
55*b1992c37SMasahiro Yamadagen-compat_vdsosym := $(src)/gen_compat_vdso_offsets.sh
560715372aSGuo Renquiet_cmd_compat_vdsosym = VDSOSYM $@
570715372aSGuo Ren	cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@
580715372aSGuo Ren
590715372aSGuo Reninclude/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE
600715372aSGuo Ren	$(call if_changed,compat_vdsosym)
610715372aSGuo Ren
620715372aSGuo Ren# actual build commands
630715372aSGuo Ren# The DSO images are built using a special linker script
640715372aSGuo Ren# Make sure only to export the intended __compat_vdso_xxx symbol offsets.
650715372aSGuo Renquiet_cmd_compat_vdsold = VDSOLD  $@
660715372aSGuo Ren      cmd_compat_vdsold = $(COMPAT_LD) $(ld_flags) $(COMPAT_LD_FLAGS) -T $(filter-out FORCE,$^) -o $@.tmp && \
670715372aSGuo Ren                   $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \
680715372aSGuo Ren                   rm $@.tmp
690715372aSGuo Ren
700715372aSGuo Ren# actual build commands
710715372aSGuo Renquiet_cmd_compat_vdsoas = VDSOAS  $@
720715372aSGuo Ren      cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $<
73