summaryrefslogtreecommitdiff
blob: 94342cc656336496b5943a93cc673d63f7b34cae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
2003-08-29  Jakub Jelinek  <jakub@redhat.com>

	* dw2gencfi.c (cfi_pseudo_table): Add cfi_window_save.
	(dot_cfi, output_cfi_insn): Handle DW_CFA_GNU_window_save.
	(output_cie): Don't use DW_EH_PE_pcrel if neither DIFF_EXPR_OK
	nor tc_cfi_emit_pcrel_expr are defined.
	(output_fde): Use tc_cfi_emit_pcrel_expr if available and
	DIFF_EXPR_OK is not defined.
	* config/tc-sparc.h (TARGET_USE_CFIPOP): Define.
	(tc_cfi_frame_initial_instructions, tc_regname_to_dw2regnum,
	tc_cfi_emit_pcrel_expr): Define.
	(sparc_cfi_frame_initial_instructions, sparc_regname_to_dw2regnum,
	sparc_cfi_emit_pcrel_expr): New prototypes.
	(sparc_cie_data_alignment): New decl.
	(DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT): Define.
	* config/tc-sparc.c: Include dw2gencfi.h.
	(sparc_cie_data_alignment): New variable.
	(md_begin): Initialize it.
	(sparc_cfi_frame_initial_instructions): New function.
	(sparc_regname_to_dw2regnum): Likewise.
	(sparc_cfi_emit_pcrel_expr): Likewise.
	* doc/as.texinfo: Document .cfi_window_save.

	* config/tc-sparc.c (s_common): Cast last argument to long and
	change format string to shut up warning.
testsuite/
	* gas/cfi/cfi-sparc-1.s: New test.
	* gas/cfi/cfi-sparc-1.d: New test.
	* gas/cfi/cfi-sparc64-1.s: New test.
	* gas/cfi/cfi-sparc64-1.d: New test.
	* gas/cfi/cfi.exp: Run them.

--- gas/dw2gencfi.c.jj	2003-06-18 13:57:59.000000000 -0400
+++ gas/dw2gencfi.c	2003-08-29 14:00:41.000000000 -0400
@@ -374,6 +374,7 @@ const pseudo_typeS cfi_pseudo_table[] =
     { "cfi_same_value", dot_cfi, DW_CFA_same_value },
     { "cfi_remember_state", dot_cfi, DW_CFA_remember_state },
     { "cfi_restore_state", dot_cfi, DW_CFA_restore_state },
+    { "cfi_window_save", dot_cfi, DW_CFA_GNU_window_save },
     { "cfi_escape", dot_cfi_escape, 0 },
     { NULL, NULL, 0 }
   };
@@ -529,6 +530,10 @@ dot_cfi (int arg)
       cfi_add_CFA_restore_state ();
       break;
 
+    case DW_CFA_GNU_window_save:
+      cfi_add_CFA_insn (DW_CFA_GNU_window_save);
+      break;
+
     default:
       abort ();
     }
@@ -798,6 +803,10 @@ output_cfi_insn (struct cfi_insn_data *i
       out_one (insn->insn);
       break;
 
+    case DW_CFA_GNU_window_save:
+      out_one (DW_CFA_GNU_window_save);
+      break;
+
     case CFI_escape:
       {
 	struct cfi_escape_data *e;
@@ -838,7 +847,11 @@ output_cie (struct cie_entry *cie)
   out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT);	/* Data alignment */
   out_one (cie->return_column);			/* Return column */
   out_uleb128 (1);				/* Augmentation size */
+#if defined DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
   out_one (DW_EH_PE_pcrel | DW_EH_PE_sdata4);
+#else
+  out_one (DW_EH_PE_sdata4);
+#endif
 
   if (cie->first)
     for (i = cie->first; i != cie->last; i = i->next)
@@ -867,10 +880,22 @@ output_fde (struct fde_entry *fde, struc
   exp.X_add_symbol = after_size_address;
   exp.X_op_symbol = cie->start_address;
   emit_expr (&exp, 4);				/* CIE offset */
-  
+
+#ifdef DIFF_EXPR_OK  
   exp.X_add_symbol = fde->start_address;
   exp.X_op_symbol = symbol_temp_new_now ();
   emit_expr (&exp, 4);				/* Code offset */
+#else
+  exp.X_op = O_symbol;
+  exp.X_add_symbol = fde->start_address;
+  exp.X_op_symbol = NULL;
+#ifdef tc_cfi_emit_pcrel_expr
+  tc_cfi_emit_pcrel_expr (&exp, 4);		/* Code offset */
+#else
+  emit_expr (&exp, 4);				/* Code offset */
+#endif
+  exp.X_op = O_subtract;
+#endif
 
   exp.X_add_symbol = fde->end_address;
   exp.X_op_symbol = fde->start_address;		/* Code length */
--- gas/config/tc-sparc.h.jj	2003-01-24 18:37:51.000000000 -0500
+++ gas/config/tc-sparc.h	2003-08-29 15:38:47.000000000 -0400
@@ -174,6 +174,21 @@ extern void cons_fix_new_sparc
     }									\
   while (0)
 
-#define DWARF2_LINE_MIN_INSN_LENGTH 4
+#define TARGET_USE_CFIPOP 1
+
+#define tc_cfi_frame_initial_instructions sparc_cfi_frame_initial_instructions
+extern void sparc_cfi_frame_initial_instructions PARAMS ((void));
+
+#define tc_regname_to_dw2regnum sparc_regname_to_dw2regnum
+extern int sparc_regname_to_dw2regnum PARAMS ((const char *regname));
+
+#define tc_cfi_emit_pcrel_expr sparc_cfi_emit_pcrel_expr
+extern void sparc_cfi_emit_pcrel_expr PARAMS ((expressionS *, unsigned int));
+
+extern int sparc_cie_data_alignment;
+
+#define DWARF2_LINE_MIN_INSN_LENGTH     4
+#define DWARF2_DEFAULT_RETURN_COLUMN    15
+#define DWARF2_CIE_DATA_ALIGNMENT       sparc_cie_data_alignment
 
 /* end of tc-sparc.h */
--- gas/config/tc-sparc.c.jj	2003-07-02 11:01:56.000000000 -0400
+++ gas/config/tc-sparc.c	2003-08-29 15:39:10.000000000 -0400
@@ -26,6 +26,7 @@
 #include "subsegs.h"
 
 #include "opcode/sparc.h"
+#include "dw2gencfi.h"
 
 #ifdef OBJ_ELF
 #include "elf/sparc.h"
@@ -116,6 +117,9 @@ static int target_little_endian_data;
 /* Symbols for global registers on v9.  */
 static symbolS *globals[8];
 
+/* The dwarf2 data alignment, adjusted for 32 or 64 bit.  */
+int sparc_cie_data_alignment;
+
 /* V9 and 86x have big and little endian data, but instructions are always big
    endian.  The sparclet has bi-endian support but both data and insns have
    the same endianness.  Global `target_big_endian' is used for data.
@@ -798,6 +802,7 @@ md_begin ()
   if (! default_init_p)
     init_default_arch ();
 
+  sparc_cie_data_alignment = sparc_arch_size == 64 ? -8 : -4;
   op_hash = hash_new ();
 
   while (i < (unsigned int) sparc_num_opcodes)
@@ -3804,8 +3809,8 @@ s_common (ignore)
     {
       if (S_GET_VALUE (symbolP) != (valueT) size)
 	{
-	  as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
-		   S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
+	  as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
+		   S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), (long) size);
 	}
     }
   else
@@ -4482,4 +4487,63 @@ cons_fix_new_sparc (frag, where, nbytes,
    }
 
   fix_new_exp (frag, where, (int) nbytes, exp, 0, r);
+  sparc_cons_special_reloc = NULL;
+}
+
+void
+sparc_cfi_frame_initial_instructions ()
+{
+  cfi_add_CFA_def_cfa (14, sparc_arch_size == 64 ? 0x7ff : 0);
+}
+
+int
+sparc_regname_to_dw2regnum (const char *regname)
+{
+  char *p, *q;
+
+  if (!regname[0])
+    return -1;
+
+  q = "goli";
+  p = strchr (q, regname[0]);
+  if (p)
+    {
+      if (regname[1] < '0' || regname[1] > '8' || regname[2])
+	return -1;
+      return (p - q) * 8 + regname[1] - '0';
+    }
+  if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
+    return 14;
+  if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
+    return 30;
+  if (regname[0] == 'f' || regname[0] == 'r')
+    {
+      unsigned int regnum;
+
+      regnum = strtoul (regname + 1, &q, 10);
+      if (p == q || *q)
+        return -1;
+      if (regnum >= ((regname[0] == 'f'
+		      && SPARC_OPCODE_ARCH_V9_P (max_architecture))
+		     ? 64 : 32))
+	return -1;
+      if (regname[0] == 'f')
+	{
+          regnum += 32;
+          if (regnum >= 64 && (regnum & 1))
+	    return -1;
+        }
+      return regnum;
+    }
+  return -1;
+}
+
+void
+sparc_cfi_emit_pcrel_expr (expressionS *exp, unsigned int nbytes)
+{
+  sparc_cons_special_reloc = "disp";
+  sparc_no_align_cons = 1;
+  emit_expr (exp, nbytes);
+  sparc_no_align_cons = 0;
+  sparc_cons_special_reloc = NULL;
 }
--- gas/doc/as.texinfo.jj	2003-07-29 05:40:36.000000000 -0400
+++ gas/doc/as.texinfo	2003-08-29 15:29:21.000000000 -0400
@@ -4050,6 +4050,9 @@ using the known displacement of the CFA 
 This is often easier to use, because the number will match the
 code it's annotating.
 
+@section @code{.cfi_window_save}
+SPARC register window has been saved.
+
 @section @code{.cfi_escape} @var{expression}[, @dots{}]
 Allows the user to add arbitrary bytes to the unwind info.  One
 might use this to add OS-specific CFI opcodes, or generic CFI
--- gas/testsuite/gas/cfi/cfi-sparc-1.s.jj	2003-08-28 05:56:33.000000000 -0400
+++ gas/testsuite/gas/cfi/cfi-sparc-1.s	2003-08-28 06:26:37.000000000 -0400
@@ -0,0 +1,23 @@
+#; $ as -o test.o -32 gas-cfi-test.s && gcc -m32 -nostdlib -o test test.o
+
+	.file	"a.c"
+	.text
+	.align	4
+	.globl foo
+	.type	foo, @function
+foo:
+	.cfi_startproc
+        save    %sp, -104, %sp
+	.cfi_def_cfa_register	%fp
+	.cfi_window_save
+	.cfi_register	%o7, %i7
+	add	%i0, 1, %o0
+	call	bar, 0
+	add	%i0, 2, %i0
+	call	bar, 0
+	mov	%i0, %o0
+	add	%o0, 3, %o0
+	ret
+	restore	%g0, %o0, %o0
+	.cfi_endproc
+	.size	foo, .-foo
--- gas/testsuite/gas/cfi/cfi-sparc64-1.s.jj	2003-08-28 05:56:33.000000000 -0400
+++ gas/testsuite/gas/cfi/cfi-sparc64-1.s	2003-08-28 06:26:44.000000000 -0400
@@ -0,0 +1,26 @@
+#; $ as -o test.o -64 gas-cfi-test.s && gcc -m64 -nostdlib -o test test.o
+
+	.file	"a.c"
+	.text
+	.align	4
+	.globl foo
+	.type	foo, @function
+foo:
+	.cfi_startproc
+	save	%sp, -192, %sp
+	.cfi_def_cfa_register	%fp
+	.cfi_window_save
+	.cfi_register	%o7, %i7
+	add	%i0, 1, %o0
+	add	%i0, 2, %i0
+	call	bar, 0
+	sra	%o0, 0, %o0
+	sra	%i0, 0, %i0
+	call	bar, 0
+	mov	%i0, %o0
+	add	%o0, 3, %o0
+	sra	%o0, 0, %o0
+	ret
+	restore	%g0, %o0, %o0
+	.cfi_endproc
+	.size	foo, .-foo
--- gas/testsuite/gas/cfi/cfi-sparc-1.d.jj	2003-08-29 15:17:54.000000000 -0400
+++ gas/testsuite/gas/cfi/cfi-sparc-1.d	2003-08-29 15:17:44.000000000 -0400
@@ -0,0 +1,22 @@
+#readelf: -wf
+#name: CFI on SPARC 32-bit
+#as: -32
+
+The section .eh_frame contains:
+
+00000000 00000010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -4
+  Return address column: 15
+  Augmentation data:     1b
+
+  DW_CFA_def_cfa: r14 ofs 0
+
+00000014 00000014 00000018 FDE cie=00000000 pc=0000001c..00000040
+  DW_CFA_advance_loc: 4 to 00000020
+  DW_CFA_def_cfa_reg: r30
+  DW_CFA_GNU_window_save
+  DW_CFA_register: r15 in r31
+
--- gas/testsuite/gas/cfi/cfi-sparc64-1.d.jj	2003-08-29 15:17:51.000000000 -0400
+++ gas/testsuite/gas/cfi/cfi-sparc64-1.d	2003-08-29 15:17:35.000000000 -0400
@@ -0,0 +1,25 @@
+#readelf: -wf
+#name: CFI on SPARC 64-bit
+#as: -64
+
+The section .eh_frame contains:
+
+00000000 00000011 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 15
+  Augmentation data:     1b
+
+  DW_CFA_def_cfa: r14 ofs 2047
+
+00000015 00000017 00000019 FDE cie=00000000 pc=0000001d..0000004d
+  DW_CFA_advance_loc: 4 to 00000021
+  DW_CFA_def_cfa_reg: r30
+  DW_CFA_GNU_window_save
+  DW_CFA_register: r15 in r31
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+
--- gas/testsuite/gas/cfi/cfi.exp.jj	2003-08-10 15:56:11.000000000 -0400
+++ gas/testsuite/gas/cfi/cfi.exp	2003-08-29 15:23:29.000000000 -0400
@@ -39,6 +39,16 @@ if [istarget "x86_64-*"] then {
 } elseif { [istarget "m68*-*"] } then {
     run_dump_test "cfi-m68k"
 
+} elseif { [istarget sparc*-*-*] } then {
+    global NM
+    global NMFLAGS
+    global srcdir
+
+    catch "exec $srcdir/lib/run $NM $NMFLAGS --help" nm_help
+    run_dump_test "cfi-sparc-1"
+    if { [regexp "elf64\[_-\]sparc" $nm_help] } then {
+	run_dump_test "cfi-sparc64-1"
+    }
 } else {
     return
 }