On Tue, Mar 24, 2015 at 7:45 AM, H.J. Lu <[email protected]> wrote: > On Tue, Mar 24, 2015 at 6:48 AM, Mark Wielaard <[email protected]> wrote: >> On Thu, 2015-03-12 at 15:03 -0700, H.J. Lu wrote: >>> This patch adds x32_corenote.c to support x32 coredump. X32 coredump is >>> a hybrid between ia32 coredump and x86-64 coredump. The exact formats >>> are described in bfd/hosts/x86-64linux.h in GNU binutils source tree. >> >> So i386 uses EM_386 and ELFCLASS32. x86_64 uses EM_X86_64 and ELFCLASS32 >> and x32 also uses EM_X86_64 but with ELFCLASS32? Are there any other > > x86_64 uses EM_X86_64 with ELFCLASS64. x32 uses EM_X86_64 > with ELFCLASS32. > >> differences in ident or other ehdr identifiers? >> >> Will a x86_64 GNU/Linux setup always support x86_64 and one or both of >> i386 and x32? > > x86_64 GNU/Linux will always support x86-64. i386 and x32 support > is optional. > >> I don't see a gabi processor supplement for x32 here: >> http://refspecs.linuxbase.org/elf/index.html >> Do you know where it is kept? > > http://www.x86-64.org/svn/trunk/x86-64-ABI/ > >> Are there any distros using x32 to run some tests on? > > Ubuntu 14.02. > >> If you want to make sure that x32 is correctly supported (also cross >> arch) then you might want to provide a couple of test cases and binaries >> for things like tests/run-readelf-mixed-corenote.sh, >> tests/run-allregs.sh, run-strip-reloc.sh, run-addrcfi.sh, >> tests/run-backtrace-core-x32.sh, etc. The files should have a little >> description how to generate the test binaries. Don't feel obliged to add >> tests for everything at once (adding one test at a time is preferred). >> But it would help making sure the arch is properly supported (even if >> the test as is just passes without needing any new backend tweaks). > > I will add those. > >> A ChangeLog entry would make review of patches easier. It is also needed >> to get this checked in.
Here is the updated patch. Testcases will be sent separately. -- H.J.
From 0058c95f2c8ab28b3eadedab0f8c6419797f6612 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <[email protected]> Date: Thu, 12 Mar 2015 14:51:42 -0700 Subject: [PATCH 1/7] Add x32_corenote.c This patch adds x32_corenote.c to support x32 coredump. X32 coredump is a hybrid between ia32 coredump and x86-64 coredump. The exact formats are described in bfd/hosts/x86-64linux.h in GNU binutils source tree. backends/ * Makefile.am (x86_64_SRCS): Add x32_corenote.c. * linux-core-note.c (PR_REG): New. (PRPSINFO_UID_T): Likewise. (ALIGN_PRPSINFO_UID_T): Likewise. (PRPSINFO_GID_T): Likewise. (ALIGN_PRPSINFO_GID_T): Likewise. (pr_reg): Replace ULONG with PR_REG. (pr_uid): Replace UID_T with PRPSINFO_UID_T. (pr_gid): Replace GID_T with PRPSINFO_GID_T. * x32_corenote.c: New file. * x86_64_corenote.c (BITS): New. Support x32. (BACKEND): Support x32. (ULONG): Likewise. (ALIGN_ULONG): Likewise. (PRPSINFO_UID_T): New. (ALIGN_PRPSINFO_UID_T): Likewise. (PRPSINFO_GID_T): Likewise. (ALIGN_PRPSINFO_GID_T): Likewise. (PR_REG): Likewise. (ALIGN_PR_REG): Likewise. * x86_64_init.c (x32_core_note): New. (x86_64_init): Set eh->core_note to x32_core_note for x32. --- backends/Makefile.am | 2 +- backends/linux-core-note.c | 19 +++++++++++++++---- backends/x32_corenote.c | 2 ++ backends/x86_64_corenote.c | 29 +++++++++++++++++++++++++---- backends/x86_64_init.c | 9 +++++++-- 5 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 backends/x32_corenote.c diff --git a/backends/Makefile.am b/backends/Makefile.am index 687c089..21d7bd2 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -58,7 +58,7 @@ am_libebl_sh_pic_a_OBJECTS = $(sh_SRCS:.c=.os) x86_64_SRCS = x86_64_init.c x86_64_symbol.c x86_64_corenote.c x86_64_cfi.c \ x86_64_retval.c x86_64_regs.c i386_auxv.c x86_64_syscall.c \ - x86_64_initreg.c + x86_64_initreg.c x32_corenote.c cpu_x86_64 = ../libcpu/libcpu_x86_64.a libebl_x86_64_pic_a_SOURCES = $(x86_64_SRCS) am_libebl_x86_64_pic_a_OBJECTS = $(x86_64_SRCS:.c=.os) diff --git a/backends/linux-core-note.c b/backends/linux-core-note.c index e3c0109..d6bf993 100644 --- a/backends/linux-core-note.c +++ b/backends/linux-core-note.c @@ -1,5 +1,5 @@ /* Common core note type descriptions for Linux. - Copyright (C) 2007-2010 Red Hat, Inc. + Copyright (C) 2007-2015 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -42,9 +42,20 @@ #define INT int32_t #define ALIGN_INT 4 #define TYPE_INT ELF_T_SWORD +#ifndef PR_REG +# define PR_REG ULONG +#endif #ifndef ALIGN_PR_REG # define ALIGN_PR_REG ALIGN_ULONG #endif +#ifndef PRPSINFO_UID_T +# define PRPSINFO_UID_T UID_T +# define ALIGN_PRPSINFO_UID_T ALIGN_UID_T +#endif +#ifndef PRPSINFO_GID_T +# define PRPSINFO_GID_T GID_T +# define ALIGN_PRPSINFO_GID_T ALIGN_GID_T +#endif #define FIELD(type, name) type name __attribute__ ((aligned (ALIGN_##type))) @@ -86,7 +97,7 @@ struct EBLHOOK(prstatus) struct EBLHOOK(timeval) pr_cstime; struct { - FIELD (ULONG, pr_reg[PRSTATUS_REGS_SIZE / sizeof (ULONG)]); + FIELD (PR_REG, pr_reg[PRSTATUS_REGS_SIZE / sizeof (PR_REG)]); } #ifdef ALIGN_PR_REG __attribute__ ((aligned (ALIGN_PR_REG))) @@ -105,8 +116,8 @@ struct EBLHOOK(prpsinfo) FIELD (CHAR, pr_zomb); FIELD (CHAR, pr_nice); FIELD (ULONG, pr_flag); - FIELD (UID_T, pr_uid); - FIELD (GID_T, pr_gid); + FIELD (PRPSINFO_UID_T, pr_uid); + FIELD (PRPSINFO_GID_T, pr_gid); FIELD (PID_T, pr_pid); FIELD (PID_T, pr_ppid); FIELD (PID_T, pr_pgrp); diff --git a/backends/x32_corenote.c b/backends/x32_corenote.c new file mode 100644 index 0000000..bd6560d --- /dev/null +++ b/backends/x32_corenote.c @@ -0,0 +1,2 @@ +#define BITS 32 +#include "x86_64_corenote.c" diff --git a/backends/x86_64_corenote.c b/backends/x86_64_corenote.c index f9d8db4..cd136ca 100644 --- a/backends/x86_64_corenote.c +++ b/backends/x86_64_corenote.c @@ -1,5 +1,5 @@ /* x86-64 specific core note handling. - Copyright (C) 2005, 2007, 2008 Red Hat, Inc. + Copyright (C) 2005, 2007, 2008, 2015 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -36,7 +36,13 @@ #include <stdio.h> #include <sys/time.h> -#define BACKEND x86_64_ +#ifndef BITS +# define BITS 64 +# define BACKEND x86_64_ +#else +# define BITS 32 +# define BACKEND x32_ +#endif #include "libebl_CPU.h" @@ -77,11 +83,26 @@ static const Ebl_Register_Location prstatus_regs[] = }; #define PRSTATUS_REGS_SIZE (27 * 8) -#define ULONG uint64_t +#if BITS == 32 +# define ULONG uint32_t +# define ALIGN_ULONG 4 +# define PRPSINFO_UID_T uint16_t +# define ALIGN_PRPSINFO_UID_T 2 +# define PRPSINFO_GID_T uint16_t +# define ALIGN_PRPSINFO_GID_T 2 +#else +# define ULONG uint64_t +# define ALIGN_ULONG 8 +# define PRPSINFO_UID_T uint32_t +# define ALIGN_PRPSINFO_UID_T 4 +# define PRPSINFO_GID_T uint32_t +# define ALIGN_PRPSINFO_GID_T 4 +#endif +#define PR_REG uint64_t +#define ALIGN_PR_REG 8 #define PID_T int32_t #define UID_T uint32_t #define GID_T uint32_t -#define ALIGN_ULONG 8 #define ALIGN_PID_T 4 #define ALIGN_UID_T 4 #define ALIGN_GID_T 4 diff --git a/backends/x86_64_init.c b/backends/x86_64_init.c index b885558..ec5107f 100644 --- a/backends/x86_64_init.c +++ b/backends/x86_64_init.c @@ -1,5 +1,5 @@ /* Initialization of x86-64 specific backend library. - Copyright (C) 2002-2009, 2013 Red Hat, Inc. + Copyright (C) 2002-2009, 2013, 2015 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2002. @@ -38,6 +38,8 @@ /* This defines the common reloc hooks based on x86_64_reloc.def. */ #include "common-reloc.c" +extern __typeof (EBLHOOK (core_note)) x32_core_note attribute_hidden; + const char * x86_64_init (elf, machine, eh, ehlen) Elf *elf __attribute__ ((unused)); @@ -53,7 +55,10 @@ x86_64_init (elf, machine, eh, ehlen) eh->name = "AMD x86-64"; x86_64_init_reloc (eh); HOOK (eh, reloc_simple_type); - HOOK (eh, core_note); + if (eh->class == ELFCLASS32) + eh->core_note = x32_core_note; + else + HOOK (eh, core_note); HOOK (eh, return_value_location); HOOK (eh, register_info); HOOK (eh, syscall_abi); -- 2.1.0
