blob: a809d5ba8e7065f5a1fc8f28fe4ec456dbc60488 [file] [log] [blame]
Andrew Geissler706d5aa2021-02-12 15:55:30 -06001From 8c9a5076543eb3d497e016b3d7707e93d6311883 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= <anibal.limon@linux.intel.com>
3Date: Mon, 15 Jul 2013 23:32:36 -0700
4Subject: [PATCH] x86_64: Add support to build kexec-tools with x32 ABI
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Summary of changes,
10
11configure.ac: Add test for detect x32 ABI.
12purgatory/arch/x86_64/Makefile: Not use mcmodel large when
13 x32 ABI is set.
14kexec/arch/x86_64/kexec-elf-rel-x86_64.c: When x32 ABI is set
15 use ELFCLASS32 instead of ELFCLASS64.
16kexec/kexec-syscall.h: Add correct syscall number for x32 ABI.
17
18Upstream-Status: Submitted
19
20Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
21Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
22---
23 configure.ac | 9 +++++++++
24 kexec/arch/x86_64/kexec-elf-rel-x86_64.c | 4 ++++
25 kexec/kexec-syscall.h | 4 ++++
26 purgatory/arch/x86_64/Makefile | 4 +++-
27 4 files changed, 20 insertions(+), 1 deletion(-)
28
29diff --git a/configure.ac b/configure.ac
30index c2b0c68..60882b8 100644
31--- a/configure.ac
32+++ b/configure.ac
33@@ -54,6 +54,15 @@ case $target_cpu in
34 ;;
35 ia64|x86_64|alpha|m68k )
36 ARCH="$target_cpu"
37+
38+ dnl ---Test for x32 ABI in x86_64
39+ if test "x$ARCH" = "xx86_64" ; then
40+ AC_EGREP_CPP(x32_test,
41+ [#if defined(__x86_64__) && defined (__ILP32__)
42+ x32_test
43+ #endif
44+ ], SUBARCH='x32', SUBARCH='64')
45+ fi
46 ;;
47 * )
48 AC_MSG_ERROR([unsupported architecture $target_cpu])
49diff --git a/kexec/arch/x86_64/kexec-elf-rel-x86_64.c b/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
50index db85b44..0ce1172 100644
51--- a/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
52+++ b/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
53@@ -8,7 +8,11 @@ int machine_verify_elf_rel(struct mem_ehdr *ehdr)
54 if (ehdr->ei_data != ELFDATA2LSB) {
55 return 0;
56 }
57+#ifdef __ILP32__
58+ if (ehdr->ei_class != ELFCLASS32) {
59+#else
60 if (ehdr->ei_class != ELFCLASS64) {
61+#endif
62 return 0;
63 }
64 if (ehdr->e_machine != EM_X86_64) {
65diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h
66index dac1c1f..e9479b7 100644
67--- a/kexec/kexec-syscall.h
68+++ b/kexec/kexec-syscall.h
69@@ -31,8 +31,12 @@
70 #define __NR_kexec_load 268
71 #endif
72 #ifdef __x86_64__
73+#ifdef __ILP32__
74+#define __NR_kexec_load 528
75+#else
76 #define __NR_kexec_load 246
77 #endif
78+#endif
79 #ifdef __s390x__
80 #define __NR_kexec_load 277
81 #endif
82diff --git a/purgatory/arch/x86_64/Makefile b/purgatory/arch/x86_64/Makefile
83index 7300937..4af11e4 100644
84--- a/purgatory/arch/x86_64/Makefile
85+++ b/purgatory/arch/x86_64/Makefile
86@@ -23,4 +23,6 @@ x86_64_PURGATORY_SRCS += purgatory/arch/i386/console-x86.c
87 x86_64_PURGATORY_SRCS += purgatory/arch/i386/vga.c
88 x86_64_PURGATORY_SRCS += purgatory/arch/i386/pic.c
89
90-x86_64_PURGATORY_EXTRA_CFLAGS = -mcmodel=large
91+ifeq ($(SUBARCH),64)
92+ x86_64_PURGATORY_EXTRA_CFLAGS = -mcmodel=large
93+endif