blob: 3c2594a5d093dda65030610dea6c0357923acf1b [file] [log] [blame]
Brad Bishop26bdd442019-08-16 17:08:17 -04001From fd40eee42273220fb0050fe10744b10067adc0a7 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= <anibal.limon@linux.intel.com>
3Date: Fri, 31 Aug 2018 17:31:50 +0200
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
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008
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---
24 configure.ac | 9 +++++++++
25 kexec/arch/x86_64/kexec-elf-rel-x86_64.c | 4 ++++
26 kexec/kexec-syscall.h | 4 ++++
27 purgatory/arch/x86_64/Makefile | 4 +++-
28 4 files changed, 20 insertions(+), 1 deletion(-)
29
Brad Bishop26bdd442019-08-16 17:08:17 -040030diff --git a/configure.ac b/configure.ac
31index e05d601..c428146 100644
32--- a/configure.ac
33+++ b/configure.ac
34@@ -54,6 +54,15 @@ case $target_cpu in
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080035 ;;
36 ia64|x86_64|alpha|m68k )
37 ARCH="$target_cpu"
38+
39+ dnl ---Test for x32 ABI in x86_64
40+ if test "x$ARCH" = "xx86_64" ; then
41+ AC_EGREP_CPP(x32_test,
42+ [#if defined(__x86_64__) && defined (__ILP32__)
43+ x32_test
44+ #endif
45+ ], SUBARCH='x32', SUBARCH='64')
46+ fi
47 ;;
48 * )
49 AC_MSG_ERROR([unsupported architecture $target_cpu])
Brad Bishop26bdd442019-08-16 17:08:17 -040050diff --git a/kexec/arch/x86_64/kexec-elf-rel-x86_64.c b/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
51index 761a4ed..1c0e3f8 100644
52--- a/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
53+++ b/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
54@@ -8,7 +8,11 @@ int machine_verify_elf_rel(struct mem_ehdr *ehdr)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055 if (ehdr->ei_data != ELFDATA2LSB) {
56 return 0;
57 }
58+#ifdef __ILP32__
59+ if (ehdr->ei_class != ELFCLASS32) {
60+#else
61 if (ehdr->ei_class != ELFCLASS64) {
62+#endif
63 return 0;
64 }
65 if (ehdr->e_machine != EM_X86_64) {
Brad Bishop26bdd442019-08-16 17:08:17 -040066diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h
67index 2a3794d..3e67078 100644
68--- a/kexec/kexec-syscall.h
69+++ b/kexec/kexec-syscall.h
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070@@ -31,8 +31,12 @@
71 #define __NR_kexec_load 268
72 #endif
73 #ifdef __x86_64__
74+#ifdef __ILP32__
75+#define __NR_kexec_load 528
76+#else
77 #define __NR_kexec_load 246
78 #endif
79+#endif
80 #ifdef __s390x__
81 #define __NR_kexec_load 277
82 #endif
Brad Bishop26bdd442019-08-16 17:08:17 -040083diff --git a/purgatory/arch/x86_64/Makefile b/purgatory/arch/x86_64/Makefile
84index 7300937..4af11e4 100644
85--- a/purgatory/arch/x86_64/Makefile
86+++ b/purgatory/arch/x86_64/Makefile
87@@ -23,4 +23,6 @@ x86_64_PURGATORY_SRCS += purgatory/arch/i386/console-x86.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088 x86_64_PURGATORY_SRCS += purgatory/arch/i386/vga.c
89 x86_64_PURGATORY_SRCS += purgatory/arch/i386/pic.c
90
91-x86_64_PURGATORY_EXTRA_CFLAGS = -mcmodel=large
92+ifeq ($(SUBARCH),64)
93+ x86_64_PURGATORY_EXTRA_CFLAGS = -mcmodel=large
94+endif