blob: 95e72d271b95b3281d6c921869586dc63d614b9c [file] [log] [blame]
Thomas Gleixner2522fe42019-05-28 09:57:20 -07001// SPDX-License-Identifier: GPL-2.0-only
Roland McGrath2f79e482008-01-30 13:31:46 +01002/*
3 * 32-bit compatibility support for ELF format executables and core dumps.
4 *
5 * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
6 *
Roland McGrath2f79e482008-01-30 13:31:46 +01007 * Red Hat Author: Roland McGrath.
8 *
9 * This file is used in a 64-bit kernel that wants to support 32-bit ELF.
10 * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros
11 * used below, with definitions appropriate for 32-bit ABI compatibility.
12 *
13 * We use macros to rename the ABI types and machine-dependent
14 * functions used in binfmt_elf.c to compat versions.
15 */
16
17#include <linux/elfcore-compat.h>
18#include <linux/time.h>
19
Dave Martin00e19ce2020-03-16 16:50:44 +000020#define ELF_COMPAT 1
21
Roland McGrath2f79e482008-01-30 13:31:46 +010022/*
23 * Rename the basic ELF layout types to refer to the 32-bit class of files.
24 */
25#undef ELF_CLASS
26#define ELF_CLASS ELFCLASS32
27
28#undef elfhdr
29#undef elf_phdr
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080030#undef elf_shdr
Roland McGrath2f79e482008-01-30 13:31:46 +010031#undef elf_note
32#undef elf_addr_t
Dave Martin00e19ce2020-03-16 16:50:44 +000033#undef ELF_GNU_PROPERTY_ALIGN
Roland McGrath2f79e482008-01-30 13:31:46 +010034#define elfhdr elf32_hdr
35#define elf_phdr elf32_phdr
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080036#define elf_shdr elf32_shdr
Roland McGrath2f79e482008-01-30 13:31:46 +010037#define elf_note elf32_note
38#define elf_addr_t Elf32_Addr
Dave Martin00e19ce2020-03-16 16:50:44 +000039#define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN
Roland McGrath2f79e482008-01-30 13:31:46 +010040
41/*
Denys Vlasenko49ae4d42012-10-04 17:15:35 -070042 * Some data types as stored in coredump.
43 */
Denys Vlasenko2aa362c2012-10-04 17:15:36 -070044#define user_long_t compat_long_t
Denys Vlasenko49ae4d42012-10-04 17:15:35 -070045#define user_siginfo_t compat_siginfo_t
Eric W. Biedermanfa4751f2020-05-05 12:12:54 +020046#define copy_siginfo_to_external copy_siginfo_to_external32
Denys Vlasenko49ae4d42012-10-04 17:15:35 -070047
48/*
Roland McGrath2f79e482008-01-30 13:31:46 +010049 * The machine-dependent core note format types are defined in elfcore-compat.h,
50 * which requires asm/elf.h to define compat_elf_gregset_t et al.
51 */
52#define elf_prstatus compat_elf_prstatus
Al Virof2485a22020-06-13 00:08:44 -040053#define elf_prstatus_common compat_elf_prstatus_common
Roland McGrath2f79e482008-01-30 13:31:46 +010054#define elf_prpsinfo compat_elf_prpsinfo
55
Arnd Bergmanne2bb80d2017-11-23 13:46:33 +010056#undef ns_to_kernel_old_timeval
57#define ns_to_kernel_old_timeval ns_to_old_timeval32
Roland McGrath2f79e482008-01-30 13:31:46 +010058
59/*
60 * To use this file, asm/elf.h must define compat_elf_check_arch.
61 * The other following macros can be defined if the compat versions
62 * differ from the native ones, or omitted when they match.
63 */
64
Roland McGrath2f79e482008-01-30 13:31:46 +010065#undef elf_check_arch
66#define elf_check_arch compat_elf_check_arch
67
68#ifdef COMPAT_ELF_PLATFORM
69#undef ELF_PLATFORM
70#define ELF_PLATFORM COMPAT_ELF_PLATFORM
71#endif
72
73#ifdef COMPAT_ELF_HWCAP
74#undef ELF_HWCAP
75#define ELF_HWCAP COMPAT_ELF_HWCAP
76#endif
77
Ard Biesheuvel66d6e3b2014-03-03 07:34:44 +000078#ifdef COMPAT_ELF_HWCAP2
79#undef ELF_HWCAP2
80#define ELF_HWCAP2 COMPAT_ELF_HWCAP2
81#endif
82
Roland McGrath2f79e482008-01-30 13:31:46 +010083#ifdef COMPAT_ARCH_DLINFO
84#undef ARCH_DLINFO
85#define ARCH_DLINFO COMPAT_ARCH_DLINFO
86#endif
87
88#ifdef COMPAT_ELF_ET_DYN_BASE
89#undef ELF_ET_DYN_BASE
90#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE
91#endif
92
Roland McGrath2f79e482008-01-30 13:31:46 +010093#ifdef COMPAT_ELF_PLAT_INIT
94#undef ELF_PLAT_INIT
95#define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT
96#endif
97
98#ifdef COMPAT_SET_PERSONALITY
99#undef SET_PERSONALITY
100#define SET_PERSONALITY COMPAT_SET_PERSONALITY
101#endif
102
103#ifdef compat_start_thread
Gabriel Krisman Bertazibc3d7bf2020-10-03 23:25:31 -0400104#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp) \
105 compat_start_thread(regs, new_ip, new_sp)
106#endif
107
108#ifdef COMPAT_START_THREAD
109#undef START_THREAD
110#define START_THREAD COMPAT_START_THREAD
Roland McGrath2f79e482008-01-30 13:31:46 +0100111#endif
112
Gabriel Krisman Bertazi9a29a672020-10-03 23:25:33 -0400113#ifdef compat_arch_setup_additional_pages
114#define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter) \
115 compat_arch_setup_additional_pages(bprm, interpreter)
116#endif
117
118#ifdef COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
Roland McGrath2f79e482008-01-30 13:31:46 +0100119#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES
120#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
Gabriel Krisman Bertazi9a29a672020-10-03 23:25:33 -0400121#undef ARCH_SETUP_ADDITIONAL_PAGES
122#define ARCH_SETUP_ADDITIONAL_PAGES COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
Roland McGrath2f79e482008-01-30 13:31:46 +0100123#endif
124
Kees Cook6e0d6ac2020-03-26 23:48:20 -0700125#ifdef compat_elf_read_implies_exec
126#undef elf_read_implies_exec
127#define elf_read_implies_exec compat_elf_read_implies_exec
128#endif
129
Roland McGrath2f79e482008-01-30 13:31:46 +0100130/*
131 * Rename a few of the symbols that binfmt_elf.c will define.
132 * These are all local so the names don't really matter, but it
133 * might make some debugging less confusing not to duplicate them.
134 */
135#define elf_format compat_elf_format
136#define init_elf_binfmt init_compat_elf_binfmt
137#define exit_elf_binfmt exit_compat_elf_binfmt
138
139/*
140 * We share all the actual code with the native (64-bit) version.
141 */
142#include "binfmt_elf.c"