blob: 5d179502a52cce8ee6b9f8f5fe643a35e0bf472a [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
6VDSO32-$(CONFIG_X86_32) := y
7VDSO32-$(CONFIG_COMPAT) := y
8
9vdso-install-$(VDSO64-y) += vdso.so
Roland McGrath2c158262008-02-11 14:38:51 -080010vdso-install-$(VDSO32-y) += $(vdso32-images)
Roland McGrath0249c9c2008-01-30 13:30:42 +010011
12
Andi Kleen2aae9502007-07-21 17:10:01 +020013# files to link into the vdso
Andy Lutomirski8c49d9a2011-05-23 09:31:24 -040014vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
Andi Kleen2aae9502007-07-21 17:10:01 +020015
16# files to link into kernel
Roland McGrath6c3652e2008-01-30 13:30:42 +010017obj-$(VDSO64-y) += vma.o vdso.o
Roland McGrathaf65d642008-01-30 13:30:43 +010018obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
Andi Kleen2aae9502007-07-21 17:10:01 +020019
20vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
21
22$(obj)/vdso.o: $(obj)/vdso.so
23
Roland McGrath2b9c97e2008-01-30 13:30:41 +010024targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
Andi Kleen2aae9502007-07-21 17:10:01 +020025
Sam Ravnborgd746d642007-11-12 20:14:19 +010026export CPPFLAGS_vdso.lds += -P -C
Andi Kleen2aae9502007-07-21 17:10:01 +020027
H. Peter Anvinde2a8cf2010-12-13 16:01:38 -080028VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
Andy Lutomirski7f79ad12011-07-13 09:24:12 -040029 -Wl,--no-undefined \
Roland McGrath16e48e72008-01-30 13:30:44 +010030 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
Andi Kleen2aae9502007-07-21 17:10:01 +020031
32$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
33
Roland McGrathf79eb832007-10-17 18:04:32 +020034$(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
Roland McGrath16e48e72008-01-30 13:30:44 +010035 $(call if_changed,vdso)
Andi Kleen2aae9502007-07-21 17:10:01 +020036
Roland McGrathf79eb832007-10-17 18:04:32 +020037$(obj)/%.so: OBJCOPYFLAGS := -S
38$(obj)/%.so: $(obj)/%.so.dbg FORCE
39 $(call if_changed,objcopy)
40
Andy Lutomirski6447fac2011-05-23 09:31:29 -040041#
42# Don't omit frame pointers for ease of userspace debugging, but do
43# optimize sibling calls.
44#
Roland McGrath8705a492008-04-14 12:19:30 -070045CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
Andy Lutomirski6447fac2011-05-23 09:31:29 -040046 $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
47 -fno-omit-frame-pointer -foptimize-sibling-calls
Andi Kleen2aae9502007-07-21 17:10:01 +020048
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -030049$(vobjs): KBUILD_CFLAGS += $(CFL)
Andi Kleen2aae9502007-07-21 17:10:01 +020050
Andy Lutomirski6447fac2011-05-23 09:31:29 -040051#
52# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
53#
54CFLAGS_REMOVE_vdso-note.o = -pg
55CFLAGS_REMOVE_vclock_gettime.o = -pg
56CFLAGS_REMOVE_vgetcpu.o = -pg
57CFLAGS_REMOVE_vvar.o = -pg
58
Roland McGrath5b930492008-01-30 13:30:40 +010059targets += vdso-syms.lds
Roland McGrath6c3652e2008-01-30 13:30:42 +010060obj-$(VDSO64-y) += vdso-syms.lds
Roland McGrath5b930492008-01-30 13:30:40 +010061
62#
63# Match symbols in the DSO that look like VDSO*; produce a file of constants.
64#
65sed-vdsosym := -e 's/^00*/0/' \
Roland McGrathf2dbe032008-02-27 11:42:15 -080066 -e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p'
Roland McGrath5b930492008-01-30 13:30:40 +010067quiet_cmd_vdsosym = VDSOSYM $@
Roland McGrathf2dbe032008-02-27 11:42:15 -080068define cmd_vdsosym
69 $(NM) $< | LC_ALL=C sed -n $(sed-vdsosym) | LC_ALL=C sort > $@
70endef
Roland McGrath5b930492008-01-30 13:30:40 +010071
72$(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
73 $(call if_changed,vdsosym)
74
Roland McGrath0249c9c2008-01-30 13:30:42 +010075#
76# Build multiple 32-bit vDSO images to choose from at boot time.
77#
Roland McGrath6c3652e2008-01-30 13:30:42 +010078obj-$(VDSO32-y) += vdso32-syms.lds
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -070079vdso32.so-$(VDSO32-y) += int80
Roland McGrath00f8b1b2008-01-30 13:30:43 +010080vdso32.so-$(CONFIG_COMPAT) += syscall
Roland McGrath0249c9c2008-01-30 13:30:42 +010081vdso32.so-$(VDSO32-y) += sysenter
82
Roland McGrath2c158262008-02-11 14:38:51 -080083vdso32-images = $(vdso32.so-y:%=vdso32-%.so)
84
Roland McGrath0249c9c2008-01-30 13:30:42 +010085CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
H. Peter Anvinde2a8cf2010-12-13 16:01:38 -080086VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1
Roland McGrath0249c9c2008-01-30 13:30:42 +010087
88# This makes sure the $(obj) subdirectory exists even though vdso32/
89# is not a kbuild sub-make subdirectory.
90override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
91
92targets += vdso32/vdso32.lds
Roland McGrath2c158262008-02-11 14:38:51 -080093targets += $(vdso32-images) $(vdso32-images:=.dbg)
Roland McGrath0249c9c2008-01-30 13:30:42 +010094targets += vdso32/note.o $(vdso32.so-y:%=vdso32/%.o)
95
Roland McGrath2c158262008-02-11 14:38:51 -080096extra-y += $(vdso32-images)
Roland McGrath0249c9c2008-01-30 13:30:42 +010097
Roland McGrath2c158262008-02-11 14:38:51 -080098$(obj)/vdso32.o: $(vdso32-images:%=$(obj)/%)
Roland McGrath6c3652e2008-01-30 13:30:42 +010099
Roland McGrath0249c9c2008-01-30 13:30:42 +0100100KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
Roland McGrath2c158262008-02-11 14:38:51 -0800101$(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
102$(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32
Roland McGrath0249c9c2008-01-30 13:30:42 +0100103
Roland McGrath2c158262008-02-11 14:38:51 -0800104$(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
105 $(obj)/vdso32/vdso32.lds \
106 $(obj)/vdso32/note.o \
107 $(obj)/vdso32/%.o
Roland McGrath0249c9c2008-01-30 13:30:42 +0100108 $(call if_changed,vdso)
109
110# Make vdso32-*-syms.lds from each image, and then make sure they match.
111# The only difference should be that some do not define VDSO32_SYSENTER_RETURN.
112
113targets += vdso32-syms.lds $(vdso32.so-y:%=vdso32-%-syms.lds)
114
115quiet_cmd_vdso32sym = VDSOSYM $@
116define cmd_vdso32sym
117 if LC_ALL=C sort -u $(filter-out FORCE,$^) > $(@D)/.tmp_$(@F) && \
118 $(foreach H,$(filter-out FORCE,$^),\
119 if grep -q VDSO32_SYSENTER_RETURN $H; \
120 then diff -u $(@D)/.tmp_$(@F) $H; \
121 else sed /VDSO32_SYSENTER_RETURN/d $(@D)/.tmp_$(@F) | \
122 diff -u - $H; fi &&) : ;\
123 then mv -f $(@D)/.tmp_$(@F) $@; \
124 else rm -f $(@D)/.tmp_$(@F); exit 1; \
125 fi
126endef
127
128$(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE
129 $(call if_changed,vdso32sym)
130
131#
132# The DSO images are built using a special linker script.
133#
134quiet_cmd_vdso = VDSO $@
135 cmd_vdso = $(CC) -nostdlib -o $@ \
136 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
H. Peter Anvin05d0b082010-06-18 14:36:26 -0700137 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
138 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
Roland McGrath0249c9c2008-01-30 13:30:42 +0100139
Sam Ravnborgf86fd302009-09-19 10:14:33 +0200140VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
Peter Oberparleiter7bf99fb2009-06-17 16:28:09 -0700141GCOV_PROFILE := n
Roland McGrath0249c9c2008-01-30 13:30:42 +0100142
143#
144# Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
145#
Roland McGrathf79eb832007-10-17 18:04:32 +0200146quiet_cmd_vdso_install = INSTALL $@
147 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
Roland McGrath0249c9c2008-01-30 13:30:42 +0100148$(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE
Roland McGrathf79eb832007-10-17 18:04:32 +0200149 @mkdir -p $(MODLIB)/vdso
150 $(call cmd,vdso_install)
151
Roland McGrath0249c9c2008-01-30 13:30:42 +0100152PHONY += vdso_install $(vdso-install-y)
153vdso_install: $(vdso-install-y)
Sam Ravnborgd531b4f2008-01-30 13:32:27 +0100154
155clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80*