[2/7,gas] Allow to create symbols with octets value

Message ID 20190310182158.23705-3-ceggers@gmx.de
State New
Headers show
Series
  • gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1
Related show

Commit Message

Christian Eggers March 10, 2019, 6:21 p.m.
Up to now, all symbol values are in units of bytes, where a "byte" can
consist of one or more octets (e.g. 8 bit or 16 bit).

Allow to specfiy that the "unit" of a newly created symbol is octets
(exactly 8 bit), instead of octets.

Signed-off-by: Christian Eggers <ceggers@gmx.de>

---
 gas/ChangeLog | 13 +++++++++++++
 gas/symbols.c | 39 ++++++++++++++++++++++++++++++++++++++-
 gas/symbols.h |  3 +++
 3 files changed, 54 insertions(+), 1 deletion(-)

-- 
2.16.4

Patch

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 688f562b5d..be1c6d99b0 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,16 @@ 
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* symbols.h: New functions.
+	(symbol_temp_new_now_octets): New.
+	(symbol_set_value_now_octets): New.
+	(symbol_octets_p): New.
+	* symbols.c: Likewise.
+	(struct symbol_flags): New member sy_octets.
+	(symbol_temp_new_now_octets): New function.
+	(resolve_symbol_value): Return octets instead of bytes of sy_octets is set.
+	(symbol_set_value_now_octets): New function.
+	(symbol_octets_p): New function.
+
 2019-03-10  Christian Eggers  <ceggers@gmx.de>
 
 	* dwarf2dbg.c (dwarf2_emit_insn): Fix calculation of line info offset.
diff --git a/gas/symbols.c b/gas/symbols.c
index b12ab74efd..25b50055ba 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -73,6 +73,10 @@  struct symbol_flags
      before.  It is cleared as soon as any direct reference to the
      symbol is present.  */
   unsigned int sy_weakrefd : 1;
+
+  /* This if set if the unit of the symbol value is "octets" instead
+     of "bytes".  */
+  unsigned int sy_octets : 1;
 };
 
 /* The information we keep for a symbol.  Note that the symbol table
@@ -843,6 +847,14 @@  symbol_temp_new_now (void)
   return symbol_temp_new (now_seg, frag_now_fix (), frag_now);
 }
 
+symbolS *
+symbol_temp_new_now_octets (void)
+{
+  symbolS * symb = symbol_temp_new (now_seg, frag_now_fix_octets (), frag_now);
+  symb->sy_flags.sy_octets = 1;
+  return symb;
+}
+
 symbolS *
 symbol_temp_make (void)
 {
@@ -1324,7 +1336,14 @@  resolve_symbol_value (symbolS *symp)
 	  /* Fall through.  */
 
 	case O_constant:
-	  final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
+	  if (symp->sy_flags.sy_octets)
+	  {
+	    final_val += symp->sy_frag->fr_address;
+	  }
+	  else
+	  {
+	    final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
+	  }
 	  if (final_seg == expr_section)
 	    final_seg = absolute_section;
 	  /* Fall through.  */
@@ -2650,6 +2669,17 @@  symbol_set_value_now (symbolS *sym)
   symbol_set_frag (sym, frag_now);
 }
 
+/* Set the value of SYM to the current position in the current segment.  */
+
+void
+symbol_set_value_now_octets (symbolS *sym)
+{
+  S_SET_SEGMENT (sym, now_seg);
+  S_SET_VALUE (sym, frag_now_fix_octets ());
+  symbol_set_frag (sym, frag_now);
+  sym->sy_flags.sy_octets = 1;
+}
+
 /* Set the frag of a symbol.  */
 
 void
@@ -2921,6 +2951,13 @@  symbol_set_bfdsym (symbolS *s, asymbol *bsym)
   /* else XXX - What do we do now ?  */
 }
 
+/* Return whether symbol unit is "octets" (instead of "bytes")  */
+
+int symbol_octets_p (symbolS *s)
+{
+  return s->sy_flags.sy_octets;
+}
+
 #ifdef OBJ_SYMFIELD_TYPE
 
 /* Get a pointer to the object format information for a symbol.  */
diff --git a/gas/symbols.h b/gas/symbols.h
index 38ae3ac47b..f8429d9730 100644
--- a/gas/symbols.h
+++ b/gas/symbols.h
@@ -57,6 +57,7 @@  symbolS *symbol_clone_if_forward_ref (symbolS *, int);
 #define symbol_clone_if_forward_ref(s) symbol_clone_if_forward_ref (s, 0)
 symbolS *symbol_temp_new (segT, valueT, fragS *);
 symbolS *symbol_temp_new_now (void);
+symbolS *symbol_temp_new_now_octets (void);
 symbolS *symbol_temp_make (void);
 
 symbolS *colon (const char *sym_name);
@@ -181,6 +182,7 @@  extern expressionS *symbol_get_value_expression (symbolS *);
 extern void symbol_set_value_expression (symbolS *, const expressionS *);
 extern offsetT *symbol_X_add_number (symbolS *);
 extern void symbol_set_value_now (symbolS *);
+extern void symbol_set_value_now_octets (symbolS *);
 extern void symbol_set_frag (symbolS *, fragS *);
 extern fragS *symbol_get_frag (symbolS *);
 extern void symbol_mark_used (symbolS *);
@@ -206,6 +208,7 @@  extern symbolS *symbol_symbolS (symbolS *);
 extern asymbol *symbol_get_bfdsym (symbolS *);
 extern void symbol_set_bfdsym (symbolS *, asymbol *);
 extern int symbol_same_p (symbolS *, symbolS *);
+extern int symbol_octets_p (symbolS *);
 
 #ifdef OBJ_SYMFIELD_TYPE
 OBJ_SYMFIELD_TYPE *symbol_get_obj (symbolS *);