blob: a2de5fc155119078e6b5eb7548b73a58679d38b6 [file] [log] [blame]
Andi Kleen2aae9502007-07-21 17:10:01 +02001#
Roland McGrath0249c9c2008-01-30 13:30:42 +01002# Building vDSO images for x86.
Andi Kleen2aae9502007-07-21 17:10:01 +02003#
4
Roland McGrath0249c9c2008-01-30 13:30:42 +01005VDSO64-$(CONFIG_X86_64) := y
H. J. Lu1a21d4e2012-02-19 11:38:06 -08006VDSOX32-$(CONFIG_X86_X32_ABI) := y
Roland McGrath0249c9c2008-01-30 13:30:42 +01007VDSO32-$(CONFIG_X86_32) := y
8VDSO32-$(CONFIG_COMPAT) := y
9
10vdso-install-$(VDSO64-y) += vdso.so
H. J. Lu1a21d4e2012-02-19 11:38:06 -080011vdso-install-$(VDSOX32-y) += vdsox32.so
Roland McGrath2c158262008-02-11 14:38:51 -080012vdso-install-$(VDSO32-y) += $(vdso32-images)
Roland McGrath0249c9c2008-01-30 13:30:42 +010013
14
Andi Kleen2aae9502007-07-21 17:10:01 +020015# files to link into the vdso
Andy Lutomirski8c49d9a2011-05-23 09:31:24 -040016vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
Andi Kleen2aae9502007-07-21 17:10:01 +020017
H. J. Lu1a21d4e2012-02-19 11:38:06 -080018vobjs-$(VDSOX32-y) += $(vobjx32s-compat)
19
20# Filter out x32 objects.
21vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y))
22
Andi Kleen2aae9502007-07-21 17:10:01 +020023# files to link into kernel
Andy Lutomirskib4b541a2014-03-17 23:22:08 +010024obj-y += vma.o
25obj-$(VDSO64-y) += vdso.o
H. J. Lu1a21d4e2012-02-19 11:38:06 -080026obj-$(VDSOX32-y) += vdsox32.o
Roland McGrathaf65d642008-01-30 13:30:43 +010027obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
Andi Kleen2aae9502007-07-21 17:10:01 +020028
H. J. Lu1a21d4e2012-02-19 11:38:06 -080029vobjs := $(foreach F,$(vobj64s),$(obj)/$F)
Andi Kleen2aae9502007-07-21 17:10:01 +020030
31$(obj)/vdso.o: $(obj)/vdso.so
32
Roland McGrath2b9c97e2008-01-30 13:30:41 +010033targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
Andi Kleen2aae9502007-07-21 17:10:01 +020034
Sam Ravnborgd746d642007-11-12 20:14:19 +010035export CPPFLAGS_vdso.lds += -P -C
Andi Kleen2aae9502007-07-21 17:10:01 +020036
H. Peter Anvinde2a8cf2010-12-13 16:01:38 -080037VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
Andy Lutomirski7f79ad12011-07-13 09:24:12 -040038 -Wl,--no-undefined \
Roland McGrath16e48e72008-01-30 13:30:44 +010039 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
Andi Kleen2aae9502007-07-21 17:10:01 +020040
41$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
42
Roland McGrathf79eb832007-10-17 18:04:32 +020043$(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
Roland McGrath16e48e72008-01-30 13:30:44 +010044 $(call if_changed,vdso)
Andi Kleen2aae9502007-07-21 17:10:01 +020045
Roland McGrathf79eb832007-10-17 18:04:32 +020046$(obj)/%.so: OBJCOPYFLAGS := -S
47$(obj)/%.so: $(obj)/%.so.dbg FORCE
48 $(call if_changed,objcopy)
49
Andy Lutomirski6447fac2011-05-23 09:31:29 -040050#
51# Don't omit frame pointers for ease of userspace debugging, but do
52# optimize sibling calls.
53#
Roland McGrath8705a492008-04-14 12:19:30 -070054CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
Andy Lutomirski6447fac2011-05-23 09:31:29 -040055 $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
56 -fno-omit-frame-pointer -foptimize-sibling-calls
Andi Kleen2aae9502007-07-21 17:10:01 +020057
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -030058$(vobjs): KBUILD_CFLAGS += $(CFL)
Andi Kleen2aae9502007-07-21 17:10:01 +020059
Andy Lutomirski6447fac2011-05-23 09:31:29 -040060#
61# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
62#
63CFLAGS_REMOVE_vdso-note.o = -pg
64CFLAGS_REMOVE_vclock_gettime.o = -pg
65CFLAGS_REMOVE_vgetcpu.o = -pg
66CFLAGS_REMOVE_vvar.o = -pg
67
Roland McGrath5b930492008-01-30 13:30:40 +010068targets += vdso-syms.lds
Roland McGrath6c3652e2008-01-30 13:30:42 +010069obj-$(VDSO64-y) += vdso-syms.lds
Roland McGrath5b930492008-01-30 13:30:40 +010070
71#
72# Match symbols in the DSO that look like VDSO*; produce a file of constants.
73#
74sed-vdsosym := -e 's/^00*/0/' \
Roland McGrathf2dbe032008-02-27 11:42:15 -080075 -e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p'
Roland McGrath5b930492008-01-30 13:30:40 +010076quiet_cmd_vdsosym = VDSOSYM $@
Roland McGrathf2dbe032008-02-27 11:42:15 -080077define cmd_vdsosym
78 $(NM) $< | LC_ALL=C sed -n $(sed-vdsosym) | LC_ALL=C sort > $@
79endef
Roland McGrath5b930492008-01-30 13:30:40 +010080
81$(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
82 $(call if_changed,vdsosym)
83
Roland McGrath0249c9c2008-01-30 13:30:42 +010084#
H. J. Lu1a21d4e2012-02-19 11:38:06 -080085# X32 processes use x32 vDSO to access 64bit kernel data.
86#
87# Build x32 vDSO image:
88# 1. Compile x32 vDSO as 64bit.
89# 2. Convert object files to x32.
90# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
91# so that it can reach 64bit address space with 64bit pointers.
92#
93
94targets += vdsox32-syms.lds
95obj-$(VDSOX32-y) += vdsox32-syms.lds
96
97CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
98VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
99 -Wl,-soname=linux-vdso.so.1 \
100 -Wl,-z,max-page-size=4096 \
101 -Wl,-z,common-page-size=4096
102
103vobjx32s-y := $(vobj64s:.o=-x32.o)
104vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
105
106# Convert 64bit object file to x32 for x32 vDSO.
107quiet_cmd_x32 = X32 $@
108 cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
109
110$(obj)/%-x32.o: $(obj)/%.o FORCE
111 $(call if_changed,x32)
112
113targets += vdsox32.so vdsox32.so.dbg vdsox32.lds $(vobjx32s-y)
114
115$(obj)/vdsox32.o: $(src)/vdsox32.S $(obj)/vdsox32.so
116
117$(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
118 $(call if_changed,vdso)
119
120#
Roland McGrath0249c9c2008-01-30 13:30:42 +0100121# Build multiple 32-bit vDSO images to choose from at boot time.
122#
Roland McGrath6c3652e2008-01-30 13:30:42 +0100123obj-$(VDSO32-y) += vdso32-syms.lds
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700124vdso32.so-$(VDSO32-y) += int80
Roland McGrath00f8b1b2008-01-30 13:30:43 +0100125vdso32.so-$(CONFIG_COMPAT) += syscall
Roland McGrath0249c9c2008-01-30 13:30:42 +0100126vdso32.so-$(VDSO32-y) += sysenter
127
Roland McGrath2c158262008-02-11 14:38:51 -0800128vdso32-images = $(vdso32.so-y:%=vdso32-%.so)
129
Roland McGrath0249c9c2008-01-30 13:30:42 +0100130CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
H. Peter Anvinde2a8cf2010-12-13 16:01:38 -0800131VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1
Roland McGrath0249c9c2008-01-30 13:30:42 +0100132
133# This makes sure the $(obj) subdirectory exists even though vdso32/
134# is not a kbuild sub-make subdirectory.
135override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
136
137targets += vdso32/vdso32.lds
Roland McGrath2c158262008-02-11 14:38:51 -0800138targets += $(vdso32-images) $(vdso32-images:=.dbg)
Roland McGrath0249c9c2008-01-30 13:30:42 +0100139targets += vdso32/note.o $(vdso32.so-y:%=vdso32/%.o)
140
Roland McGrath2c158262008-02-11 14:38:51 -0800141extra-y += $(vdso32-images)
Roland McGrath0249c9c2008-01-30 13:30:42 +0100142
Roland McGrath2c158262008-02-11 14:38:51 -0800143$(obj)/vdso32.o: $(vdso32-images:%=$(obj)/%)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100144
Roland McGrath0249c9c2008-01-30 13:30:42 +0100145KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
Roland McGrath2c158262008-02-11 14:38:51 -0800146$(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
147$(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32
Roland McGrath0249c9c2008-01-30 13:30:42 +0100148
Stefani Seibold7a59ed42014-03-17 23:22:09 +0100149KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
150KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
151KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
152KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
153KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
H. Peter Anvin008cc902014-03-17 23:22:12 +0100154KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
155KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
156KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
Stefani Seibold7a59ed42014-03-17 23:22:09 +0100157$(vdso32-images:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
158
Roland McGrath2c158262008-02-11 14:38:51 -0800159$(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
160 $(obj)/vdso32/vdso32.lds \
Stefani Seibold7a59ed42014-03-17 23:22:09 +0100161 $(obj)/vdso32/vclock_gettime.o \
Roland McGrath2c158262008-02-11 14:38:51 -0800162 $(obj)/vdso32/note.o \
163 $(obj)/vdso32/%.o
Roland McGrath0249c9c2008-01-30 13:30:42 +0100164 $(call if_changed,vdso)
165
166# Make vdso32-*-syms.lds from each image, and then make sure they match.
167# The only difference should be that some do not define VDSO32_SYSENTER_RETURN.
168
169targets += vdso32-syms.lds $(vdso32.so-y:%=vdso32-%-syms.lds)
170
171quiet_cmd_vdso32sym = VDSOSYM $@
172define cmd_vdso32sym
173 if LC_ALL=C sort -u $(filter-out FORCE,$^) > $(@D)/.tmp_$(@F) && \
174 $(foreach H,$(filter-out FORCE,$^),\
175 if grep -q VDSO32_SYSENTER_RETURN $H; \
176 then diff -u $(@D)/.tmp_$(@F) $H; \
177 else sed /VDSO32_SYSENTER_RETURN/d $(@D)/.tmp_$(@F) | \
178 diff -u - $H; fi &&) : ;\
179 then mv -f $(@D)/.tmp_$(@F) $@; \
180 else rm -f $(@D)/.tmp_$(@F); exit 1; \
181 fi
182endef
183
184$(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE
185 $(call if_changed,vdso32sym)
186
187#
188# The DSO images are built using a special linker script.
189#
190quiet_cmd_vdso = VDSO $@
191 cmd_vdso = $(CC) -nostdlib -o $@ \
192 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
H. Peter Anvin05d0b082010-06-18 14:36:26 -0700193 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
194 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
Roland McGrath0249c9c2008-01-30 13:30:42 +0100195
Sam Ravnborgf86fd302009-09-19 10:14:33 +0200196VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
Peter Oberparleiter7bf99fb2009-06-17 16:28:09 -0700197GCOV_PROFILE := n
Roland McGrath0249c9c2008-01-30 13:30:42 +0100198
199#
200# Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
201#
Roland McGrathf79eb832007-10-17 18:04:32 +0200202quiet_cmd_vdso_install = INSTALL $@
203 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
Roland McGrath0249c9c2008-01-30 13:30:42 +0100204$(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE
Roland McGrathf79eb832007-10-17 18:04:32 +0200205 @mkdir -p $(MODLIB)/vdso
206 $(call cmd,vdso_install)
207
Roland McGrath0249c9c2008-01-30 13:30:42 +0100208PHONY += vdso_install $(vdso-install-y)
209vdso_install: $(vdso-install-y)
Sam Ravnborgd531b4f2008-01-30 13:32:27 +0100210
211clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80*