blob: b596a7396382d771943eb364f81726281ea34e6d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Chris Metcalf4a556f42013-08-07 15:33:32 -04002# Symbols present in the vdso
3vdso-syms = rt_sigreturn gettimeofday
4
5# Files to link into the vdso
6obj-vdso = $(patsubst %, v%.o, $(vdso-syms))
7
8# Build rules
Nicholas Piggind6d62a12017-06-22 22:39:29 +10009targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-dummy.o
Chris Metcalf4a556f42013-08-07 15:33:32 -040010obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
11
12# vdso32 is only for tilegx -m32 compat task.
13VDSO32-$(CONFIG_COMPAT) := y
14
Nicholas Piggind6d62a12017-06-22 22:39:29 +100015obj-y += vdso.o vdso-syms.o
Chris Metcalf4a556f42013-08-07 15:33:32 -040016obj-$(VDSO32-y) += vdso32.o
Chris Metcalf4a556f42013-08-07 15:33:32 -040017CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
18
19# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
20CFLAGS_REMOVE_vdso.o = -pg
21CFLAGS_REMOVE_vdso32.o = -pg
22CFLAGS_REMOVE_vrt_sigreturn.o = -pg
23CFLAGS_REMOVE_vrt_sigreturn32.o = -pg
24CFLAGS_REMOVE_vgettimeofday.o = -pg
25CFLAGS_REMOVE_vgettimeofday32.o = -pg
26
27ifdef CONFIG_FEEDBACK_COLLECT
28# vDSO code runs in userspace, not collecting feedback data.
29CFLAGS_REMOVE_vdso.o = -ffeedback-generate
30CFLAGS_REMOVE_vdso32.o = -ffeedback-generate
31CFLAGS_REMOVE_vrt_sigreturn.o = -ffeedback-generate
32CFLAGS_REMOVE_vrt_sigreturn32.o = -ffeedback-generate
33CFLAGS_REMOVE_vgettimeofday.o = -ffeedback-generate
34CFLAGS_REMOVE_vgettimeofday32.o = -ffeedback-generate
35endif
36
37# Disable gcov profiling for VDSO code
38GCOV_PROFILE := n
39
40# Force dependency
41$(obj)/vdso.o: $(obj)/vdso.so
42
43# link rule for the .so file, .lds has to be first
44SYSCFLAGS_vdso.so.dbg = $(c_flags)
Masahiro Yamada44ea9942017-06-25 10:53:08 +090045$(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE
Chris Metcalf4a556f42013-08-07 15:33:32 -040046 $(call if_changed,vdsold)
47
Chris Metcalf4a556f42013-08-07 15:33:32 -040048# We also create a special relocatable object that should mirror the symbol
49# table and layout of the linked DSO. With ld -R we can then refer to
50# these symbols in the kernel code rather than hand-coded addresses.
Chris Metcalf4a556f42013-08-07 15:33:32 -040051
52SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
Chris Metcalfff3e9a72015-08-06 20:22:40 -040053 $(call cc-ldoption, -Wl$(comma)--hash-style=both)
Nicholas Piggind6d62a12017-06-22 22:39:29 +100054SYSCFLAGS_vdso_dummy.o = -r
55$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/vrt_sigreturn.o FORCE
Chris Metcalf4a556f42013-08-07 15:33:32 -040056 $(call if_changed,vdsold)
57
Nicholas Piggind6d62a12017-06-22 22:39:29 +100058LDFLAGS_vdso-syms.o := -r -R
59$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
60 $(call if_changed,ld)
Chris Metcalf4a556f42013-08-07 15:33:32 -040061
62# strip rule for the .so file
63$(obj)/%.so: OBJCOPYFLAGS := -S
64$(obj)/%.so: $(obj)/%.so.dbg FORCE
65 $(call if_changed,objcopy)
66
67# actual build commands
68# The DSO images are built using a special linker script
69# Add -lgcc so tilepro gets static muldi3 and lshrdi3 definitions.
70# Make sure only to export the intended __vdso_xxx symbol offsets.
71quiet_cmd_vdsold = VDSOLD $@
72 cmd_vdsold = $(CC) $(KCFLAGS) -nostdlib $(SYSCFLAGS_$(@F)) \
73 -Wl,-T,$(filter-out FORCE,$^) -o $@.tmp -lgcc && \
74 $(CROSS_COMPILE)objcopy \
75 $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@
76
77# install commands for the unstripped file
78quiet_cmd_vdso_install = INSTALL $@
79 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
80
81vdso.so: $(obj)/vdso.so.dbg
82 @mkdir -p $(MODLIB)/vdso
83 $(call cmd,vdso_install)
84
85vdso32.so: $(obj)/vdso32.so.dbg
86 $(call cmd,vdso_install)
87
88vdso_install: vdso.so
89vdso32_install: vdso32.so
90
91
92KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
93KBUILD_AFLAGS_32 += -m32 -s
94KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
95KBUILD_CFLAGS_32 += -m32 -fPIC -shared
96
97obj-vdso32 = $(patsubst %, v%32.o, $(vdso-syms))
Chris Metcalf4a556f42013-08-07 15:33:32 -040098
99targets += $(obj-vdso32) vdso32.so vdso32.so.dbg
Masahiro Yamada44ea9942017-06-25 10:53:08 +0900100obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32))
Chris Metcalf4a556f42013-08-07 15:33:32 -0400101
102$(obj-vdso32:%=%): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
103$(obj-vdso32:%=%): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
104
Masahiro Yamada44ea9942017-06-25 10:53:08 +0900105$(obj)/vgettimeofday32.o: $(obj)/vgettimeofday.c FORCE
Kerry Sheh603eb2c2014-04-02 10:45:35 +0800106 $(call if_changed_rule,cc_o_c)
Chris Metcalf4a556f42013-08-07 15:33:32 -0400107
Masahiro Yamada44ea9942017-06-25 10:53:08 +0900108$(obj)/vrt_sigreturn32.o: $(obj)/vrt_sigreturn.S FORCE
Chris Metcalf4a556f42013-08-07 15:33:32 -0400109 $(call if_changed,as_o_S)
110
111# Force dependency
112$(obj)/vdso32.o: $(obj)/vdso32.so
113
114SYSCFLAGS_vdso32.so.dbg = -m32 -shared -s -Wl,-soname=linux-vdso32.so.1 \
Chris Metcalfff3e9a72015-08-06 20:22:40 -0400115 $(call cc-ldoption, -Wl$(comma)--hash-style=both)
Masahiro Yamada44ea9942017-06-25 10:53:08 +0900116$(obj)/vdso32.so.dbg: $(src)/vdso.lds $(obj-vdso32) FORCE
Chris Metcalf4a556f42013-08-07 15:33:32 -0400117 $(call if_changed,vdsold)