From patchwork Tue Jul 23 20:27:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 261210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 853B52C00CF for ; Wed, 24 Jul 2013 06:29:31 +1000 (EST) Received: from localhost ([::1]:47689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1jD7-00010q-4z for incoming@patchwork.ozlabs.org; Tue, 23 Jul 2013 16:29:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1jBm-0007ld-H7 for qemu-devel@nongnu.org; Tue, 23 Jul 2013 16:28:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1jBh-0005Cd-JJ for qemu-devel@nongnu.org; Tue, 23 Jul 2013 16:28:06 -0400 Received: from mail-pb0-x232.google.com ([2607:f8b0:400e:c01::232]:61116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1jBh-0005CO-9d for qemu-devel@nongnu.org; Tue, 23 Jul 2013 16:28:01 -0400 Received: by mail-pb0-f50.google.com with SMTP id wz7so8758063pbc.23 for ; Tue, 23 Jul 2013 13:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=RGO8RYzmVGkd7eVFurg+xQoihDp2DNqwAlTLTqvIOSY=; b=l8l6EY0SoFiQdmoIxIRU46eXNYByK6CtXvw2qRxNEN2p8iVv64qDYWMb1dPq4hAoPl kz2UiFVKRgy9MmeG8Dhhalql+6yAR2kTed8MJ/bgVEFepwad6Dt6ItnqjXWoGziZEeAE npRg2lsAmGYbptgk5UZaLrcEow7umiN4NGHLQxt0U+s9E8V4UHrEDKm0NC8HeEMtS/ZN ef3OuaZnHOLW0jgiZJxi9hkix/H2pWkQN/gK43tXVrizzcK9erFekfGI0rDXZQY82/nJ wkW+xdBRi98gZt88Aa3yH7cVraBNGqwIXOrA8AHunYsJY82f26IGBlUL8cXRcPnLkDZ7 1DcA== X-Received: by 10.68.113.2 with SMTP id iu2mr38561745pbb.108.1374611280602; Tue, 23 Jul 2013 13:28:00 -0700 (PDT) Received: from pebble.twiddle.net (34-136-165-209.tsia.static.gci.net. [209.165.136.34]) by mx.google.com with ESMTPSA id bb1sm33680849pbc.10.2013.07.23.13.27.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 23 Jul 2013 13:27:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 23 Jul 2013 12:27:53 -0800 Message-Id: <1374611274-19493-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1374611274-19493-1-git-send-email-rth@twiddle.net> References: <1374611274-19493-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::232 Cc: riku.voipio@iki.fi Subject: [Qemu-devel] [PATCH 1/2] linux-user: Build vdso for x64. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: 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 | 100 ++++++++++++++++++++++++++++++++++++++++++++++ pc-bios/vdso-linux-x64.ld | 79 ++++++++++++++++++++++++++++++++++++ pc-bios/vdso-linux-x64.so | Bin 0 -> 7419 bytes 5 files changed, 186 insertions(+), 1 deletion(-) 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..5fd8221527f0fc54ce3f93e98e6b9e14dadc7489 GIT binary patch literal 7419 zcmeHMQEMDk6h512nxw`isYR+$TqNy7se>t^g0>{7NmII}rA?rUFxh6O*eXzek6b0X;;Ddd$B~aUfj|E@EKB(Y}=!2nxx}I<5eA}Jr#1|igGB>&N-SeGu z?%aFk-r3>Yw?+$NZMmGVIC4-z>A{E@GR0++Ar8s2vQ@7=(yb`6CFG!iE-J+1)-|!y z^q}FpSt&b_hA5H`3HY^ZEk6*7cj3*ph$qqyG{$+s#*@To(rRFOjuSqpD?9a)f&&pP zMA)Jn|1l_`{i*pSk@iITZ4bRgBODd-obT^{H)_y)Wb;QXP;Qybm|n0rY>U)#!tg%B zU50-)qW;EhoPU{Y?((b2`%Q0d{|h+M)r=gxZX6plUtGWJomnVWe6L(m zdrIO4emw|>`=2lU+5`3w)*s4dd13BXuA$z@Jk0wdr^SOAi�RQlsVm z%o7uLm^JU8#G|T5&Y3*(&_vFkF-ngAW%b8LHM&F)W}rlVnU{B`r^`=9w|;(>%e*B$9TZE)?910Jxv^to12+sWtGI`>x7m4_qg zwmINj0+r+E`o(Wr+WqTz>1uf=g61`O|E40P;pk|&A6wOqJ}vIAIPWy~Pn_S*SiNmewM9 zZKj=vxXP!UV_<)!os-}eaIV9fU!m*Lz of_H3e?BwXAH#s~~81*Fny>jR4!#-#J<;x|eQUPBxsUJcA0EOZRod5s; literal 0 HcmV?d00001 diff --git a/Makefile b/Makefile index c06bfab..0148da1 100644 --- a/Makefile +++ b/Makefile @@ -296,7 +296,8 @@ multiboot.bin linuxboot.bin kvmvapic.bin \ s390-zipl.rom \ s390-ccw.img \ spapr-rtas.bin slof.bin \ -palcode-clipper +palcode-clipper \ +vdso-linux-x64.so else BLOBS= endif diff --git a/pc-bios/Makefile b/pc-bios/Makefile index 315288d..70e2485 100644 --- a/pc-bios/Makefile +++ b/pc-bios/Makefile @@ -15,5 +15,10 @@ all: $(TARGETS) %.dtb: %.dts dtc -I dts -O dtb -o $@ $< +vdso-linux-x64.so: vdso-linux-x64.o vdso-linux-x64.ld + $(CC) -nostdlib -shared -Wl,-T,vdso-linux-x64.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both \ + vdso-linux-x64.o -o $@ + clean: rm -f $(TARGETS) *.o *~ diff --git a/pc-bios/vdso-linux-x64.S b/pc-bios/vdso-linux-x64.S new file mode 100644 index 0000000..92efcd1 --- /dev/null +++ b/pc-bios/vdso-linux-x64.S @@ -0,0 +1,100 @@ +/* + * x86-64 linux replacement vdso. + * + * 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 . + */ + +#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..9e7e2d1 --- /dev/null +++ b/pc-bios/vdso-linux-x64.ld @@ -0,0 +1,79 @@ +/* + * Linker script for linux x64 replacement vdso. + * + * 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 +}