aboutsummaryrefslogtreecommitdiff
path: root/gas/scfidw2gen.c
blob: 2b018fac8bdf5e58e8330ba981d153a5038b4a06 (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
/* scfidw2gen.c - Support for emission of synthesized Dwarf2 CFI.
   Copyright (C) 2023 Free Software Foundation, Inc.

   This file is part of GAS, the GNU Assembler.

   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GAS 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 General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GAS; see the file COPYING.  If not, write to the Free
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

#include "as.h"
#include "ginsn.h"
#include "scfi.h"
#include "dw2gencfi.h"
#include "subsegs.h"
#include "scfidw2gen.h"

#if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)

static bool scfi_ignore_warn_once;

static void
dot_scfi_ignore (int ignored ATTRIBUTE_UNUSED)
{
  gas_assert (flag_synth_cfi);

  if (!scfi_ignore_warn_once)
    {
      as_warn (_("SCFI ignores most user-specified CFI directives"));
      scfi_ignore_warn_once = true;
    }
  ignore_rest_of_line ();
}

static void
scfi_process_cfi_label (void)
{
  char *name;
  ginsnS *ginsn;

  name = read_symbol_name ();
  if (name == NULL)
    return;

  /* Add a new ginsn.  */
  ginsn = ginsn_new_phantom (symbol_temp_new_now ());
  frch_ginsn_data_append (ginsn);

  scfi_op_add_cfi_label (ginsn, name);
  /* NB: Can't free NAME here since it will be used later.  Free it in
     handle_scfi_dot_cfi after it is unused.  */

  demand_empty_rest_of_line ();
}

static void
scfi_process_cfi_signal_frame (void)
{
  ginsnS *ginsn;

  ginsn = ginsn_new_phantom (symbol_temp_new_now ());
  frch_ginsn_data_append (ginsn);

  scfi_op_add_signal_frame (ginsn);
}

static void
dot_scfi (int arg)
{
  switch (arg)
    {
      case CFI_label:
	scfi_process_cfi_label ();
	break;
      case CFI_signal_frame:
	scfi_process_cfi_signal_frame ();
	break;
      default:
	abort ();
    }
}

const pseudo_typeS scfi_pseudo_table[] =
  {
    { "cfi_sections", dot_cfi_sections, 0 }, /* No ignore.  */
    { "cfi_signal_frame", dot_scfi, CFI_signal_frame }, /* No ignore.  */
    { "cfi_label", dot_scfi, CFI_label }, /* No ignore.  */
    { "cfi_startproc", dot_scfi_ignore, 0 },
    { "cfi_endproc", dot_scfi_ignore, 0 },
    { "cfi_fde_data", dot_scfi_ignore, 0 },
    { "cfi_def_cfa", dot_scfi_ignore, 0 },
    { "cfi_def_cfa_register", dot_scfi_ignore, 0 },
    { "cfi_def_cfa_offset", dot_scfi_ignore, 0 },
    { "cfi_adjust_cfa_offset", dot_scfi_ignore, 0 },
    { "cfi_offset", dot_scfi_ignore, 0 },
    { "cfi_rel_offset", dot_scfi_ignore, 0 },
    { "cfi_register", dot_scfi_ignore, 0 },
    { "cfi_return_column", dot_scfi_ignore, 0 },
    { "cfi_restore", dot_scfi_ignore, 0 },
    { "cfi_undefined", dot_scfi_ignore, 0 },
    { "cfi_same_value", dot_scfi_ignore, 0 },
    { "cfi_remember_state", dot_scfi_ignore, 0 },
    { "cfi_restore_state", dot_scfi_ignore, 0 },
    { "cfi_window_save", dot_scfi_ignore, 0 },
    { "cfi_negate_ra_state", dot_scfi_ignore, 0 },
    { "cfi_escape", dot_scfi_ignore, 0 },
    { "cfi_personality", dot_scfi_ignore, 0 },
    { "cfi_personality_id", dot_scfi_ignore, 0 },
    { "cfi_lsda", dot_scfi_ignore, 0 },
    { "cfi_val_encoded_addr", dot_scfi_ignore, 0 },
    { "cfi_inline_lsda", dot_scfi_ignore, 0 },
    { "cfi_val_offset", dot_scfi_ignore, 0 },
    { NULL, NULL, 0 }
  };

void
scfi_dot_cfi_startproc (const symbolS *start_sym)
{
  if (frchain_now->frch_cfi_data != NULL)
    {
      as_bad (_("SCFI: missing previous SCFI endproc marker"));
      return;
    }

  cfi_new_fde ((symbolS *)start_sym);

  cfi_set_sections ();

  frchain_now->frch_cfi_data->cur_cfa_offset = 0;

  /* By default, SCFI machinery assumes .cfi_startproc is used without
     parameter simple.  */
  tc_cfi_frame_initial_instructions ();

  if ((all_cfi_sections & CFI_EMIT_target) != 0)
    tc_cfi_startproc ();
}

void
scfi_dot_cfi_endproc (const symbolS *end_sym)
{
  struct fde_entry *fde_last;

  if (frchain_now->frch_cfi_data == NULL)
    {
      as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
      return;
    }

  fde_last = frchain_now->frch_cfi_data->cur_fde_data;
  cfi_set_last_fde (fde_last);

  cfi_end_fde ((symbolS *)end_sym);

  if ((all_cfi_sections & CFI_EMIT_target) != 0)
    tc_cfi_endproc (fde_last);
}

void
scfi_dot_cfi (int arg, unsigned reg1, unsigned reg2, offsetT offset,
	      const char *name, const symbolS *advloc)
{
  if (frchain_now->frch_cfi_data == NULL)
    {
      as_bad (_("CFI instruction used without previous .cfi_startproc"));
      return;
    }

  /* If the last address was not at the current PC, advance to current.  */
  if (frchain_now->frch_cfi_data->last_address != advloc)
    cfi_add_advance_loc ((symbolS *)advloc);

  switch (arg)
    {
    case DW_CFA_offset:
      cfi_add_CFA_offset (reg1, offset);
      break;

    case DW_CFA_val_offset:
      cfi_add_CFA_val_offset (reg1, offset);
      break;

    case CFI_rel_offset:
      cfi_add_CFA_offset (reg1,
			  offset - frchain_now->frch_cfi_data->cur_cfa_offset);
      break;

    case DW_CFA_def_cfa:
      cfi_add_CFA_def_cfa (reg1, offset);
      break;

    case DW_CFA_register:
      cfi_add_CFA_register (reg1, reg2);
      break;

    case DW_CFA_def_cfa_register:
      cfi_add_CFA_def_cfa_register (reg1);
      break;

    case DW_CFA_def_cfa_offset:
      cfi_add_CFA_def_cfa_offset (offset);
      break;

    case CFI_adjust_cfa_offset:
      cfi_add_CFA_def_cfa_offset (frchain_now->frch_cfi_data->cur_cfa_offset
				  + offset);
      break;

    case DW_CFA_restore:
      cfi_add_CFA_restore (reg1);
      break;

    case DW_CFA_remember_state:
      cfi_add_CFA_remember_state ();
      break;

    case DW_CFA_restore_state:
      cfi_add_CFA_restore_state ();
      break;

    case CFI_label:
      cfi_add_label (name);
      break;

    case CFI_signal_frame:
      frchain_now->frch_cfi_data->cur_fde_data->signal_frame = 1;
      break;

/*
    case DW_CFA_undefined:
      for (;;)
	{
	  reg1 = cfi_parse_reg ();
	  cfi_add_CFA_undefined (reg1);
	  SKIP_WHITESPACE ();
	  if (*input_line_pointer != ',')
	    break;
	  ++input_line_pointer;
	}
      break;

    case DW_CFA_same_value:
      reg1 = cfi_parse_reg ();
      cfi_add_CFA_same_value (reg1);
      break;

    case CFI_return_column:
      reg1 = cfi_parse_reg ();
      cfi_set_return_column (reg1);
      break;

    case DW_CFA_GNU_window_save:
      cfi_add_CFA_insn (DW_CFA_GNU_window_save);
      break;

*/
    default:
      abort ();
    }
}

#endif