| 1 |
# SPDX-License-Identifier: GPL-2.0-only |
| 2 |
# Copied from arch/tile/kernel/vdso/Makefile |
| 3 |
|
| 4 |
# Include the generic Makefile to check the built vdso. |
| 5 |
include $(srctree)/lib/vdso/Makefile.include |
| 6 |
# Symbols present in the vdso |
| 7 |
vdso-syms = rt_sigreturn |
| 8 |
ifdef CONFIG_64BIT |
| 9 |
vdso-syms += vgettimeofday |
| 10 |
endif |
| 11 |
vdso-syms += getcpu |
| 12 |
vdso-syms += flush_icache |
| 13 |
vdso-syms += hwprobe |
| 14 |
vdso-syms += sys_hwprobe |
| 15 |
|
| 16 |
ifdef CONFIG_VDSO_GETRANDOM |
| 17 |
vdso-syms += getrandom |
| 18 |
endif |
| 19 |
|
| 20 |
ifdef VDSO_CFI_BUILD |
| 21 |
CFI_MARCH = _zicfilp_zicfiss |
| 22 |
CFI_FULL = -fcf-protection=full |
| 23 |
CFI_SUFFIX = -cfi |
| 24 |
OFFSET_SUFFIX = _cfi |
| 25 |
ccflags-y += -DVDSO_CFI=1 |
| 26 |
asflags-y += -DVDSO_CFI=1 |
| 27 |
endif |
| 28 |
|
| 29 |
# Files to link into the vdso |
| 30 |
obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o |
| 31 |
|
| 32 |
ifdef CONFIG_VDSO_GETRANDOM |
| 33 |
obj-vdso += vgetrandom-chacha.o |
| 34 |
endif |
| 35 |
|
| 36 |
ccflags-y := -fno-stack-protector |
| 37 |
ccflags-y += -DDISABLE_BRANCH_PROFILING |
| 38 |
ccflags-y += -fno-builtin |
| 39 |
ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) |
| 40 |
ccflags-y += $(CFI_FULL) |
| 41 |
asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) |
| 42 |
asflags-y += $(CFI_FULL) |
| 43 |
|
| 44 |
ifneq ($(c-gettimeofday-y),) |
| 45 |
CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y) |
| 46 |
endif |
| 47 |
|
| 48 |
ifneq ($(c-getrandom-y),) |
| 49 |
CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y) |
| 50 |
endif |
| 51 |
|
| 52 |
CFLAGS_hwprobe.o += -fPIC |
| 53 |
|
| 54 |
# Build rules |
| 55 |
vdso_offsets := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),)-offsets.h |
| 56 |
vdso_o := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o |
| 57 |
vdso_so := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so |
| 58 |
vdso_so_dbg := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so.dbg |
| 59 |
vdso_lds := vdso.lds |
| 60 |
|
| 61 |
targets := $(obj-vdso) $(vdso_so) $(vdso_so_dbg) $(vdso_lds) |
| 62 |
|
| 63 |
obj-vdso := $(addprefix $(obj)/, $(obj-vdso)) |
| 64 |
|
| 65 |
obj-y += vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o |
| 66 |
CPPFLAGS_$(vdso_lds) += -P -C -U$(ARCH) |
| 67 |
ifneq ($(filter vgettimeofday, $(vdso-syms)),) |
| 68 |
CPPFLAGS_$(vdso_lds) += -DHAS_VGETTIMEOFDAY |
| 69 |
endif |
| 70 |
|
| 71 |
# Disable -pg to prevent insert call site |
| 72 |
CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) |
| 73 |
CFLAGS_REMOVE_getrandom.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) |
| 74 |
CFLAGS_REMOVE_hwprobe.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) |
| 75 |
|
| 76 |
# Force dependency |
| 77 |
$(obj)/$(vdso_o): $(obj)/$(vdso_so) |
| 78 |
|
| 79 |
# link rule for the .so file, .lds has to be first |
| 80 |
$(obj)/$(vdso_so_dbg): $(obj)/$(vdso_lds) $(obj-vdso) FORCE |
| 81 |
$(call if_changed,vdsold_and_check) |
| 82 |
LDFLAGS_$(vdso_so_dbg) = -shared -soname=linux-vdso.so.1 \ |
| 83 |
--build-id=sha1 --eh-frame-hdr |
| 84 |
|
| 85 |
# strip rule for the .so file |
| 86 |
$(obj)/%.so: OBJCOPYFLAGS := -S |
| 87 |
$(obj)/%.so: $(obj)/%.so.dbg FORCE |
| 88 |
$(call if_changed,objcopy) |
| 89 |
|
| 90 |
# Generate VDSO offsets using helper script |
| 91 |
gen-vdsosym := $(src)/gen_vdso_offsets.sh |
| 92 |
quiet_cmd_vdsosym = VDSOSYM $@ |
| 93 |
cmd_vdsosym = $(NM) $< | $(gen-vdsosym) $(OFFSET_SUFFIX) | LC_ALL=C sort > $@ |
| 94 |
|
| 95 |
include/generated/$(vdso_offsets): $(obj)/$(vdso_so_dbg) FORCE |
| 96 |
$(call if_changed,vdsosym) |
| 97 |
|
| 98 |
# actual build commands |
| 99 |
# The DSO images are built using a special linker script |
| 100 |
# Make sure only to export the intended __vdso_xxx symbol offsets. |
| 101 |
quiet_cmd_vdsold_and_check = VDSOLD $@ |
| 102 |
cmd_vdsold_and_check = $(LD) $(CFI_FULL) $(ld_flags) -T $(filter-out FORCE,$^) -o [email protected] && \ |
| 103 |
$(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) [email protected] $@ && \ |
| 104 |
rm [email protected] && \ |
| 105 |
$(cmd_vdso_check) |