From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: Re: [PATCH 15/17] risu: Allow use of ELF test files
Date: Wed, 15 May 2024 15:03:54 +0200 [thread overview]
Message-ID: <f573e2e7-4b15-4cc5-a44c-8e5cf0a50102@linaro.org> (raw)
In-Reply-To: <20240511115400.7587-16-richard.henderson@linaro.org>
On 11/5/24 13:53, Richard Henderson wrote:
> By using elf files, we make it easier to disassemble
> the test file, to match comparison failures to code.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> risu.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/risu.c b/risu.c
> index c28b4a5..e3845f6 100644
> --- a/risu.c
> +++ b/risu.c
> @@ -24,6 +24,8 @@
> #include <sys/mman.h>
> #include <fcntl.h>
> #include <string.h>
> +#include <elf.h>
> +#include <endian.h>
>
> #include "config.h"
> #include "risu.h"
> @@ -371,6 +373,57 @@ static void load_image(const char *imgfile)
> close(fd);
Maybe move the code here, doing 'addr = e32 | e64;', ...
> image_start = addr;
> image_start_address = (uintptr_t) addr;
> +
> + /*
> + * TODO: More complete parsing of ELF file, verify assumtion, namely:
> + * Single PT_LOAD covering the ELF header, code and data.
> + * For now, simply update image_start from the elf header.
> + */
> + if (memcmp(addr, ELFMAG, SELFMAG) == 0) {
> + const unsigned char *e_ident = addr;
> + bool swap, is_64;
> +
> + switch (e_ident[EI_DATA]) {
> + case ELFDATA2LSB:
> + swap = __BYTE_ORDER != __LITTLE_ENDIAN;
> + break;
> + case ELFDATA2MSB:
> + swap = __BYTE_ORDER == __LITTLE_ENDIAN;
> + break;
> + default:
> + fprintf(stderr, "%s: Bad elf header: EI_DATA = %x\n",
> + imgfile, e_ident[EI_DATA]);
> + exit(1);
> + }
> + switch (e_ident[EI_CLASS]) {
> + case ELFCLASS32:
> + is_64 = false;
> + break;
> + case ELFCLASS64:
> + is_64 = true;
> + break;
> + default:
> + fprintf(stderr, "%s: Bad elf header: EI_CLASS = %x\n",
> + imgfile, e_ident[EI_CLASS]);
> + exit(1);
> + }
> +
> + if (is_64) {
> + const Elf64_Ehdr *h64 = addr;
> + Elf64_Addr e64 = h64->e_entry;
> + if (swap) {
> + e64 = __builtin_bswap64(e64);
> + }
> + image_start = addr + e64;
> + } else {
> + const Elf32_Ehdr *h32 = addr;
> + Elf32_Addr e32 = h32->e_entry;
> + if (swap) {
> + e32 = __builtin_bswap32(e32);
> + }
> + image_start = addr + e32;
> + }
> + }
... otherwise image_start_address == &e_ident.
> }
>
> static int master(void)
next prev parent reply other threads:[~2024-05-15 13:04 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-11 11:53 [PATCH 00/17] RISU misc updates Richard Henderson
2024-05-11 11:53 ` [PATCH 01/17] ppc64: Fix <sys/user.h> include order Richard Henderson
2024-05-15 13:11 ` Philippe Mathieu-Daudé
2024-05-15 13:53 ` Richard Henderson
2024-05-15 16:55 ` Philippe Mathieu-Daudé
2024-05-16 13:32 ` Richard Henderson
2024-05-11 11:53 ` [PATCH 02/17] Fix load_image error check for mmap Richard Henderson
2024-05-15 12:51 ` Philippe Mathieu-Daudé
2024-05-11 11:53 ` [PATCH 03/17] Standardize reginfo_dump_mismatch printing Richard Henderson
2024-05-21 12:20 ` Peter Maydell
2024-05-11 11:53 ` [PATCH 04/17] Add --fulldump and --diffdup options Richard Henderson
2024-05-11 11:53 ` [PATCH 05/17] Remove return value from reginfo_dump Richard Henderson
2024-05-15 12:52 ` Philippe Mathieu-Daudé
2024-05-11 11:53 ` [PATCH 06/17] ppc64: Clean register values in reginfo_init Richard Henderson
2024-05-21 12:22 ` Peter Maydell
2024-05-11 11:53 ` [PATCH 07/17] ppc64: Compare all bits of CCR Richard Henderson
2024-05-15 12:54 ` Philippe Mathieu-Daudé
2024-05-11 11:53 ` [PATCH 08/17] ppc64: Simplify reginfo_is_eq Richard Henderson
2024-05-21 12:23 ` Peter Maydell
2024-05-11 11:53 ` [PATCH 09/17] ppc64: Clean up reginfo_dump Richard Henderson
2024-05-21 12:25 ` Peter Maydell
2024-05-11 11:53 ` [PATCH 10/17] aarch64: Tidy reginfo dumping ahead of ZA state Richard Henderson
2024-05-15 12:55 ` Philippe Mathieu-Daudé
2024-05-11 11:53 ` [PATCH 11/17] aarch64: Add support for ZA storage Richard Henderson
2024-05-11 11:53 ` [PATCH 12/17] aarch64: Trivial SME test Richard Henderson
2024-05-21 12:27 ` Peter Maydell
2024-05-11 11:53 ` [PATCH 13/17] Use bool for reginfo_is_eq Richard Henderson
2024-05-15 12:56 ` Philippe Mathieu-Daudé
2024-05-11 11:53 ` [PATCH 14/17] aarch64: Use bool for sve_{z,p}reg_is_eq Richard Henderson
2024-05-15 12:56 ` Philippe Mathieu-Daudé
2024-05-11 11:53 ` [PATCH 15/17] risu: Allow use of ELF test files Richard Henderson
2024-05-15 13:03 ` Philippe Mathieu-Daudé [this message]
2024-05-11 11:53 ` [PATCH 16/17] configure: Enable loongarch64 Richard Henderson
2024-05-15 13:06 ` Philippe Mathieu-Daudé
2024-05-15 13:08 ` Philippe Mathieu-Daudé
2024-05-11 11:54 ` [PATCH 17/17] Build elf test cases instead of raw binaries Richard Henderson
2024-05-15 13:08 ` Philippe Mathieu-Daudé
2024-05-21 12:46 ` [PATCH 00/17] RISU misc updates Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f573e2e7-4b15-4cc5-a44c-8e5cf0a50102@linaro.org \
--to=philmd@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).