Merge branch 'x86-vdso-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / arch / x86 / vdso / Makefile
1 #
2 # Building vDSO images for x86.
3 #
4
5 KBUILD_CFLAGS += $(DISABLE_LTO)
6
7 VDSO64-$(CONFIG_X86_64)         := y
8 VDSOX32-$(CONFIG_X86_X32_ABI)   := y
9 VDSO32-$(CONFIG_X86_32)         := y
10 VDSO32-$(CONFIG_COMPAT)         := y
11
12 vdso-install-$(VDSO64-y)        += vdso.so
13 vdso-install-$(VDSOX32-y)       += vdsox32.so
14 vdso-install-$(VDSO32-y)        += $(vdso32-images)
15
16
17 # files to link into the vdso
18 vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
19
20 vobjs-$(VDSOX32-y) += $(vobjx32s-compat)
21
22 # Filter out x32 objects.
23 vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y))
24
25 # files to link into kernel
26 obj-y                           += vma.o
27 obj-$(VDSO64-y)                 += vdso.o
28 obj-$(VDSOX32-y)                += vdsox32.o
29 obj-$(VDSO32-y)                 += vdso32.o vdso32-setup.o
30
31 vobjs := $(foreach F,$(vobj64s),$(obj)/$F)
32
33 $(obj)/vdso.o: $(obj)/vdso.so
34
35 targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
36
37 export CPPFLAGS_vdso.lds += -P -C
38
39 VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
40                         -Wl,--no-undefined \
41                         -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
42                         $(DISABLE_LTO)
43
44 $(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
45
46 $(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
47         $(call if_changed,vdso)
48
49 $(obj)/%.so: OBJCOPYFLAGS := -S
50 $(obj)/%.so: $(obj)/%.so.dbg FORCE
51         $(call if_changed,objcopy)
52
53 #
54 # Don't omit frame pointers for ease of userspace debugging, but do
55 # optimize sibling calls.
56 #
57 CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
58        $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
59        -fno-omit-frame-pointer -foptimize-sibling-calls
60
61 $(vobjs): KBUILD_CFLAGS += $(CFL)
62
63 #
64 # vDSO code runs in userspace and -pg doesn't help with profiling anyway.
65 #
66 CFLAGS_REMOVE_vdso-note.o = -pg
67 CFLAGS_REMOVE_vclock_gettime.o = -pg
68 CFLAGS_REMOVE_vgetcpu.o = -pg
69 CFLAGS_REMOVE_vvar.o = -pg
70
71 targets += vdso-syms.lds
72 obj-$(VDSO64-y)                 += vdso-syms.lds
73
74 #
75 # Match symbols in the DSO that look like VDSO*; produce a file of constants.
76 #
77 sed-vdsosym := -e 's/^00*/0/' \
78         -e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p'
79 quiet_cmd_vdsosym = VDSOSYM $@
80 define cmd_vdsosym
81         $(NM) $< | LC_ALL=C sed -n $(sed-vdsosym) | LC_ALL=C sort > $@
82 endef
83
84 $(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
85         $(call if_changed,vdsosym)
86
87 #
88 # X32 processes use x32 vDSO to access 64bit kernel data.
89 #
90 # Build x32 vDSO image:
91 # 1. Compile x32 vDSO as 64bit.
92 # 2. Convert object files to x32.
93 # 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
94 # so that it can reach 64bit address space with 64bit pointers.
95 #
96
97 targets += vdsox32-syms.lds
98 obj-$(VDSOX32-y)                += vdsox32-syms.lds
99
100 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
101 VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
102                            -Wl,-soname=linux-vdso.so.1 \
103                            -Wl,-z,max-page-size=4096 \
104                            -Wl,-z,common-page-size=4096
105
106 vobjx32s-y := $(vobj64s:.o=-x32.o)
107 vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
108
109 # Convert 64bit object file to x32 for x32 vDSO.
110 quiet_cmd_x32 = X32     $@
111       cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
112
113 $(obj)/%-x32.o: $(obj)/%.o FORCE
114         $(call if_changed,x32)
115
116 targets += vdsox32.so vdsox32.so.dbg vdsox32.lds $(vobjx32s-y)
117
118 $(obj)/vdsox32.o: $(src)/vdsox32.S $(obj)/vdsox32.so
119
120 $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
121         $(call if_changed,vdso)
122
123 #
124 # Build multiple 32-bit vDSO images to choose from at boot time.
125 #
126 obj-$(VDSO32-y)                 += vdso32-syms.lds
127 vdso32.so-$(VDSO32-y)           += int80
128 vdso32.so-$(CONFIG_COMPAT)      += syscall
129 vdso32.so-$(VDSO32-y)           += sysenter
130
131 vdso32-images                   = $(vdso32.so-y:%=vdso32-%.so)
132
133 CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
134 VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
135
136 # This makes sure the $(obj) subdirectory exists even though vdso32/
137 # is not a kbuild sub-make subdirectory.
138 override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
139
140 targets += vdso32/vdso32.lds
141 targets += $(vdso32-images) $(vdso32-images:=.dbg)
142 targets += vdso32/note.o vdso32/vclock_gettime.o $(vdso32.so-y:%=vdso32/%.o)
143
144 extra-y += $(vdso32-images)
145
146 $(obj)/vdso32.o: $(vdso32-images:%=$(obj)/%)
147
148 KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
149 $(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
150 $(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32
151
152 KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
153 KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
154 KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
155 KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
156 KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
157 KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
158 KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
159 KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
160 $(vdso32-images:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
161
162 $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
163                                  $(obj)/vdso32/vdso32.lds \
164                                  $(obj)/vdso32/vclock_gettime.o \
165                                  $(obj)/vdso32/note.o \
166                                  $(obj)/vdso32/%.o
167         $(call if_changed,vdso)
168
169 # Make vdso32-*-syms.lds from each image, and then make sure they match.
170 # The only difference should be that some do not define VDSO32_SYSENTER_RETURN.
171
172 targets += vdso32-syms.lds $(vdso32.so-y:%=vdso32-%-syms.lds)
173
174 quiet_cmd_vdso32sym = VDSOSYM $@
175 define cmd_vdso32sym
176         if LC_ALL=C sort -u $(filter-out FORCE,$^) > $(@D)/.tmp_$(@F) && \
177            $(foreach H,$(filter-out FORCE,$^),\
178                      if grep -q VDSO32_SYSENTER_RETURN $H; \
179                      then diff -u $(@D)/.tmp_$(@F) $H; \
180                      else sed /VDSO32_SYSENTER_RETURN/d $(@D)/.tmp_$(@F) | \
181                           diff -u - $H; fi &&) : ;\
182         then mv -f $(@D)/.tmp_$(@F) $@; \
183         else rm -f $(@D)/.tmp_$(@F); exit 1; \
184         fi
185 endef
186
187 $(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE
188         $(call if_changed,vdso32sym)
189
190 #
191 # The DSO images are built using a special linker script.
192 #
193 quiet_cmd_vdso = VDSO    $@
194       cmd_vdso = $(CC) -nostdlib -o $@ \
195                        $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
196                        -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
197                  sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
198
199 VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
200                 $(LTO_CFLAGS)
201 GCOV_PROFILE := n
202
203 #
204 # Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
205 #
206 quiet_cmd_vdso_install = INSTALL $@
207       cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
208 $(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE
209         @mkdir -p $(MODLIB)/vdso
210         $(call cmd,vdso_install)
211
212 PHONY += vdso_install $(vdso-install-y)
213 vdso_install: $(vdso-install-y)
214
215 clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80*