Hi,

On Mon, 2026-07-13 at 18:03 +0200, Mark Wielaard wrote:
> These are both big endian machines, and they fail the same way on the
> new testcase:
> 
> --- readelf.out       2026-07-13 13:39:25.906716471 +0000
> +++ - 2026-07-13 13:39:25.911392375 +0000
> @@ -1 +1,5 @@
> -/var/lib/buildbot/workers/wildebeest/elfutils-debian-
> ppc64/build/src/readelf: failed reading 'core-ioperm-huge.core':
> invalid data
> +
> +Note segment of 16777236 bytes at offset 0x78:
> +  Owner          Data size  Type
> +  CORE            16777216  386_IOPERM
> +    ioperm: <>
> FAIL run-readelf-core-ioperm-huge.sh (exit status: 1)
> 
> I don't know yet if that is an existing bug reading core files with eu-
> readelf or a specific bug for this note type.

Found it. The generated test file should be little endian even on a big
endian test machine. I pushed the attached fix.

Cheers,

Mark

From 40d077029b3eeff5b4b71b1b0dd0892d0523350c Mon Sep 17 00:00:00 2001
From: Mark Wielaard <[email protected]>
Date: Mon, 13 Jul 2026 18:33:35 +0200
Subject: [PATCH] tests: Generate core-ioperm-huge little endian core file on
 big endian

The core file generated by the core-ioperm-huge testcase should be
little endian even when executed on a big endian machine. Use
elf64_xlatetof to transform the Elf data structure to ELFDATA2LSB
before writing to disk.

	* tests/Makefile.am (core_ioperm_huge_LDADD): Add libelf.
	* tests/core-ioperm-huge.c: Call elf64_xlatetof on ehdr, phdr
	and nhdr.

Signed-off-by: Mark Wielaard <[email protected]>
---
 tests/Makefile.am        |  2 +-
 tests/core-ioperm-huge.c | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 08c0a23d0129..8e6109f5ea5a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -790,7 +790,7 @@ arextract_LDADD = $(libelf)
 arsymtest_LDADD = $(libelf)
 ar_extract_ar_LDADD = $(libelf)
 ar_getarsym_mem_LDADD = $(libelf)
-core_ioperm_huge_LDADD =
+core_ioperm_huge_LDADD = $(libelf)
 newfile_LDADD = $(libelf)
 saridx_LDADD = $(libeu) $(libelf)
 scnnames_LDADD = $(libelf)
diff --git a/tests/core-ioperm-huge.c b/tests/core-ioperm-huge.c
index 10d533b67a41..6a111ebbe970 100644
--- a/tests/core-ioperm-huge.c
+++ b/tests/core-ioperm-huge.c
@@ -27,6 +27,7 @@
 #ifndef NT_386_IOPERM
 # define NT_386_IOPERM 0x201
 #endif
+#include <libelf.h>
 
 #include <fcntl.h>
 #include <stdint.h>
@@ -71,6 +72,10 @@ main (int argc, char **argv)
   const char name[] = "CORE";
   const size_t name_padded = (sizeof (name) + 3) & ~(size_t) 3; /* 8 */
   const size_t filesz = sizeof (Elf64_Nhdr) + name_padded + DESCSZ;
+  Elf_Data data;
+  data.d_version = EV_CURRENT;
+  data.d_off = 0;
+  data.d_align = 1;
 
   Elf64_Ehdr ehdr;
   memset (&ehdr, 0, sizeof ehdr);
@@ -85,6 +90,11 @@ main (int argc, char **argv)
   ehdr.e_ehsize = sizeof (Elf64_Ehdr);
   ehdr.e_phentsize = sizeof (Elf64_Phdr);
   ehdr.e_phnum = 1;
+
+  data.d_buf = &ehdr;
+  data.d_size = sizeof ehdr;
+  data.d_type = ELF_T_EHDR;
+  elf64_xlatetof (&data, &data, ELFDATA2LSB);
   put (fd, &ehdr, sizeof ehdr);
 
   Elf64_Phdr phdr;
@@ -95,6 +105,11 @@ main (int argc, char **argv)
   phdr.p_filesz = filesz;
   phdr.p_memsz = filesz;
   phdr.p_align = 4;
+
+  data.d_buf = &phdr;
+  data.d_size = sizeof phdr;
+  data.d_type = ELF_T_PHDR;
+  elf64_xlatetof (&data, &data, ELFDATA2LSB);
   put (fd, &phdr, sizeof phdr);
 
   Elf64_Nhdr nhdr;
@@ -102,6 +117,11 @@ main (int argc, char **argv)
   nhdr.n_namesz = sizeof (name); /* 5, includes the NUL */
   nhdr.n_descsz = DESCSZ;
   nhdr.n_type = NT_386_IOPERM;
+
+  data.d_buf = &nhdr;
+  data.d_size = sizeof nhdr;
+  data.d_type = ELF_T_NHDR;
+  elf64_xlatetof (&data, &data, ELFDATA2LSB);
   put (fd, &nhdr, sizeof nhdr);
 
   char namebuf[8];
-- 
2.54.0

Reply via email to