Back to home page

LXR

 
 

    


0001 #
0002 # Building vDSO images for x86.
0003 #
0004 
0005 KBUILD_CFLAGS += $(DISABLE_LTO)
0006 KASAN_SANITIZE                  := n
0007 UBSAN_SANITIZE                  := n
0008 OBJECT_FILES_NON_STANDARD       := y
0009 
0010 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
0011 KCOV_INSTRUMENT         := n
0012 
0013 VDSO64-$(CONFIG_X86_64)         := y
0014 VDSOX32-$(CONFIG_X86_X32_ABI)   := y
0015 VDSO32-$(CONFIG_X86_32)         := y
0016 VDSO32-$(CONFIG_IA32_EMULATION) := y
0017 
0018 # files to link into the vdso
0019 vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
0020 
0021 # files to link into kernel
0022 obj-y                           += vma.o
0023 OBJECT_FILES_NON_STANDARD_vma.o := n
0024 
0025 # vDSO images to build
0026 vdso_img-$(VDSO64-y)            += 64
0027 vdso_img-$(VDSOX32-y)           += x32
0028 vdso_img-$(VDSO32-y)            += 32
0029 
0030 obj-$(VDSO32-y)                 += vdso32-setup.o
0031 
0032 vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
0033 
0034 $(obj)/vdso.o: $(obj)/vdso.so
0035 
0036 targets += vdso.lds $(vobjs-y)
0037 
0038 # Build the vDSO image C files and link them in.
0039 vdso_img_objs := $(vdso_img-y:%=vdso-image-%.o)
0040 vdso_img_cfiles := $(vdso_img-y:%=vdso-image-%.c)
0041 vdso_img_sodbg := $(vdso_img-y:%=vdso%.so.dbg)
0042 obj-y += $(vdso_img_objs)
0043 targets += $(vdso_img_cfiles)
0044 targets += $(vdso_img_sodbg)
0045 .SECONDARY: $(vdso_img-y:%=$(obj)/vdso-image-%.c) \
0046         $(vdso_img-y:%=$(obj)/vdso%.so)
0047 
0048 export CPPFLAGS_vdso.lds += -P -C
0049 
0050 VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
0051                         -Wl,--no-undefined \
0052                         -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
0053                         $(DISABLE_LTO)
0054 
0055 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
0056         $(call if_changed,vdso)
0057 
0058 HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi 
0059 hostprogs-y                     += vdso2c
0060 
0061 quiet_cmd_vdso2c = VDSO2C  $@
0062 define cmd_vdso2c
0063         $(obj)/vdso2c $< $(<:%.dbg=%) $@
0064 endef
0065 
0066 $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
0067         $(call if_changed,vdso2c)
0068 
0069 #
0070 # Don't omit frame pointers for ease of userspace debugging, but do
0071 # optimize sibling calls.
0072 #
0073 CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
0074        $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
0075        -fno-omit-frame-pointer -foptimize-sibling-calls \
0076        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
0077 
0078 $(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
0079 
0080 #
0081 # vDSO code runs in userspace and -pg doesn't help with profiling anyway.
0082 #
0083 CFLAGS_REMOVE_vdso-note.o = -pg
0084 CFLAGS_REMOVE_vclock_gettime.o = -pg
0085 CFLAGS_REMOVE_vgetcpu.o = -pg
0086 CFLAGS_REMOVE_vvar.o = -pg
0087 
0088 #
0089 # X32 processes use x32 vDSO to access 64bit kernel data.
0090 #
0091 # Build x32 vDSO image:
0092 # 1. Compile x32 vDSO as 64bit.
0093 # 2. Convert object files to x32.
0094 # 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
0095 # so that it can reach 64bit address space with 64bit pointers.
0096 #
0097 
0098 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
0099 VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
0100                            -Wl,-soname=linux-vdso.so.1 \
0101                            -Wl,-z,max-page-size=4096 \
0102                            -Wl,-z,common-page-size=4096
0103 
0104 # 64-bit objects to re-brand as x32
0105 vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y))
0106 
0107 # x32-rebranded versions
0108 vobjx32s-y := $(vobjs64-for-x32:.o=-x32.o)
0109 
0110 # same thing, but in the output directory
0111 vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
0112 
0113 # Convert 64bit object file to x32 for x32 vDSO.
0114 quiet_cmd_x32 = X32     $@
0115       cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
0116 
0117 $(obj)/%-x32.o: $(obj)/%.o FORCE
0118         $(call if_changed,x32)
0119 
0120 targets += vdsox32.lds $(vobjx32s-y)
0121 
0122 $(obj)/%.so: OBJCOPYFLAGS := -S
0123 $(obj)/%.so: $(obj)/%.so.dbg
0124         $(call if_changed,objcopy)
0125 
0126 $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
0127         $(call if_changed,vdso)
0128 
0129 CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
0130 VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
0131 
0132 # This makes sure the $(obj) subdirectory exists even though vdso32/
0133 # is not a kbuild sub-make subdirectory.
0134 override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
0135 
0136 targets += vdso32/vdso32.lds
0137 targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
0138 targets += vdso32/vclock_gettime.o
0139 
0140 KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO
0141 $(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
0142 $(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32
0143 
0144 KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
0145 KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
0146 KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
0147 KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
0148 KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
0149 KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
0150 KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
0151 KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
0152 KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
0153 KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
0154 $(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
0155 
0156 $(obj)/vdso32.so.dbg: FORCE \
0157                       $(obj)/vdso32/vdso32.lds \
0158                       $(obj)/vdso32/vclock_gettime.o \
0159                       $(obj)/vdso32/note.o \
0160                       $(obj)/vdso32/system_call.o \
0161                       $(obj)/vdso32/sigreturn.o
0162         $(call if_changed,vdso)
0163 
0164 #
0165 # The DSO images are built using a special linker script.
0166 #
0167 quiet_cmd_vdso = VDSO    $@
0168       cmd_vdso = $(CC) -nostdlib -o $@ \
0169                        $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
0170                        -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
0171                  sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
0172 
0173 VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \
0174         $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
0175 GCOV_PROFILE := n
0176 
0177 #
0178 # Install the unstripped copies of vdso*.so.  If our toolchain supports
0179 # build-id, install .build-id links as well.
0180 #
0181 quiet_cmd_vdso_install = INSTALL $(@:install_%=%)
0182 define cmd_vdso_install
0183         cp $< "$(MODLIB)/vdso/$(@:install_%=%)"; \
0184         if readelf -n $< |grep -q 'Build ID'; then \
0185           buildid=`readelf -n $< |grep 'Build ID' |sed -e 's/^.*Build ID: \(.*\)$$/\1/'`; \
0186           first=`echo $$buildid | cut -b-2`; \
0187           last=`echo $$buildid | cut -b3-`; \
0188           mkdir -p "$(MODLIB)/vdso/.build-id/$$first"; \
0189           ln -sf "../../$(@:install_%=%)" "$(MODLIB)/vdso/.build-id/$$first/$$last.debug"; \
0190         fi
0191 endef
0192 
0193 vdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%)
0194 
0195 $(MODLIB)/vdso: FORCE
0196         @mkdir -p $(MODLIB)/vdso
0197 
0198 $(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso
0199         $(call cmd,vdso_install)
0200 
0201 PHONY += vdso_install $(vdso_img_insttargets)
0202 vdso_install: $(vdso_img_insttargets)
0203 
0204 clean-files := vdso32.so vdso32.so.dbg vdso64* vdso-image-*.c vdsox32.so*