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