annotate gcc/config/powerpcspe/host-darwin.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Darwin/powerpc host-specific hook definitions.
kono
parents:
diff changeset
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published
kono
parents:
diff changeset
8 by the Free Software Foundation; either version 3, or (at your
kono
parents:
diff changeset
9 option) any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
kono
parents:
diff changeset
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
kono
parents:
diff changeset
14 License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "diagnostic.h"
kono
parents:
diff changeset
24 #include <sys/ucontext.h>
kono
parents:
diff changeset
25 #include "hosthooks.h"
kono
parents:
diff changeset
26 #include "hosthooks-def.h"
kono
parents:
diff changeset
27 #include "config/host-darwin.h"
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 static void segv_crash_handler (int);
kono
parents:
diff changeset
30 static void segv_handler (int, siginfo_t *, void *);
kono
parents:
diff changeset
31 static void darwin_rs6000_extra_signals (void);
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #ifndef HAVE_DECL_SIGALTSTACK
kono
parents:
diff changeset
34 /* This doesn't have a prototype in signal.h in 10.2.x and earlier,
kono
parents:
diff changeset
35 fixed in later releases. */
kono
parents:
diff changeset
36 extern int sigaltstack(const struct sigaltstack *, struct sigaltstack *);
kono
parents:
diff changeset
37 #endif
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 /* The fields of the mcontext_t type have acquired underscores in later
kono
parents:
diff changeset
40 OS versions. */
kono
parents:
diff changeset
41 #ifdef HAS_MCONTEXT_T_UNDERSCORES
kono
parents:
diff changeset
42 #define MC_FLD(x) __ ## x
kono
parents:
diff changeset
43 #else
kono
parents:
diff changeset
44 #define MC_FLD(x) x
kono
parents:
diff changeset
45 #endif
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 #undef HOST_HOOKS_EXTRA_SIGNALS
kono
parents:
diff changeset
48 #define HOST_HOOKS_EXTRA_SIGNALS darwin_rs6000_extra_signals
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* On Darwin/powerpc, hitting the stack limit turns into a SIGSEGV.
kono
parents:
diff changeset
51 This code detects the difference between hitting the stack limit and
kono
parents:
diff changeset
52 a true wild pointer dereference by looking at the instruction that
kono
parents:
diff changeset
53 faulted; only a few kinds of instruction are used to access below
kono
parents:
diff changeset
54 the previous bottom of the stack. */
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 static void
kono
parents:
diff changeset
57 segv_crash_handler (int sig ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 internal_error ("Segmentation Fault (code)");
kono
parents:
diff changeset
60 }
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 static void
kono
parents:
diff changeset
63 segv_handler (int sig ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
64 siginfo_t *sip ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
65 void *scp)
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 ucontext_t *uc = (ucontext_t *)scp;
kono
parents:
diff changeset
68 sigset_t sigset;
kono
parents:
diff changeset
69 unsigned faulting_insn;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 /* The fault might have happened when trying to run some instruction, in
kono
parents:
diff changeset
72 which case the next line will segfault _again_. Handle this case. */
kono
parents:
diff changeset
73 signal (SIGSEGV, segv_crash_handler);
kono
parents:
diff changeset
74 sigemptyset (&sigset);
kono
parents:
diff changeset
75 sigaddset (&sigset, SIGSEGV);
kono
parents:
diff changeset
76 sigprocmask (SIG_UNBLOCK, &sigset, NULL);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 faulting_insn = *(unsigned *)uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0);
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /* Note that this only has to work for GCC, so we don't have to deal
kono
parents:
diff changeset
81 with all the possible cases (GCC has no AltiVec code, for
kono
parents:
diff changeset
82 instance). It's complicated because Darwin allows stores to
kono
parents:
diff changeset
83 below the stack pointer, and the prologue code takes advantage of
kono
parents:
diff changeset
84 this. */
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 if ((faulting_insn & 0xFFFF8000) == 0x94218000 /* stwu %r1, -xxx(%r1) */
kono
parents:
diff changeset
87 || (faulting_insn & 0xFC1F03FF) == 0x7C01016E /* stwux xxx, %r1, xxx */
kono
parents:
diff changeset
88 || (faulting_insn & 0xFC1F8000) == 0x90018000 /* stw xxx, -yyy(%r1) */
kono
parents:
diff changeset
89 || (faulting_insn & 0xFC1F8000) == 0xD8018000 /* stfd xxx, -yyy(%r1) */
kono
parents:
diff changeset
90 || (faulting_insn & 0xFC1F8000) == 0xBC018000 /* stmw xxx, -yyy(%r1) */)
kono
parents:
diff changeset
91 {
kono
parents:
diff changeset
92 char *shell_name;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 fnotice (stderr, "Out of stack space.\n");
kono
parents:
diff changeset
95 shell_name = getenv ("SHELL");
kono
parents:
diff changeset
96 if (shell_name != NULL)
kono
parents:
diff changeset
97 shell_name = strrchr (shell_name, '/');
kono
parents:
diff changeset
98 if (shell_name != NULL)
kono
parents:
diff changeset
99 {
kono
parents:
diff changeset
100 static const char * shell_commands[][2] = {
kono
parents:
diff changeset
101 { "sh", "ulimit -S -s unlimited" },
kono
parents:
diff changeset
102 { "bash", "ulimit -S -s unlimited" },
kono
parents:
diff changeset
103 { "tcsh", "limit stacksize unlimited" },
kono
parents:
diff changeset
104 { "csh", "limit stacksize unlimited" },
kono
parents:
diff changeset
105 /* zsh doesn't have "unlimited", this will work under the
kono
parents:
diff changeset
106 default configuration. */
kono
parents:
diff changeset
107 { "zsh", "limit stacksize 32m" }
kono
parents:
diff changeset
108 };
kono
parents:
diff changeset
109 size_t i;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 for (i = 0; i < ARRAY_SIZE (shell_commands); i++)
kono
parents:
diff changeset
112 if (strcmp (shell_commands[i][0], shell_name + 1) == 0)
kono
parents:
diff changeset
113 {
kono
parents:
diff changeset
114 fnotice (stderr,
kono
parents:
diff changeset
115 "Try running '%s' in the shell to raise its limit.\n",
kono
parents:
diff changeset
116 shell_commands[i][1]);
kono
parents:
diff changeset
117 }
kono
parents:
diff changeset
118 }
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 if (global_dc->abort_on_error)
kono
parents:
diff changeset
121 fancy_abort (__FILE__, __LINE__, __FUNCTION__);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 exit (FATAL_EXIT_CODE);
kono
parents:
diff changeset
124 }
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 fprintf (stderr, "[address=%08lx pc=%08x]\n",
kono
parents:
diff changeset
127 uc->uc_mcontext->MC_FLD(es).MC_FLD(dar),
kono
parents:
diff changeset
128 uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0));
kono
parents:
diff changeset
129 internal_error ("Segmentation Fault");
kono
parents:
diff changeset
130 exit (FATAL_EXIT_CODE);
kono
parents:
diff changeset
131 }
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 static void
kono
parents:
diff changeset
134 darwin_rs6000_extra_signals (void)
kono
parents:
diff changeset
135 {
kono
parents:
diff changeset
136 struct sigaction sact;
kono
parents:
diff changeset
137 stack_t sigstk;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 sigstk.ss_sp = (char*)xmalloc (SIGSTKSZ);
kono
parents:
diff changeset
140 sigstk.ss_size = SIGSTKSZ;
kono
parents:
diff changeset
141 sigstk.ss_flags = 0;
kono
parents:
diff changeset
142 if (sigaltstack (&sigstk, NULL) < 0)
kono
parents:
diff changeset
143 fatal_error (input_location, "While setting up signal stack: %m");
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 sigemptyset(&sact.sa_mask);
kono
parents:
diff changeset
146 sact.sa_flags = SA_ONSTACK | SA_SIGINFO;
kono
parents:
diff changeset
147 sact.sa_sigaction = segv_handler;
kono
parents:
diff changeset
148 if (sigaction (SIGSEGV, &sact, 0) < 0)
kono
parents:
diff changeset
149 fatal_error (input_location, "While setting up signal handler: %m");
kono
parents:
diff changeset
150 }
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;