bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/4] exec: Allow loading x86_64 executables on x86_64


From: Sergey Bugaev
Subject: [PATCH v2 1/4] exec: Allow loading x86_64 executables on x86_64
Date: Mon, 15 May 2023 10:35:57 +0300

Since we don't support mixing i386 and x86_64 binaries on the same
system (as running them requires different build-time gnumach
configurations), the exec server can simply require the binary being
loaded to have been built for the same architecture as the exec server
itself.
---
 exec/exec.c     | 8 +++++++-
 exec/hostarch.c | 9 +++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/exec/exec.c b/exec/exec.c
index 8944167d..2e5fbfcd 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -518,6 +518,12 @@ prepare (file_t file, struct execdata *e)
 #define host_ELFDATA ELFDATA2LSB
 #endif
 
+#ifdef __LP64__
+#define host_ELFCLASS ELFCLASS64
+#else
+#define host_ELFCLASS ELFCLASS32
+#endif
+
 static void
 check_elf (struct execdata *e)
 {
@@ -539,7 +545,7 @@ check_elf (struct execdata *e)
       return;
     }
 
-  if (ehdr->e_ident[EI_CLASS] != ELFCLASS32 ||
+  if (ehdr->e_ident[EI_CLASS] != host_ELFCLASS ||
       ehdr->e_ident[EI_DATA] != host_ELFDATA ||
       ehdr->e_ident[EI_VERSION] != EV_CURRENT ||
       ehdr->e_version != EV_CURRENT ||
diff --git a/exec/hostarch.c b/exec/hostarch.c
index 363fda69..ed50e0a8 100644
--- a/exec/hostarch.c
+++ b/exec/hostarch.c
@@ -72,6 +72,15 @@ elf_machine_matches_host (ElfW(Half) e_machine)
     case CPU_TYPE_PENTIUMPRO:
       CACHE (e_machine == EM_386);
 
+    /* When building for x86_64, CPU_TYPE_X86_64 must be defined; otherwise
+       it's OK if we don't compile this branch -- none of the branches other
+       than the actual architecture the code is built for are going to be
+       taken anyway.  */
+#if defined (CPU_TYPE_X86_64) || defined (__x86_64__)
+    case CPU_TYPE_X86_64:
+      CACHE (e_machine == EM_X86_64);
+#endif
+
     case CPU_TYPE_POWERPC:
       CACHE (e_machine == EM_PPC);
 
-- 
2.40.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]