[PATCH, RFC 7/9] gas: scfidw2gen: new functionality to prepapre for SCFI
Indu Bhagat
indu.bhagat@oracle.com
Wed Sep 20 23:03:59 GMT 2023
Since the option --scfi=inline still needs to be worked out, the
implementation in scfidw2gen remains in the form it currently is. This
implementation needs to be cleaned up thereafter.
gas/
* Makefile.am: Add new files to GAS_CFILES and HFILES.
* Makefile.in: Likewise.
* scfidw2gen.c: New file.
* scfidw2gen.h: New file.
---
gas/Makefile.am | 2 +
gas/Makefile.in | 9 ++-
gas/scfidw2gen.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++
gas/scfidw2gen.h | 35 +++++++++
4 files changed, 228 insertions(+), 3 deletions(-)
create mode 100644 gas/scfidw2gen.c
create mode 100644 gas/scfidw2gen.h
diff --git a/gas/Makefile.am b/gas/Makefile.am
index 0e98ca3ec85..e174305ca62 100644
--- a/gas/Makefile.am
+++ b/gas/Makefile.am
@@ -93,6 +93,7 @@ GAS_CFILES = \
read.c \
remap.c \
sb.c \
+ scfidw2gen.c \
sframe-opt.c \
stabs.c \
subsegs.c \
@@ -128,6 +129,7 @@ HFILES = \
output-file.h \
read.h \
sb.h \
+ scfidw2gen.h \
subsegs.h \
symbols.h \
tc.h \
diff --git a/gas/Makefile.in b/gas/Makefile.in
index fae3a47c144..87428bc46b8 100644
--- a/gas/Makefile.in
+++ b/gas/Makefile.in
@@ -170,9 +170,9 @@ am__objects_1 = app.$(OBJEXT) as.$(OBJEXT) atof-generic.$(OBJEXT) \
hash.$(OBJEXT) input-file.$(OBJEXT) input-scrub.$(OBJEXT) \
listing.$(OBJEXT) literal.$(OBJEXT) macro.$(OBJEXT) \
messages.$(OBJEXT) output-file.$(OBJEXT) read.$(OBJEXT) \
- remap.$(OBJEXT) sb.$(OBJEXT) sframe-opt.$(OBJEXT) \
- stabs.$(OBJEXT) subsegs.$(OBJEXT) symbols.$(OBJEXT) \
- write.$(OBJEXT)
+ remap.$(OBJEXT) sb.$(OBJEXT) scfidw2gen.$(OBJEXT) \
+ sframe-opt.$(OBJEXT) stabs.$(OBJEXT) subsegs.$(OBJEXT) \
+ symbols.$(OBJEXT) write.$(OBJEXT)
am_as_new_OBJECTS = $(am__objects_1)
am__dirstamp = $(am__leading_dot)dirstamp
as_new_OBJECTS = $(am_as_new_OBJECTS)
@@ -581,6 +581,7 @@ GAS_CFILES = \
read.c \
remap.c \
sb.c \
+ scfidw2gen.c \
sframe-opt.c \
stabs.c \
subsegs.c \
@@ -615,6 +616,7 @@ HFILES = \
output-file.h \
read.h \
sb.h \
+ scfidw2gen.h \
subsegs.h \
symbols.h \
tc.h \
@@ -1337,6 +1339,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/remap.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scfidw2gen.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sframe-opt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stabs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/subsegs.Po@am__quote@
diff --git a/gas/scfidw2gen.c b/gas/scfidw2gen.c
new file mode 100644
index 00000000000..6ae45183012
--- /dev/null
+++ b/gas/scfidw2gen.c
@@ -0,0 +1,185 @@
+/* scfidw2gen.c - Support for emission of synthesized Dwarf2 CFI.
+ Copyright (C) 2003-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 "dw2gencfi.h"
+#include "subsegs.h"
+#include "scfidw2gen.h"
+
+void
+scfi_dot_cfi_startproc (symbolS *start_sym)
+{
+ if (frchain_now->frch_cfi_data != NULL)
+ {
+ as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
+ return;
+ }
+
+ cfi_new_fde (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 (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 (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, symbolS *advloc)
+{
+ if (frchain_now->frch_cfi_data == NULL)
+ {
+ as_bad (_("CFI instruction used without previous .cfi_startproc"));
+ // ignore_rest_of_line ();
+ 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 (advloc);
+
+ switch (arg)
+ {
+ case DW_CFA_offset:
+ // reg1 = cfi_parse_reg ();
+ // cfi_parse_separator ();
+ // offset = cfi_parse_const ();
+ cfi_add_CFA_offset (reg1, offset);
+ break;
+
+ case DW_CFA_val_offset:
+ // reg1 = cfi_parse_reg ();
+ // cfi_parse_separator ();
+ // offset = cfi_parse_const ();
+ cfi_add_CFA_val_offset (reg1, offset);
+ break;
+
+ case CFI_rel_offset:
+ // reg1 = cfi_parse_reg ();
+ // cfi_parse_separator ();
+ // offset = cfi_parse_const ();
+ cfi_add_CFA_offset (reg1,
+ offset - frchain_now->frch_cfi_data->cur_cfa_offset);
+ break;
+
+ case DW_CFA_def_cfa:
+ // reg1 = cfi_parse_reg ();
+ // cfi_parse_separator ();
+ // offset = cfi_parse_const ();
+ cfi_add_CFA_def_cfa (reg1, offset);
+ break;
+
+ case DW_CFA_register:
+ // reg1 = cfi_parse_reg ();
+ // cfi_parse_separator ();
+ // reg2 = cfi_parse_reg ();
+ cfi_add_CFA_register (reg1, reg2);
+ break;
+
+ case DW_CFA_def_cfa_register:
+ // reg1 = cfi_parse_reg ();
+ cfi_add_CFA_def_cfa_register (reg1);
+ break;
+
+ case DW_CFA_def_cfa_offset:
+ // offset = cfi_parse_const ();
+ cfi_add_CFA_def_cfa_offset (offset);
+ break;
+
+ case CFI_adjust_cfa_offset:
+ // offset = cfi_parse_const ();
+ 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 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;
+
+ case CFI_signal_frame:
+ frchain_now->frch_cfi_data->cur_fde_data->signal_frame = 1;
+ break;
+*/
+ default:
+ abort ();
+ }
+
+ // demand_empty_rest_of_line ();
+}
diff --git a/gas/scfidw2gen.h b/gas/scfidw2gen.h
new file mode 100644
index 00000000000..c08cbb38a97
--- /dev/null
+++ b/gas/scfidw2gen.h
@@ -0,0 +1,35 @@
+/* scfidw2gen.h - Support for emitting synthesized Dwarf2 CFI.
+ Copyright (C) 2003-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. */
+
+#ifndef SCFIDW2GEN_H
+#define SCFIDW2GEN_H
+
+#include "as.h"
+#include "dwarf2.h"
+
+extern int all_cfi_sections;
+
+void scfi_dot_cfi_startproc (symbolS *start_sym);
+void scfi_dot_cfi_endproc (symbolS *end_sym);
+void scfi_dot_cfi (int arg, unsigned reg1, unsigned reg2, offsetT offset,
+ symbolS *advloc);
+
+#endif
+
--
2.41.0
More information about the Binutils
mailing list