vDSO for ppc64 : Preliminary release #3
Subsystems (2)
Here's a new drop of the vDSO, patch for ppc64 against the current bk.
Lots of changes since last version. It actually provides a working .so to userland that glibc can use provided it's patched properly (see note below). The only functions provided at this point are the 32 and 64 bits versions of the fully-userland gettimeofday in addition to the signal trampolines. I'm now working on adding more.
The vDSO is no longer above the stack. It's now mapped at 0x100000, still using a real VMA though, read only by default but ptrace and mprotect can be used. (gdb breakpoints do work).
Many thanks to Alan Modra for his help at various stages of the process.
What is missing is:
- more functions, especially the cpu-specific ones. on the todo list for those are: uname, get_syscall_bitmap() (arjan suggestion), cache sync (dcache/icache flush), memcpy, memset, atomics & locks. Note that we may do an early release with not all the functions in.
- cfi infos for the signal trampoline (beeing done)
- definition of a phdr allowing userland apps to request the vdso to either not exist or be mapped at a different address
- possible issues with Makefiles to be ironed out
About glibc:
Without glibc changes, the vdso patch will give you the signal trampolines out of the stack at least. Currently, there are several changes required to glibc, I don't have a clean patch to provide yet and it's still not clear what Ulrich Drepper will accept or not.
- First, we need to enable using a vdso when available on ppc &
ppc64. This is rather simple, I expect Ulrich to commit a patch for that soon. The only issue is that we don't use the vdso for syscalls, so some stuff related to that doesn't exist on ppc and compilation fails in a couple of places without some changes for which Ulrich will find the right solution I hope.
- There seem to be a small bug in the ld.so code that deals with the
vdso regarding the way it calculates the map & text size, I'll have a patch for that.
- The current glibc code for dealing with vdso's is not completely
appropriate for ppc64 in particular since we do need relocations to be performed on the OPD section (thanks mprotect + COW, it actually works) if the library is ever mapped at a differnet address than it's native 0x100000 (via the new phdr for example).
The current glibc code forces l_relocated to 1 for all vdso's (which is fine for archs without need to relocate function descriptors). It is not clear what to do here. I would like the code to set l_relocated to 1 only if l_addr is 0 (native address) but that _might_ trigger some overhead of checking relocations on archs that don't care. We may want to add an arch macro hook in there, maybe a DL_POST_PROCESS_VDSO or so ...
- We need to "hook" some glibc functions to call the vDSO for things
that are provided by. I'll let glibc experts decide how to do that (for example have it call the vdso gettimeofday instead of the syscall, etc...)
In the meantime, here's the latest drop, comments welcome:
arch/ppc64/kernel/Makefile +1 -1
@@ -11,7 +11,7 @@ udbg.o binfmt_elf32.o sys_ppc32.o ioctl32.o \ ptrace32.o signal32.o rtc.o init_task.o \ lmb.o cputable.o cpu_setup_power4.o idle_power4.o \ - iommu.o sysfs.o vio.o + iommu.o sysfs.o vio.o vdso.o obj-$(CONFIG_PPC_OF) += of_device.o
arch/ppc64/kernel/asm-offsets.c +18 -0
@@ -22,6 +22,7 @@#include <linux/types.h> #include <linux/mman.h> #include <linux/mm.h> +#include <linux/time.h> #include <linux/hardirq.h> #include <asm/io.h> #include <asm/page.h>
@@ -36,6 +37,8 @@#include <asm/prom.h> #include <asm/rtas.h> #include <asm/cputable.h> +#include <asm/systemcfg.h> +#include <asm/compat.h> #define DEFINE (sym, val) \ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
@@ -170,5 +173,20 @@DEFINE (CPU_SPEC_FEATURES , offsetof(struct cpu_spec , cpu_features));DEFINE (CPU_SPEC_SETUP , offsetof(struct cpu_spec , cpu_setup)); +/* systemcfg offsets for use by vdso */ +DEFINE (CFG_TB_ORIG_STAMP , offsetof(struct systemcfg , tb_orig_stamp)); +DEFINE (CFG_TB_TICKS_PER_SEC , offsetof(struct systemcfg , tb_ticks_per_sec)); +DEFINE (CFG_TB_TO_XS , offsetof(struct systemcfg , tb_to_xs)); +DEFINE (CFG_STAMP_XSEC , offsetof(struct systemcfg , stamp_xsec)); +DEFINE (CFG_TB_UPDATE_COUNT , offsetof(struct systemcfg , tb_update_count)); +DEFINE (CFG_TZ_MINUTEWEST , offsetof(struct systemcfg , tz_minuteswest)); +DEFINE (CFG_TZ_DSTTIME , offsetof(struct systemcfg , tz_dsttime)); +DEFINE (TVAL64_TV_SEC , offsetof(struct timeval , tv_sec)); +DEFINE (TVAL64_TV_USEC , offsetof(struct timeval , tv_usec)); +DEFINE (TVAL32_TV_SEC , offsetof(struct compat_timeval , tv_sec)); +DEFINE (TVAL32_TV_USEC , offsetof(struct compat_timeval , tv_usec)); +DEFINE (TZONE_TZ_MINWEST , offsetof(struct timezone , tz_minuteswest)); +DEFINE (TZONE_TZ_DSTTIME , offsetof(struct timezone , tz_dsttime)); +return 0 ; }
arch/ppc64/kernel/signal.c +9 -5
@@ -34,6 +34,7 @@#include <asm/ppcdebug.h> #include <asm/unistd.h> #include <asm/cacheflush.h> +#include <asm/vdso.h> #define DEBUG_SIG 0
@@ -412,10 +413,14 @@ goto badframe;/* Set up to return from userspace. */ - err |=setup_trampoline (__NR_rt_sigreturn, &frame->tramp[0 ]); -if (err) - goto badframe; - +if (vdso64_rt_sigtramp && current->thread.vdso_base) { + regs->link = current->thread.vdso_base + vdso64_rt_sigtramp; + }else { + err |=setup_trampoline (__NR_rt_sigreturn, &frame->tramp[0 ]); +if (err) + goto badframe; + regs->link = (unsigned long ) &frame->tramp[0 ]; + } funct_desc_ptr = (func_descr_t __user *) ka->sa.sa_handler;/* Allocate a dummy caller frame for the signal handler. */
@@ -424,7 +429,6 @@/* Set up "regs" so we "return" to the signal handler. */ err |=get_user (regs->nip, &funct_desc_ptr->entry); - regs->link = (unsigned long ) &frame->tramp[0 ]; regs->gpr[1 ] = newsp; err |=get_user (regs->gpr[2 ], &funct_desc_ptr->toc); regs->gpr[3 ] = signr;
arch/ppc64/kernel/signal32.c +20 -7
@@ -30,6 +30,7 @@#include <asm/ppcdebug.h> #include <asm/unistd.h> #include <asm/cacheflush.h> +#include <asm/vdso.h> #define DEBUG_SIG 0
@@ -677,18 +678,24 @@/* Save user registers on the stack */ frame = &rt_sf->uc.uc_mcontext; -if (save_user_regs (regs, frame, __NR_rt_sigreturn)) - goto badframe; -if (put_user (regs->gpr[1 ], (unsigned long __user *)newsp)) goto badframe; + +if (vdso32_rt_sigtramp && current->thread.vdso_base) { +if (save_user_regs (regs, frame,0 )) + goto badframe; + regs->link = current->thread.vdso_base + vdso32_rt_sigtramp; + }else { +if (save_user_regs (regs, frame, __NR_rt_sigreturn)) + goto badframe; + regs->link = (unsigned long ) frame->tramp; + } regs->gpr[1 ] = (unsigned long ) newsp; regs->gpr[3 ] = sig; regs->gpr[4 ] = (unsigned long ) &rt_sf->info; regs->gpr[5 ] = (unsigned long ) &rt_sf->uc; regs->gpr[6 ] = (unsigned long ) rt_sf; regs->nip = (unsigned long ) ka->sa.sa_handler; - regs->link = (unsigned long ) frame->tramp; regs->trap =0 ; regs->result =0 ;
@@ -842,8 +849,15 @@ || __put_user(sig, &sc->signal)) goto badframe; -if (save_user_regs (regs, &frame->mctx, __NR_sigreturn)) - goto badframe; +if (vdso32_sigtramp && current->thread.vdso_base) { +if (save_user_regs (regs, &frame->mctx,0 )) + goto badframe; + regs->link = current->thread.vdso_base + vdso32_sigtramp; + }else { +if (save_user_regs (regs, &frame->mctx, __NR_sigreturn)) + goto badframe; + regs->link = (unsigned long ) frame->mctx.tramp; + }if (put_user (regs->gpr[1 ], (unsigned long __user *)newsp)) goto badframe;
@@ -851,7 +865,6 @@ regs->gpr[3 ] = sig; regs->gpr[4 ] = (unsigned long ) sc; regs->nip = (unsigned long ) ka->sa.sa_handler; - regs->link = (unsigned long ) frame->mctx.tramp; regs->trap =0 ; regs->result =0 ;
arch/ppc64/kernel/smp.c +1 -1
@@ -784,7 +784,7 @@* For now we leave it which means the time can be some * number of msecs off until someone does a settimeofday() */ - do_gtod.tb_orig_stamp = tb_last_stamp; + do_gtod.varp->tb_orig_stamp = tb_last_stamp; systemcfg->tb_orig_stamp = tb_last_stamp;#endif
arch/ppc64/kernel/time.c +54 -6
109 lines not on this page · raw message
arch/ppc64/kernel/vdso.c new file +468 -0
468 lines not on this page · raw message
arch/ppc64/kernel/vdso32/Makefile new file +51 -0
51 lines not on this page · raw message
arch/ppc64/kernel/vdso32/datapage.S new file +28 -0
@@ -0,0 +1,28 @@ +#include <linux/config.h> +#include <asm/processor.h> +#include <asm/ppc_asm.h> +#include <asm/vdso.h> + +/* HIDE THIS ONE FROM USERSPACE */ + + .text +V_FUNCTION_BEGIN(__v_get_datapage) + /* We don't want that exposed or overridable as we want other objects + * to be able to bl directly to here + */ + .protected __v_get_datapage + + mflr r0 + .cfi_register lr,r0 + + bcl 20,31,1f + .global __v_datapage_offset; +__v_datapage_offset: + .long 0 +1: + mflr r4 + lwz r3,0(r4) + add r3,r3,r4 + mtlr r0 + blr +V_FUNCTION_END(__v_get_datapage)
arch/ppc64/kernel/vdso32/gettimeofday.S new file +138 -0
138 lines not on this page · raw message
arch/ppc64/kernel/vdso32/sigtramp.S new file +18 -0
@@ -0,0 +1,18 @@ +#include <linux/config.h> +#include <asm/processor.h> +#include <asm/ppc_asm.h> +#include <asm/unistd.h> +#include <asm/vdso.h> + + .text + +V_FUNCTION_BEGIN(__v_sigtramp32) + li r0,__NR_sigreturn + sc +V_FUNCTION_END(__v_sigtramp32) + +V_FUNCTION_BEGIN(__v_sigtramp_rt32) + li r0,__NR_rt_sigreturn + sc +V_FUNCTION_END(__v_sigtramp_rt32) +
arch/ppc64/kernel/vdso32/vdso32.lds.S new file +91 -0
91 lines not on this page · raw message
arch/ppc64/kernel/vdso32/vdso32_wrapper.S new file +12 -0
@@ -0,0 +1,12 @@ +#include <linux/init.h> + + .section ".data" + + .globl vdso32_start, vdso32_end + .balign 4096 +vdso32_start: + .incbin "arch/ppc64/kernel/vdso32/vdso32.so" + .balign 4096 +vdso32_end: + + .previous
arch/ppc64/kernel/vdso64/Makefile new file +38 -0
@@ -0,0 +1,38 @@ +# List of files in the vdso, has to be asm only for now + +src-vdso64 = sigtramp.S gettimeofday.S datapage.S + +# Build rules + +obj-vdso64 := $(addsuffix .o, $(basename $(src-vdso64))) +obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) +src-vdso64 := $(addprefix $(src)/, $(src-vdso64)) + +VDSO64_CFLAGS := -shared -s -fno-common -Iinclude -fno-builtin -nostdlib +VDSO64_CFLAGS += -Wl,-soname=linux-vdso64.so.1 +VDSO64_AFLAGS := -D__ASSEMBLY__ -D__KERNEL__ -D__VDSO64__ -s -nostdinc -Iinclude + +obj-y += vdso64_wrapper.o +extra-y += vdso64.lds +CPPFLAGS_vdso64.lds += -P -C -U$(ARCH) + +# Force dependency (incbin is bad) +$(obj)/vdso64_wrapper.o : $(obj)/vdso64.so + +# link rule for the .so file, .lds has to be first +$(obj)/vdso64.so: $(src)/vdso64.lds $(obj-vdso64) + $(call if_changed,vdso64ld) + +# assembly rules for the .S files +# This is probably wrong with split src & obj trees +$(obj-vdso64): %.o: %.S + $(call if_changed_dep,vdso64as) + +# actual build commands +quiet_cmd_vdso64ld = VDSO64L $@ + cmd_vdso64ld = $(CC) -Wp,-MD,$(depfile) $(VDSO64_CFLAGS) \ + -Wl,-T $^ -o $@ +quiet_cmd_vdso64as = VDSO64A $@ + cmd_vdso64as = $(CC) -Wp,-MD,$(depfile) $(VDSO64_AFLAGS) -c -o $@ $^ + +targets += vdso64.so
arch/ppc64/kernel/vdso64/datapage.S new file +28 -0
@@ -0,0 +1,28 @@ +#include <linux/config.h> +#include <asm/processor.h> +#include <asm/ppc_asm.h> +#include <asm/vdso.h> + +/* HIDE THIS ONE FROM USERSPACE */ + + .text +V_FUNCTION_BEGIN(__v_get_datapage) + /* We don't want that exposed or overridable as we want other objects + * to be able to bl directly to here + */ + .protected __v_get_datapage + + mflr r0 + .cfi_register lr,r0 + + bcl 20,31,1f + .global __v_datapage_offset; +__v_datapage_offset: + .long 0 +1: + mflr r4 + lwz r3,0(r4) + add r3,r3,r4 + mtlr r0 + blr +V_FUNCTION_END(__v_get_datapage)
arch/ppc64/kernel/vdso64/gettimeofday.S new file +88 -0
88 lines not on this page · raw message
arch/ppc64/kernel/vdso64/sigtramp.S new file +14 -0
@@ -0,0 +1,14 @@ +#include <linux/config.h> +#include <asm/processor.h> +#include <asm/ppc_asm.h> +#include <asm/unistd.h> +#include <asm/vdso.h> + + .text + +V_FUNCTION_BEGIN(__v_sigtramp_rt64) + addi r1, r1, __SIGNAL_FRAMESIZE + li r0,__NR_rt_sigreturn + sc +V_FUNCTION_END(__v_sigtramp_rt64) +
arch/ppc64/kernel/vdso64/vdso64.lds.S new file +93 -0
93 lines not on this page · raw message
arch/ppc64/kernel/vdso64/vdso64_wrapper.S new file +12 -0
@@ -0,0 +1,12 @@ +#include <linux/init.h> + + .section ".data" + + .globl vdso64_start, vdso64_end + .balign 4096 +vdso64_start: + .incbin "arch/ppc64/kernel/vdso64/vdso64.so" + .balign 4096 +vdso64_end: + + .previous
arch/ppc64/mm/init.c +3 -0
@@ -61,6 +61,7 @@#include <asm/system.h> #include <asm/iommu.h> #include <asm/abs_addr.h> +#include <asm/vdso.h> struct mmu_context_queue_t mmu_context_queue;
@@ -706,6 +707,8 @@#ifdef CONFIG_PPC_ISERIES iommu_vio_init ();#endif +/* Initialize the vDSO */ +vdso_init (); }/*
fs/binfmt_elf.c +8 -0
@@ -716,6 +716,14 @@ goto out_free_dentry; } +#ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES + retval =arch_setup_additional_pages (bprm, executable_stack); +if (retval <0 ) { +send_sig (SIGKILL , current,0 ); + goto out_free_dentry; + } +#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */ + current->mm->start_stack = bprm->p;/* Now we do a little grungy work by mmaping the ELF image into
include/asm-ppc64/a.out.h +4 -7
@@ -30,14 +30,11 @@#ifdef __KERNEL__ -#define STACK_TOP_USER64 (TASK_SIZE_USER64) +#define STACK_TOP_USER64 TASK_SIZE_USER64 +#define STACK_TOP_USER32 TASK_SIZE_USER32 -/* Give 32-bit user space a full 4G address space to live in. */ -#define STACK_TOP_USER32 (TASK_SIZE_USER32) - -#define STACK_TOP ((test_thread_flag(TIF_32BIT) || \ - (ppcdebugset(PPCDBG_BINFMT_32ADDR))) ? \ - STACK_TOP_USER32 : STACK_TOP_USER64) +#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ + STACK_TOP_USER32 : STACK_TOP_USER64)#endif /* __KERNEL__ */
include/asm-ppc64/elf.h +12 -0
@@ -238,10 +238,20 @@/* A special ignored type value for PPC, for glibc compatibility. */ #define AT_IGNOREPPC 22 +/* The vDSO location. We have to use the same value as x86 for glibc's +* sake :-) +*/ +#define AT_SYSINFO_EHDR 33 +extern int dcache_bsize;extern int icache_bsize;extern int ucache_bsize; +/* We do have an arch_setup_additional_pages for vDSO matters */ +#define ARCH_HAS_SETUP_ADDITIONAL_PAGES +struct linux_binprm ; +extern int arch_setup_additional_pages (struct linux_binprm *bprm,int executable_stack); +/* * The requirements here are: * - keep the final alignment of sp (sp & 0xf)
@@ -260,6 +270,8 @@NEW_AUX_ENT (AT_DCACHEBSIZE , dcache_bsize); \NEW_AUX_ENT (AT_ICACHEBSIZE , icache_bsize); \NEW_AUX_ENT (AT_UCACHEBSIZE , ucache_bsize); \ +/* vDSO base */ \ +NEW_AUX_ENT (AT_SYSINFO_EHDR , current->thread.vdso_base); \ }while (0 )/* PowerPC64 relocations defined by the ABIs */
include/asm-ppc64/page.h +5 -0
@@ -183,6 +183,11 @@extern int page_is_ram (unsigned long pfn); +/* We do define AT_SYSINFO_EHDR but don't use the gate mecanism */ +#define CONFIG_ARCH_GATE_AREA 1 +#define get_gate_vma (tsk) (NULL) +#define in_gate_area (task, addr) (0) +#endif /* __ASSEMBLY__ */ #ifdef MODULE
include/asm-ppc64/processor.h +4 -3
@@ -518,8 +518,8 @@/* This decides where the kernel will search for a free chunk of vm * space during mmap's. */ -#define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(STACK_TOP_USER32 / 4)) -#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(STACK_TOP_USER64 / 4)) +#define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4)) +#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4))#define TASK_UNMAPPED_BASE ((test_thread_flag(TIF_32BIT)||(ppcdebugset(PPCDBG_BINFMT_32ADDR))) ? \ TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
@@ -536,7 +536,8 @@double fpr[32 ];/* Complete floating point set */ unsigned long fpscr;/* Floating point status (plus pad) */ unsigned long fpexc_mode;/* Floating-point exception mode */ -unsigned long pad[3 ];/* was saved_msr, saved_softe */ +unsigned long pad[2 ];/* was saved_msr, saved_softe */ +unsigned long vdso_base;/* base of the vDSO library */ #ifdef CONFIG_ALTIVEC /* Complete AltiVec register set */ vector128 vr[32] __attribute((aligned(16)));
include/asm-ppc64/time.h +1 -1
@@ -43,10 +43,10 @@struct gettimeofday_vars {unsigned long tb_to_xs;unsigned long stamp_xsec; +unsigned long tb_orig_stamp; };struct gettimeofday_struct { -unsigned long tb_orig_stamp;unsigned long tb_ticks_per_sec;struct gettimeofday_vars vars[2 ];struct gettimeofday_vars *volatile varp;
include/asm-ppc64/vdso.h new file +60 -0
60 lines not on this page · raw message
arch/ppc64/kernel/vdso.c line 208
Quoted 8 lines · Benjamin Herrenschmidt
arch/ppc64/kernel/vdso.c new file +8
-0+/* +* pick a base address for the vDSO in process space. We have a default +* base of 1Mb on which we had a random offset up to 1Mb. +* XXX: Add possibility for a program header to specify that location +*/ + current->thread.vdso_base =0x00100000 + +0xaa000 ;/* + ((unsigned long)vma & 0x000ff000); */ +
Note that the above is a hack putting the vDSO at 0x1aa000 instead of it's native link address of 0x100000 to test that it works ;)
Ben.
Quoted 7 lines · Benjamin Herrenschmidt
- The current glibc code for dealing with vdso's is not completely
appropriate for ppc64 in particular since we do need relocations to be performed on the OPD section (thanks mprotect + COW, it actually works) if the library is ever mapped at a differnet address than it's native0x100000(via the new phdr for example).
The current glibc code forcesl_relocatedto 1 for all vdso's (which is fine for archs without need to relocate function descriptors).
That is on purpose, even if vDSO location is randomized (e.g. on IA-32), no relocations should happen, so that the vDSO can be shared (unless written into by the debugger, that is). ld.so knows how to deal with .dynamic section relocation of vDSOs.
Jakub
Quoted 4 lines · Jakub Jelinek
That is on purpose, even if vDSO location is randomized (e.g. on IA-32), no relocations should happen, so that the vDSO can be shared (unless written into by the debugger, that is). ld.so knows how to deal with .dynamic section relocation of vDSOs.
On 64-bit architectures which use procedure descriptors, the descriptors will have to be relocated (unless you or Alan can come up with some toolchain or ld.so magic or something). But the descriptors are in the data section rather than the text, of course.
Paul.
Quoted 11 lines · Paul Mackerras
Quoted 4 lines · Jakub Jelinek
That is on purpose, even if vDSO location is randomized (e.g. on IA-32), no relocations should happen, so that the vDSO can be shared (unless written into by the debugger, that is). ld.so knows how to deal with .dynamic section relocation of vDSOs.
On 64-bit architectures which use procedure descriptors, the descriptors will have to be relocated (unless you or Alan can come up with some toolchain or ld.so magic or something). But the descriptors are in the data section rather than the text, of course.
In the case of the ppc vDSO, there is no .data section, the descriptors are in the .opd section along with the .text, but that isn't a problem. That means that 1 page of vDSO text will be COW'ed for the few apps that request a different address (again, unless we want randomizing). The vDSO also has a special data page that _has_ to be shared, but it's separate and doesn't overlap the actual .so pages so it shouldn't be affected by a possible relocation.
Of course, unless somebody comes up with a clever trick to avoid those altogether...
Ben.
Quoted 9 lines · Paul Mackerras
Quoted 4 lines · Jakub Jelinek
That is on purpose, even if vDSO location is randomized (e.g. on IA-32), no relocations should happen, so that the vDSO can be shared (unless written into by the debugger, that is). ld.so knows how to deal with .dynamic section relocation of vDSOs.
On 64-bit architectures which use procedure descriptors, the descriptors will have to be relocated (unless you or Alan can come up
s/64-bit architectures which use procedure descriptors/ppc64/ (IA-64 and I guess hppa64 as well certainly don't need that).
Quoted 2 lines
with some toolchain or ld.so magic or something). But the descriptors are in the data section rather than the text, of course.
None of the assembly routines seem to use toc register, so if the functions exported from the library have special calling conventions (glibc would use them from inline assembly wrappers anyway), you can get away without .opd. vDSO is not in global search scope anyway, so applications can't call symbols from it anyway unless doing lots of magic.
Jakub
Quoted 9 lines
Quoted 3 lines
with some toolchain or ld.so magic or something). But the descriptors are in the data section rather than the text, of course.
None of the assembly routines seem to use toc register, so if the functions exported from the library have special calling conventions (glibc would use them from inline assembly wrappers anyway), you can get away without .opd. vDSO is not in global search scope anyway, so applications can't call symbols from it anyway unless doing lots of magic.
Ok. I'm linking to the vdso directly from test apps at the moment but that will die as soon as glibc has been adapted. Just let me know what you prefer. I can keep the descriptors as-is and glibc would take care of offset'ing properly when calling them, or I could try to find some way to export different symbols like Ulrich suggested... whatever you prefer for the glibc side.
Ben.
Quoted 9 lines · Jakub Jelinek
Quoted 7 lines · Benjamin Herrenschmidt
- The current glibc code for dealing with vdso's is not completely
appropriate for ppc64 in particular since we do need relocations to be performed on the OPD section (thanks mprotect + COW, it actually works) if the library is ever mapped at a differnet address than it's native0x100000(via the new phdr for example).
The current glibc code forcesl_relocatedto 1 for all vdso's (which is fine for archs without need to relocate function descriptors).
Quoted 4 lines
That is on purpose, even if vDSO location is randomized (e.g. on IA-32), no relocations should happen, so that the vDSO can be shared (unless written into by the debugger, that is). ld.so knows how to deal with .dynamic section relocation of vDSOs.
But not with function descriptors... on archs like ppc64, a function symbol is actually a descriptor containing the absolute address of the actual code and the TOC pointer. (For the vDSO, the TOC pointer is always 0 though, routines in there don't need a TOC).
So those descriptors (in the OPD section) need to be relocated if the vDSO is mapped at it's non-native address. It works fine since ld.so will do mprotect() on it, and the kernel implementation I've done on ppc do support COW when mprotect enables write access. It's also not a default case as I only expect a few apps, like emulators and/or maybe the JVM, to request a different location because they need finer control on their address space (unless we want randomizing though).
So unless we change the ABI to those calls, we have to allow relocation to happen, on ppc64.
Ulrich proposed that instead, I export the vDSO symbols as absolute symbols containing an offset from the start of the vDSO itself. I have to check how to generate those, but that would mean we lose the nice "feature" of the vDSO beeing just a normal library and require special jump trampolines to call the routines in there...
Ben.