Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ARM: Consolidate with generic unwinder wrapper code
  • Loading branch information
Roland McGrath committed Jan 5, 2015
1 parent 61695fb commit 46abb64
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 293 deletions.
28 changes: 28 additions & 0 deletions ChangeLog
@@ -1,3 +1,31 @@
2015-01-05 Roland McGrath <roland@hack.frob.com>

* sysdeps/generic/unwind-resume.h: New file.
* sysdeps/gnu/unwind-resume.c: Include it.
(libgcc_s_personality): Use PERSONALITY_PROTO macro for the prototype.
(__gcc_personality_v0): Likewise, and PERSONALITY_ARGS for the callee
argument list.
(libgcc_s_resume): Variable renamed to __libgcc_s_resume, made hidden
global rather than static.
(_Unwind_Resume): Update user.
Conditionalize definition on [!HAVE_ARCH_UNWIND_RESUME].
(init): Likewise. Renamed to __libgcc_s_init, made hidden global
rather than static. Add __attribute__ ((cold)).
(_Unwind_Resume, __gcc_personality_v0): Update callers.
* sysdeps/nptl/unwind-forcedunwind.c: Likewise.
* sysdeps/arm/arm-unwind-resume.S: New file.
* sysdeps/arm/rt-arm-unwind-resume.S: New file.
* sysdeps/arm/pt-arm-unwind-resume.S: New file.
* sysdeps/arm/Makefile [$(subdir) = csu]
(sysdep_routines, shared-only-routines): Add arm-unwind-resume.
[$(subdir) = rt] (librt-sysdep_routines, librt-shared-only-routines):
Add rt-arm-unwind-resume.
[$(subdir) = nptl]
(libpthread-sysdep_routines, libpthread-shared-only-routines):
Add pt-arm-unwind-resume.
* sysdeps/unix/sysv/linux/arm/unwind-resume.c: File removed.
* sysdeps/unix/sysv/linux/arm/unwind-forcedunwind.c: File removed.

2015-01-05 Joseph Myers <joseph@codesourcery.com>

[BZ #17748]
Expand Down
12 changes: 10 additions & 2 deletions sysdeps/arm/Makefile
Expand Up @@ -50,6 +50,9 @@ shared-only-routines += libc-aeabi_read_tp
# cantunwind marker. There's one in start.S. To make sure we reach it, add
# unwind tables for __libc_start_main.
CFLAGS-libc-start.c += -fexceptions

sysdep_routines += arm-unwind-resume
shared-only-routines += arm-unwind-resume
endif

ifeq ($(subdir),gmon)
Expand All @@ -61,6 +64,11 @@ CFLAGS-backtrace.c += -funwind-tables
endif

ifeq ($(subdir),rt)
librt-sysdep_routines += rt-aeabi_unwind_cpp_pr1
librt-shared-only-routines += rt-aeabi_unwind_cpp_pr1
librt-sysdep_routines += rt-aeabi_unwind_cpp_pr1 rt-arm-unwind-resume
librt-shared-only-routines += rt-aeabi_unwind_cpp_pr1 rt-arm-unwind-resume
endif

ifeq ($(subdir),nptl)
libpthread-sysdep_routines += pt-arm-unwind-resume
libpthread-shared-only-routines += pt-arm-unwind-resume
endif
46 changes: 46 additions & 0 deletions sysdeps/arm/arm-unwind-resume.S
@@ -0,0 +1,46 @@
/* _Unwind_Resume wrapper for ARM EABI.
Copyright (C) 2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */

#include <sysdep.h>

/* This is just implementing exactly what the C version does.
We do it in assembly just to ensure that we get an unmolested tail
call to the libgcc function, which is necessary for the ARM unwinder. */

ENTRY (_Unwind_Resume)
LDR_HIDDEN (ip, ip, __libgcc_s_resume, 0)
cmp ip, #0
beq 1f
0: PTR_DEMANGLE (ip, ip, r2, r3)
bx ip

/* We need to save and restore LR (for our own return address)
and R0 (for the argument to _Unwind_Resume) around the call. */
1: push {r0, lr}
cfi_adjust_cfa_offset (8)
cfi_rel_offset (r0, 0)
cfi_rel_offset (lr, 4)
bl __libgcc_s_init
pop {r0, lr}
cfi_adjust_cfa_offset (-8)
cfi_restore (r0)
cfi_restore (lr)

LDR_HIDDEN (ip, ip, __libgcc_s_resume, 0)
b 0b
END (_Unwind_Resume)
2 changes: 2 additions & 0 deletions sysdeps/arm/pt-arm-unwind-resume.S
@@ -0,0 +1,2 @@
#define __libgcc_s_init pthread_cancel_init
#include <arm-unwind-resume.S>
1 change: 1 addition & 0 deletions sysdeps/arm/rt-arm-unwind-resume.S
@@ -0,0 +1 @@
#include <arm-unwind-resume.S>
33 changes: 33 additions & 0 deletions sysdeps/arm/unwind-resume.h
@@ -0,0 +1,33 @@
/* Definitions for unwind-resume.c. ARM (EABI) version.
Copyright (C) 2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, see <http://www.gnu.org/licenses/>. */

/* The EABI personality routine has a different signature than the
canonical one. These macros tell sysdeps/gnu/unwind*.c how to
define __gcc_personality_v0. */
#define PERSONALITY_PROTO \
(_Unwind_State state, \
struct _Unwind_Exception *ue_header, \
struct _Unwind_Context *context)
#define PERSONALITY_ARGS \
(state, ue_header, context)

/* It's vitally important that _Unwind_Resume not have a stack frame; the
ARM unwinder relies on register state at entrance. So we write this in
assembly (see arm-unwind-resume.S). This macro tells the generic code
not to provide the generic C definition. */
#define HAVE_ARCH_UNWIND_RESUME 1
33 changes: 33 additions & 0 deletions sysdeps/generic/unwind-resume.h
@@ -0,0 +1,33 @@
/* Definitions for unwind-resume.c. Generic version.
Copyright (C) 2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, see <http://www.gnu.org/licenses/>. */

/* These describe the arguments to unwinder personality functions,
specifically __gcc_personality_v0. A machine-specific sysdeps
file might define them differently. */
#define PERSONALITY_PROTO \
(int version, _Unwind_Action actions, \
_Unwind_Exception_Class exception_class, \
struct _Unwind_Exception *ue_header, \
struct _Unwind_Context *context)
#define PERSONALITY_ARGS \
(version, actions, exception_class, ue_header, context)

/* This is defined nonzero by a machine-specific sysdeps file if
_Unwind_Resume is provided separately and thus the generic C
version should not be defined. */
#define HAVE_ARCH_UNWIND_RESUME 0
35 changes: 17 additions & 18 deletions sysdeps/gnu/unwind-resume.c
Expand Up @@ -21,15 +21,16 @@
#include <unwind.h>
#include <gnu/lib-names.h>
#include <sysdep.h>
#include <unwind-resume.h>

static void (*libgcc_s_resume) (struct _Unwind_Exception *exc)
__attribute__ ((noreturn));
static _Unwind_Reason_Code (*libgcc_s_personality)
(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
struct _Unwind_Context *);

static void
init (void)
void (*__libgcc_s_resume) (struct _Unwind_Exception *exc)
attribute_hidden __attribute__ ((noreturn));

static _Unwind_Reason_Code (*libgcc_s_personality) PERSONALITY_PROTO;

void attribute_hidden __attribute__ ((cold))
__libgcc_s_init (void)
{
void *resume, *personality;
void *handle;
Expand All @@ -43,33 +44,31 @@ init (void)
" must be installed for pthread_cancel to work\n");

PTR_MANGLE (resume);
libgcc_s_resume = resume;
__libgcc_s_resume = resume;
PTR_MANGLE (personality);
libgcc_s_personality = personality;
}

#if !HAVE_ARCH_UNWIND_RESUME
void
_Unwind_Resume (struct _Unwind_Exception *exc)
{
if (__glibc_unlikely (libgcc_s_resume == NULL))
init ();
if (__glibc_unlikely (__libgcc_s_resume == NULL))
__libgcc_s_init ();

__typeof (libgcc_s_resume) resume = libgcc_s_resume;
__typeof (__libgcc_s_resume) resume = __libgcc_s_resume;
PTR_DEMANGLE (resume);
(*resume) (exc);
}
#endif

_Unwind_Reason_Code
__gcc_personality_v0 (int version, _Unwind_Action actions,
_Unwind_Exception_Class exception_class,
struct _Unwind_Exception *ue_header,
struct _Unwind_Context *context)
__gcc_personality_v0 PERSONALITY_PROTO
{
if (__glibc_unlikely (libgcc_s_personality == NULL))
init ();
__libgcc_s_init ();

__typeof (libgcc_s_personality) personality = libgcc_s_personality;
PTR_DEMANGLE (personality);

return (*personality) (version, actions, exception_class, ue_header, context);
return (*personality) PERSONALITY_ARGS;
}
25 changes: 11 additions & 14 deletions sysdeps/nptl/unwind-forcedunwind.c
Expand Up @@ -22,12 +22,12 @@
#include <pthreadP.h>
#include <sysdep.h>
#include <gnu/lib-names.h>
#include <unwind-resume.h>

static void *libgcc_s_handle;
static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
static _Unwind_Reason_Code (*libgcc_s_personality)
(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
struct _Unwind_Context *);
void (*__libgcc_s_resume) (struct _Unwind_Exception *exc)
attribute_hidden __attribute__ ((noreturn));
static _Unwind_Reason_Code (*libgcc_s_personality) PERSONALITY_PROTO;
static _Unwind_Reason_Code (*libgcc_s_forcedunwind)
(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
static _Unwind_Word (*libgcc_s_getcfa) (struct _Unwind_Context *);
Expand Down Expand Up @@ -64,7 +64,7 @@ pthread_cancel_init (void)
__libc_fatal (LIBGCC_S_SO " must be installed for pthread_cancel to work\n");

PTR_MANGLE (resume);
libgcc_s_resume = resume;
__libgcc_s_resume = resume;
PTR_MANGLE (personality);
libgcc_s_personality = personality;
PTR_MANGLE (forcedunwind);
Expand All @@ -90,6 +90,7 @@ __unwind_freeres (void)
}
}

#if !HAVE_ARCH_UNWIND_RESUME
void
_Unwind_Resume (struct _Unwind_Exception *exc)
{
Expand All @@ -98,27 +99,23 @@ _Unwind_Resume (struct _Unwind_Exception *exc)
else
atomic_read_barrier ();

void (*resume) (struct _Unwind_Exception *exc) = libgcc_s_resume;
void (*resume) (struct _Unwind_Exception *exc) = __libgcc_s_resume;
PTR_DEMANGLE (resume);
resume (exc);
}
#endif

_Unwind_Reason_Code
__gcc_personality_v0 (int version, _Unwind_Action actions,
_Unwind_Exception_Class exception_class,
struct _Unwind_Exception *ue_header,
struct _Unwind_Context *context)
__gcc_personality_v0 PERSONALITY_PROTO
{
if (__glibc_unlikely (libgcc_s_handle == NULL))
pthread_cancel_init ();
else
atomic_read_barrier ();

_Unwind_Reason_Code (*personality)
(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
struct _Unwind_Context *) = libgcc_s_personality;
__typeof (libgcc_s_personality) personality = libgcc_s_personality;
PTR_DEMANGLE (personality);
return personality (version, actions, exception_class, ue_header, context);
return (*personality) PERSONALITY_ARGS;
}

_Unwind_Reason_Code
Expand Down

0 comments on commit 46abb64

Please sign in to comment.