Skip to content

Commit e3ddb8b

Browse files
committed
xtensa: add FDPIC and static PIE support for noMMU
Define ELFOSABI_XTENSA_FDPIC and use it as an OSABI tag in the ELF header to distinguish FDPIC ELF files from regular ELF files. Define ELF_FDPIC_PLAT_INIT and put executable map, interpreter map and executable dynamic section addresses into registers a4..a6. Update start_thread macro to preserve register values in the current register window. Add definitions for PTRACE_GETFDPIC, PTRACE_GETFDPIC_EXEC and PTRACE_GETFDPIC_INTERP. Signed-off-by: Max Filippov <[email protected]>
1 parent ccd2d9d commit e3ddb8b

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

arch/xtensa/include/asm/elf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
9393
#define elf_check_arch(x) ( ( (x)->e_machine == EM_XTENSA ) || \
9494
( (x)->e_machine == EM_XTENSA_OLD ) )
9595

96+
#define ELFOSABI_XTENSA_FDPIC 65
97+
#define elf_check_fdpic(x) ((x)->e_ident[EI_OSABI] == ELFOSABI_XTENSA_FDPIC)
98+
#define ELF_FDPIC_CORE_EFLAGS 0
99+
96100
/*
97101
* These are used to set parameters in the core dumps.
98102
*/
@@ -164,6 +168,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
164168
(_r)->areg[14] = 0; (_r)->areg[15] = 0; \
165169
} while (0)
166170

171+
#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
172+
do { \
173+
(_r)->areg[4] = _exec_map_addr; \
174+
(_r)->areg[5] = _interp_map_addr; \
175+
(_r)->areg[6] = dynamic_addr; \
176+
} while (0)
177+
167178
typedef struct {
168179
xtregs_opt_t opt;
169180
xtregs_user_t user;

arch/xtensa/include/asm/processor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,12 @@ struct thread_struct {
205205
#define start_thread(regs, new_pc, new_sp) \
206206
do { \
207207
unsigned long syscall = (regs)->syscall; \
208+
unsigned long current_aregs[16]; \
209+
memcpy(current_aregs, (regs)->areg, sizeof(current_aregs)); \
208210
memset((regs), 0, sizeof(*(regs))); \
209211
(regs)->pc = (new_pc); \
210212
(regs)->ps = USER_PS_VALUE; \
213+
memcpy((regs)->areg, current_aregs, sizeof(current_aregs)); \
211214
(regs)->areg[1] = (new_sp); \
212215
(regs)->areg[0] = 0; \
213216
(regs)->wmask = 1; \

arch/xtensa/include/uapi/asm/ptrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#define PTRACE_SETXTREGS 19
3838
#define PTRACE_GETHBPREGS 20
3939
#define PTRACE_SETHBPREGS 21
40+
#define PTRACE_GETFDPIC 22
41+
42+
#define PTRACE_GETFDPIC_EXEC 0
43+
#define PTRACE_GETFDPIC_INTERP 1
4044

4145
#ifndef __ASSEMBLY__
4246

fs/Kconfig.binfmt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY
5858
config BINFMT_ELF_FDPIC
5959
bool "Kernel support for FDPIC ELF binaries"
6060
default y if !BINFMT_ELF
61-
depends on ARM || ((M68K || SUPERH) && !MMU)
61+
depends on ARM || ((M68K || SUPERH || XTENSA) && !MMU)
6262
select ELFCORE
6363
help
6464
ELF FDPIC binaries are based on ELF, but allow the individual load

0 commit comments

Comments
 (0)