From nobody Wed Feb 11 03:43:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519148234124860.6037635863678; Tue, 20 Feb 2018 09:37:14 -0800 (PST) Received: from localhost ([::1]:56820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoBqn-0000Zs-3N for importer@patchew.org; Tue, 20 Feb 2018 12:37:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoBnL-0006kl-Rf for qemu-devel@nongnu.org; Tue, 20 Feb 2018 12:33:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoBnI-0003ta-MH for qemu-devel@nongnu.org; Tue, 20 Feb 2018 12:33:35 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:42157) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eoBnI-0003t0-Bt for qemu-devel@nongnu.org; Tue, 20 Feb 2018 12:33:32 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MPuba-1et7T10fMQ-0054Te; Tue, 20 Feb 2018 18:33:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 20 Feb 2018 18:33:05 +0100 Message-Id: <20180220173307.25125-3-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180220173307.25125-1-laurent@vivier.eu> References: <20180220173307.25125-1-laurent@vivier.eu> X-Provags-ID: V03:K0:qyKVvQ7m+z322Nf+zSozXb2aP+hfCmvXPH7P5G13cMAsw16k9MA NRVZSjh1oGqmxD+68MDR0ngxDp2MTItYCZtB+2tzKBdxwxh/BkNZ8Rk/ol30mwsczMcJw+V tYEyydNERgds/BPhP1+piCO2BKZcTkc7Tp/o6p4Fd5w/0GtqC+komip2i5noABNVdexcBNQ 3R6ZgimwF1k8/jNonYSOg== X-UI-Out-Filterresults: notjunk:1;V01:K0:hxBbdItrC/M=:5wba/4CpiFyODznPpp75NU s6oRNm0d8gyUY8VyKI+FzfrMqa4Gt9W2OO1OLz5u8pHmJC663ciuzyyqYm30mvu9YVFcil7cj 1e7pytT05HY9m0qqcPb2pcVne3cZYY4jXfLbcniPIQHsc+o04tUUbpwsmM/7yoe6AXTWLbjQ0 RoPgxVH7y49HZzpC/r0t8bApGCRlCGzvVOWmCi2HXX3L2I3eV2EWtFuBs065kZNoXqGUUhRIJ usxbUxhIxLgL71RFOz0pCokC8ULuMfYMUPxukO7tW1r+wuxcNVjCFdaDW4zEY8tVn5FAvnwwZ ZM3kUZtYKPQzz202yKVxTBY1v7UcCIP5DnPMcieoH5nxOtjgTbfHzFjla1tfyulVti2/fhleo u/rCgJSGocpBN6ZARs5JStqH98DUrilvpBaboup/RywzDx+NoHwz7xRrPDIWPiFvddPZdMPFY LUFAvdxBHW5eSmMj6VccZ0LqwP9jVkIo0ptGbCRltEBKmPf0h+qx8JaTxF03Cwgdtj31K8nC+ hkGByt6CKGdh5A+FgGRPev2/APcP6H/C3WlF9DJY2L6QtnrWPYYaqdAjJla1K1SMoJuMy7n3B 7FO0AjYXeStVkdagVtz95UZJspBhnCoLDpEQ4kqFhnuffu16qy4PSIhQTXJDx+jLpJEqgdUlw Htge9gwEO6p98q0SJctvslD9QqEyyfzXAmo5Qd+i+MXw+PvA1dAlM71DjyhSXi2KljtBMV3T6 9HsknMKdtHSi6y6AkCDw1nwoSgWDOGGlK00dnA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PATCH v5 2/4] linux-user: introduce functions to detect CPU type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , YunQiang Su , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Igor Mammedov , Aaron Sierra Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: YunQiang Su Add a function to return ELF e_flags and use it to select the CPU model. Signed-off-by: YunQiang Su [lv: split the patch and some cleanup in get_elf_eflags()] Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- Notes: v4: add YunQiang Su's Signed-off-by v2: call cpu_get_model() with the result of get_elf_eflags() linux-user/elfload.c | 35 +++++++++++++++++++++++++++++++++++ linux-user/main.c | 20 ++++++++++---------- linux-user/qemu.h | 1 + 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8bb9a2c3e8..0208022445 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2396,6 +2396,41 @@ give_up: g_free(syms); } =20 +uint32_t get_elf_eflags(int fd) +{ + struct elfhdr ehdr; + off_t offset; + int ret; + + /* Read ELF header */ + offset =3D lseek(fd, 0, SEEK_SET); + if (offset =3D=3D (off_t) -1) { + return 0; + } + ret =3D read(fd, &ehdr, sizeof(ehdr)); + if (ret < sizeof(ehdr)) { + return 0; + } + offset =3D lseek(fd, offset, SEEK_SET); + if (offset =3D=3D (off_t) -1) { + return 0; + } + + /* Check ELF signature */ + if (!elf_check_ident(&ehdr)) { + return 0; + } + + /* check header */ + bswap_ehdr(&ehdr); + if (!elf_check_ehdr(&ehdr)) { + return 0; + } + + /* return architecture id */ + return ehdr.e_flags; +} + int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) { struct image_info interp_info; diff --git a/linux-user/main.c b/linux-user/main.c index 24ecef3607..bab5bbcfb1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -4344,8 +4344,17 @@ int main(int argc, char **argv, char **envp) =20 init_qemu_uname_release(); =20 + execfd =3D qemu_getauxval(AT_EXECFD); + if (execfd =3D=3D 0) { + execfd =3D open(filename, O_RDONLY); + if (execfd < 0) { + printf("Error while loading %s: %s\n", filename, strerror(errn= o)); + _exit(EXIT_FAILURE); + } + } + if (cpu_model =3D=3D NULL) { - cpu_model =3D cpu_get_model(0); + cpu_model =3D cpu_get_model(get_elf_eflags(execfd)); } tcg_exec_init(0); /* NOTE: we need to init the CPU at this stage to get @@ -4438,15 +4447,6 @@ int main(int argc, char **argv, char **envp) cpu->opaque =3D ts; task_settid(ts); =20 - execfd =3D qemu_getauxval(AT_EXECFD); - if (execfd =3D=3D 0) { - execfd =3D open(filename, O_RDONLY); - if (execfd < 0) { - printf("Error while loading %s: %s\n", filename, strerror(errn= o)); - _exit(EXIT_FAILURE); - } - } - ret =3D loader_exec(execfd, filename, target_argv, target_environ, reg= s, info, &bprm); if (ret !=3D 0) { diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 4edd7d0c08..47ca71159c 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -188,6 +188,7 @@ int loader_exec(int fdexec, const char *filename, char = **argv, char **envp, struct target_pt_regs * regs, struct image_info *infop, struct linux_binprm *); =20 +uint32_t get_elf_eflags(int fd); int load_elf_binary(struct linux_binprm *bprm, struct image_info *info); int load_flt_binary(struct linux_binprm *bprm, struct image_info *info); =20 --=20 2.14.3