]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Generate core-ioperm-huge little endian core file on big endian
authorMark Wielaard <mark@klomp.org>
Mon, 13 Jul 2026 16:33:35 +0000 (18:33 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 13 Jul 2026 16:33:35 +0000 (18:33 +0200)
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 <mark@klomp.org>
tests/Makefile.am
tests/core-ioperm-huge.c

index 08c0a23d012952c900a15fa378c258f756a976e1..8e6109f5ea5a075a30e737265eb100a33ad56398 100644 (file)
@@ -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)
index 10d533b67a4194b249f020db7d3b5c7277ba8496..6a111ebbe970ef214d4749d89cfc8e6a58c7f4e2 100644 (file)
@@ -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];