^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # Copied from arch/tile/kernel/vdso/Makefile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # the inclusion of generic Makefile.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) include $(srctree)/lib/vdso/Makefile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # Symbols present in the vdso
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) vdso-syms = rt_sigreturn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) vdso-syms += vgettimeofday
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) vdso-syms += getcpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) vdso-syms += flush_icache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) # Files to link into the vdso
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ccflags-y := -fno-stack-protector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ifneq ($(c-gettimeofday-y),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # Build rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-syms.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) obj-y += vdso.o vdso-syms.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) # Disable -pg to prevent insert call site
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # Disable profiling and instrumentation for VDSO code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) GCOV_PROFILE := n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) KCOV_INSTRUMENT := n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) KASAN_SANITIZE := n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) # Force dependency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) $(obj)/vdso.o: $(obj)/vdso.so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) # link rule for the .so file, .lds has to be first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) $(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) $(call if_changed,vdsold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) LDFLAGS_vdso.so.dbg = -shared -s -soname=linux-vdso.so.1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) --build-id=sha1 --hash-style=both --eh-frame-hdr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) # We also create a special relocatable object that should mirror the symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) # table and layout of the linked DSO. With ld --just-symbols we can then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) # refer to these symbols in the kernel code rather than hand-coded addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) $(obj)/vdso-syms.S: $(obj)/vdso.so FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) $(call if_changed,so2s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) # strip rule for the .so file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) $(obj)/%.so: OBJCOPYFLAGS := -S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) $(obj)/%.so: $(obj)/%.so.dbg FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) $(call if_changed,objcopy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) # actual build commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) # The DSO images are built using a special linker script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) # Make sure only to export the intended __vdso_xxx symbol offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) quiet_cmd_vdsold = VDSOLD $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) cmd_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) rm $@.tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) # Extracts symbol offsets from the VDSO, converting them into an assembly file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) # that contains the same symbols at the same offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) quiet_cmd_so2s = SO2S $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh > $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) # install commands for the unstripped file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) quiet_cmd_vdso_install = INSTALL $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) vdso.so: $(obj)/vdso.so.dbg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) @mkdir -p $(MODLIB)/vdso
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) $(call cmd,vdso_install)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) vdso_install: vdso.so