From patchwork Sun Apr 4 18:38:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 51243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4FF8DB7D48 for ; Thu, 29 Apr 2010 06:31:49 +1000 (EST) Received: from localhost ([127.0.0.1]:41345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Dv2-0003KO-9D for incoming@patchwork.ozlabs.org; Wed, 28 Apr 2010 16:31:40 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7D6x-0005qU-22 for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:55 -0400 Received: from [140.186.70.92] (port=51793 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7D6q-0005k2-3s for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7D6l-0007Yo-UP for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:47 -0400 Received: from are.twiddle.net ([75.149.56.221]:55998) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7D6k-0007WL-Uv for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:43 -0400 Received: by are.twiddle.net (Postfix, from userid 5000) id 4F1901071; Wed, 28 Apr 2010 12:39:41 -0700 (PDT) Message-Id: In-Reply-To: References: From: Richard Henderson Date: Sun, 4 Apr 2010 11:38:14 -0700 To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [Qemu-devel] [PATCH 13/14] linux-user: Build vdso for x64. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ... Well, sortof. The Makefile bits are broken. Patch to load the vdso into the running program to follow. Signed-off-by: Richard Henderson --- Makefile | 3 +- pc-bios/Makefile | 5 ++ pc-bios/vdso-linux-x64.S | 102 +++++++++++++++++++++++++++++++++++++++++++++ pc-bios/vdso-linux-x64.ld | 81 +++++++++++++++++++++++++++++++++++ pc-bios/vdso-linux-x64.so | Bin 0 -> 7515 bytes 5 files changed, 190 insertions(+), 1 deletions(-) create mode 100644 pc-bios/vdso-linux-x64.S create mode 100644 pc-bios/vdso-linux-x64.ld create mode 100755 pc-bios/vdso-linux-x64.so diff --git a/pc-bios/vdso-linux-x64.so b/pc-bios/vdso-linux-x64.so new file mode 100755 index 0000000000000000000000000000000000000000..5ebf5959f9dac5065428148e7625f58c722e1cca GIT binary patch literal 7515 zcmeHMO>Z1U5Uus%*iM{y6Cwl{#0nW7EEvfVLXjZIcKj8xI3d_l!ezYij=dJ%U9iWI z%^?^OD>4#Nj&MZWI6#g*@TnkV@(Xf7Z~z1s6b@K90872;dYhfeh7%G(Oxr!L>s3`x zcTM-~sQUG>!gyOIBP>~YRwC&>#|)Wb$7F~@a#Z%{H7ENOMed0>XrOb2c-p!qcA6eE zeD78^vQ9%3$wvhI+O=-n8;N(|CvA==(hoGodBw()L^o+QFg?c!AJlga>!k(uIa-LY zMLGRLSVH?_^GhP_iS#=Vd5cEa74n?#Z-3Tn&}`fM5et-CCNrj2EDn2}TFw~mGrZsM z_qywE*2ejV$>uIMO@7Yw=Ju~ZRsxNF$I& zAdNs8fiwdDs|X;S(WMo63*>s3&(UU7n9pH82KF6Vf#8t0fXy3+^O=!AHo&0|a2IF3 zc~!3WUcG#B^T!9?KVE%n;H&=rtLKBt*~@kD{R^d)nm@Nxn|s+`2*Pl&5|A{pHeV{P zH*s^Xtjf}2b#?6txO)0OD1{SKGiUuH-cx!%jHvk!Ove7+`|OwfNFhC>mANg9y-oGI zs~={WUP8VF1+f5!c}`5t$n~E(zYGQjCO+st_x8J=e$+R2 zPy4l=M=nKk*`AHdgI`Z>*2Au?oyY1uB3m7ko4aBA7e9Az9T@!lns_Vgm9ThTF-NR_GZ(a2c49&!01avP&t0CYy1Yby8n&nB`xx%>!xu{-oK$} z(a7p(8~eCPpVg^&_IYizI&blmZ*@+Beb?$72EV1P z&QD&l{*&i33&tnURjSqx*E!df_@n2hhMzxiT>Oc`sgdD=e`. + */ + +#include + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, @function + .balign 16 + .cfi_startproc +__vdso_clock_gettime: + mov $__NR_clock_gettime, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_gettime, . - __vdso_clock_gettime + +clock_gettime = __vdso_clock_gettime + .weak clock_gettime + + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, @function + .balign 16 + .cfi_startproc +__vdso_gettimeofday: + mov $__NR_gettimeofday, %eax + syscall + ret + .cfi_endproc + .size __vdso_gettimeofday, . - __vdso_gettimeofday + +gettimeofday = __vdso_gettimeofday + .weak gettimeofday + + + .globl __vdso_getcpu + .type __vdso_getcpu, @function + .balign 16 + .cfi_startproc +__vdso_getcpu: + /* ??? There is no syscall number for this allocated on x64. + We can handle this several ways: + + (1) Invent a syscall number for use within qemu. + It should be easy enough to pick a number that + is well out of the way of the kernel numbers. + + (2) Force the emulated cpu to support the rdtscp insn, + and initialize the TSC_AUX value the appropriate value. + + (3) Pretend that we're always running on cpu 0. + + This last is the one that's implemented here, with the + tiny bit of extra code to support rdtscp in place. */ + + xor %ecx, %ecx /* rdtscp w/ tsc_aux = 0 */ + + /* if (cpu != NULL) *cpu = (ecx & 0xfff); */ + test %rdi, %rdi + jz 1f + mov %ecx, %eax + and $0xfff, %eax + mov %eax, (%rdi) + + /* if (node != NULL) *node = (ecx >> 12); */ +1: test %rsi, %rsi + jz 2f + shr $12, %ecx + mov %ecx, (%rsi) + +2: xor %eax, %eax + ret + .cfi_endproc + .size __vdso_getcpu, . - __vdso_getcpu + +getcpu = __vdso_getcpu + .weak getcpu + +/* ??? Perhaps add elf notes. E.g. + + #include + ELFNOTE_START(Linux, 0, "a") + .long LINUX_VERSION_CODE + ELFNOTE_END + + but what version number would we set for QEMU? */ diff --git a/pc-bios/vdso-linux-x64.ld b/pc-bios/vdso-linux-x64.ld new file mode 100644 index 0000000..d57d0e7 --- /dev/null +++ b/pc-bios/vdso-linux-x64.ld @@ -0,0 +1,81 @@ +/* + * Linker script for linux x64 replacement vdso. + * + * Copyright (c) 2010 Fabrice Bellard + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +VERSION { + LINUX_2.6 { + global: + clock_gettime; + __vdso_clock_gettime; + gettimeofday; + __vdso_gettimeofday; + getcpu; + __vdso_getcpu; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + note PT_NOTE FLAGS(4); + /* ??? Various versions of ld don't know PT_GNU_EH_FRAME. */ + eh_frame_hdr 0x6474e550; +} + +SECTIONS { + /* ??? We can't really prelink to any address without knowing + something about the virtual memory space of the host, since + that leaks over into the available memory space of the guest. */ + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + . += 4096; + .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .note : { *(.note*) } :text :note + .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :text + .rodata : { *(.rodata) } + + . = ALIGN(0x100); + .text : { *(.text*) } :text =0x90909090 +}