public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/7] [gas] dwarf2: Fix calculation of line info offset
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
                   ` (2 preceding siblings ...)
  2019-03-10 18:22 ` [PATCH 3/7] [gas] dwarf2: Use octets for dwarf2 headers Christian Eggers
@ 2019-03-10 18:22 ` Christian Eggers
  2019-03-10 18:22 ` [PATCH 4/7] [gas] dwarf2: Use octets for .debug_line prologue Christian Eggers
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

The units of the value returned by "frag_now_fix()" and "size" do not
match. "frag_now_fix()" returns bytes (can be 8, 16 or 32 bit), while
"size" is octets (exactly 8 bit).

This change should not affect existing targets as all targets currently
using DWARF2 have 8 bit per byte.

Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
 gas/ChangeLog   | 4 ++++
 gas/dwarf2dbg.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 3508c5a038..688f562b5d 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,7 @@
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* dwarf2dbg.c (dwarf2_emit_insn): Fix calculation of line info offset.
+
 2019-02-27  Matthew Malcomson  <matthew.malcomson@arm.com>
 
 	* testsuite/gas/aarch64/dotproduct.d: Use multiple "as" lines.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index ff7a743630..45d86a6ee3 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -579,7 +579,7 @@ dwarf2_emit_insn (int size)
 
   dwarf2_where (&loc);
 
-  dwarf2_gen_line_info (frag_now_fix () - size, &loc);
+  dwarf2_gen_line_info ((frag_now_fix_octets () - size) / OCTETS_PER_BYTE, &loc);
   dwarf2_consume_line_info ();
 }
 
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] [gas] dwarf2: Align relocation within .debug_line section
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
  2019-03-10 18:22 ` [PATCH 6/7] [gas] dwarf2: Pad size of .debug_line section Christian Eggers
@ 2019-03-10 18:22 ` Christian Eggers
  2019-03-10 18:22 ` [PATCH 3/7] [gas] dwarf2: Use octets for dwarf2 headers Christian Eggers
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

All relocations must be aligned to OCTETS_PER_BYTE. As dwarf debug
information is organized in octets, some relocations may not be aligned
to "bytes" quantities.

In most dwarf sections this requirement is already fulfilled, only
relocations for symbol address within the .debug_line section can be
misaligned.

In order to align these relocations to a multiple of OCTETS_PER_BYTE,
"nop" statements are inserted at a appropriate location.

This change should not affect existing targets as all targets currently
using DWARF2 have 8 bit per byte.

Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
 gas/ChangeLog   |  4 ++++
 gas/dwarf2dbg.c | 21 ++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index c6a857b93c..217c4024fb 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,7 @@
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* dwarf2dbg.c (out_set_addr): Align relocation within .debug_line section.
+
 2019-03-10  Christian Eggers  <ceggers@gmx.de>
 
 	* dwarf2dbg.c (out_debug_line): Pad size of .debug_line section.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 9e68233ad3..7e912d7896 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1108,16 +1108,31 @@ get_frag_fix (fragS *frag, segT seg)
 
 /* Set an absolute address (may result in a relocation entry).  */
 
+static void
+out_inc_line_addr (int line_delta, addressT addr_delta);
+
 static void
 out_set_addr (symbolS *sym)
 {
   expressionS exp;
+  addressT expr_addr, expr_addr_aligned;
 
   memset (&exp, 0, sizeof exp);
-  out_opcode (DW_LNS_extended_op);
-  out_uleb128 (sizeof_address + 1);
 
-  out_opcode (DW_LNE_set_address);
+  /* The expression at the bottom must be aligned to OCTETS_PER_BYTE. The
+     statements after the for loop will contribute 3 more octets. */
+  expr_addr = frag_now_fix_octets () + 3;
+  expr_addr_aligned = (expr_addr + OCTETS_PER_BYTE - 1) &
+                     ~(OCTETS_PER_BYTE - 1);
+  for ( ; expr_addr != expr_addr_aligned; expr_addr++)
+    {
+      out_inc_line_addr (0, 0);  /* NOP */
+    }
+
+  out_opcode (DW_LNS_extended_op);   /* 1 octet */
+  out_uleb128 (sizeof_address + 1);  /* 1 octet */
+
+  out_opcode (DW_LNE_set_address);   /* 1 octet */
   exp.X_op = O_symbol;
   exp.X_add_symbol = sym;
   exp.X_add_number = 0;
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/7] [gas] dwarf2: Pad size of .debug_line section.
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
@ 2019-03-10 18:22 ` Christian Eggers
  2019-03-10 18:22 ` [PATCH 7/7] [gas] dwarf2: Align relocation within " Christian Eggers
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

As all dwarf debug information is organized in octets, the size of all
dwarf sections must be aligned to OCTETS_PER_BYTE. Most DWARF sections
meet this requirement, only the .debug_line section can reach an
arbitrary octet size.

In order to align the size to a multiple of OCTETS_PER_BYTE, the section
is padded with "nop" statements at the end.

This change should not affect existing targets as all targets currently
using DWARF2 have 8 bit per byte.

Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
 gas/ChangeLog   |  4 ++++
 gas/dwarf2dbg.c | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 2d7dabc299..c6a857b93c 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,7 @@
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* dwarf2dbg.c (out_debug_line): Pad size of .debug_line section.
+
 2019-03-10  Christian Eggers  <ceggers@gmx.de>
 
 	* dwarf2dbg.c: Use octets for .debug_string pointers.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index d469138576..9e68233ad3 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1787,6 +1787,7 @@ out_debug_line (segT line_seg)
   symbolS *line_end;
   struct line_seg *s;
   int sizeof_offset;
+  addressT section_end, section_end_aligned;
 
   memset (&exp, 0, sizeof exp);
   sizeof_offset = out_header (line_seg, &exp);
@@ -1848,6 +1849,19 @@ out_debug_line (segT line_seg)
        in the DWARF Line Number header.  */
     subseg_set (subseg_get (".debug_line_end", FALSE), 0);
 
+  /* Pad size of .debug_line section to a multiple of OCTETS_PER_BYTE. Simply
+     sizing the section in md_section_align() is not sufficient, also the size
+     field in the .debug_line header must be a multiple of OCTETS_PER_BYTE. Not
+     doing so will introduce gaps within the .debug_line sections after linking.
+       */
+  section_end = frag_now_fix_octets ();
+  section_end_aligned = (section_end + OCTETS_PER_BYTE - 1) &
+                        ~(OCTETS_PER_BYTE  - 1);
+  for ( ; section_end != section_end_aligned; section_end++)
+    {
+      out_inc_line_addr (0, 0);  /* NOP */
+    }
+
   symbol_set_value_now_octets (line_end);
 }
 
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/7] [gas] dwarf2: Use octets for .debug_string offsets
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
                   ` (4 preceding siblings ...)
  2019-03-10 18:22 ` [PATCH 4/7] [gas] dwarf2: Use octets for .debug_line prologue Christian Eggers
@ 2019-03-10 18:22 ` Christian Eggers
  2019-03-10 18:27 ` [PATCH 2/7] [gas] Allow to create symbols with octets value Christian Eggers
  2019-03-13  4:49 ` [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Alan Modra
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

Like other dwarf2 offsets, also the string offsets in the .debug_info
section which points into the .debug_str section must be expressed in
octets instead of bytes.

This change should not affect existing targets as all targets currently
using DWARF2 have 8 bit per byte.

Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
 gas/ChangeLog   | 5 +++++
 gas/dwarf2dbg.c | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 4cb2702ab2..2d7dabc299 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,8 @@
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* dwarf2dbg.c: Use octets for .debug_string pointers.
+	(out_debug_str): symbol_temp_new_now() --> symbol_temp_new_now_octets()
+
 2019-03-10  Christian Eggers  <ceggers@gmx.de>
 
 	* dwarf2dbg.c: Use octets for .debug_line prologue.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 896a8f125a..d469138576 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -2103,7 +2103,7 @@ out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym,
      on the command line, so assume files[1] is the main input file.
      We're not supposed to get called unless at least one line number
      entry was emitted, so this should always be defined.  */
-  *name_sym = symbol_temp_new_now ();
+  *name_sym = symbol_temp_new_now_octets ();
   if (files_in_use == 0)
     abort ();
   if (files[1].dir)
@@ -2125,14 +2125,14 @@ out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym,
   memcpy (p, files[1].filename, len);
 
   /* DW_AT_comp_dir */
-  *comp_dir_sym = symbol_temp_new_now ();
+  *comp_dir_sym = symbol_temp_new_now_octets ();
   comp_dir = remap_debug_filename (getpwd ());
   len = strlen (comp_dir) + 1;
   p = frag_more (len);
   memcpy (p, comp_dir, len);
 
   /* DW_AT_producer */
-  *producer_sym = symbol_temp_new_now ();
+  *producer_sym = symbol_temp_new_now_octets ();
   sprintf (producer, "GNU AS %s", VERSION);
   len = strlen (producer) + 1;
   p = frag_more (len);
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/7] [gas] dwarf2: Use octets for .debug_line prologue
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
                   ` (3 preceding siblings ...)
  2019-03-10 18:22 ` [PATCH 1/7] [gas] dwarf2: Fix calculation of line info offset Christian Eggers
@ 2019-03-10 18:22 ` Christian Eggers
  2019-03-10 18:22 ` [PATCH 5/7] [gas] dwarf2: Use octets for .debug_string offsets Christian Eggers
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

Like the u32 size field at the beginning of the section, also the
prologue size must be expressed in octets.

This change should not affect existing targets as all targets currently
using DWARF2 have 8 bit per byte.

Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
 gas/ChangeLog   | 5 +++++
 gas/dwarf2dbg.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 08dd959afd..4cb2702ab2 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,8 @@
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* dwarf2dbg.c: Use octets for .debug_line prologue.
+	(out_debug_line): symbol_set_value_now() --> symbol_set_value_now_octets()
+
 2019-03-10  Christian Eggers  <ceggers@gmx.de>
 
 	* dwarf2dbg.c: Use octets for dwarf2 headers.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 7b0e8fdc4a..896a8f125a 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1803,7 +1803,7 @@ out_debug_line (segT line_seg)
   exp.X_op_symbol = prologue_start;
   exp.X_add_number = 0;
   emit_expr (&exp, sizeof_offset);
-  symbol_set_value_now (prologue_start);
+  symbol_set_value_now_octets (prologue_start);
 
   /* Parameters of the state machine.  */
   out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
@@ -1828,7 +1828,7 @@ out_debug_line (segT line_seg)
 
   out_file_list ();
 
-  symbol_set_value_now (prologue_end);
+  symbol_set_value_now_octets (prologue_end);
 
   /* For each section, emit a statement program.  */
   for (s = all_segs; s; s = s->next)
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1
@ 2019-03-10 18:22 Christian Eggers
  2019-03-10 18:22 ` [PATCH 6/7] [gas] dwarf2: Pad size of .debug_line section Christian Eggers
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

I'm working on a binutils port for the SDMA controller which is inside many
of NXP's i.MX SOCs. In contrast to most other architectures, the SDMA has
16 bit per instruction address (OCTETS_PER_BYTE=2). Up to now, no architecture
with OCTETS_PER_BYTE>1 uses DWARF debug information (tic4x and tic54x use
stabs).

With OCTETS_PER_BYTE=2, the smallest addressable unit is 16 bit. This is
problematic with DWARF2 debug information, as this format always uses 8 bit
quantities. Resulting problems can be truncated sections and displaced
relocations.

These patch series fixes the generation of DWARF debug information in gas for
these architectures, which is a prerequisite for the SDMA port.

These changes should not affect existing architectures as all targets currently
using DWARF2 have 8 bit per byte.

Christian Eggers (7):
  [gas] dwarf2: Fix calculation of line info offset
  [gas] Allow to create symbols with octets value
  [gas] dwarf2: Use octets for dwarf2 headers
  [gas] dwarf2: Use octets for .debug_line prologue
  [gas] dwarf2: Use octets for .debug_string offsets
  [gas] dwarf2: Pad size of .debug_line section.
  [gas] dwarf2: Align relocation within .debug_line section

 gas/ChangeLog   | 42 ++++++++++++++++++++++++++++++++++++++++++
 gas/dwarf2dbg.c | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
 gas/symbols.c   | 39 ++++++++++++++++++++++++++++++++++++++-
 gas/symbols.h   |  3 +++
 4 files changed, 125 insertions(+), 14 deletions(-)

-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/7] [gas] dwarf2: Use octets for dwarf2 headers
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
  2019-03-10 18:22 ` [PATCH 6/7] [gas] dwarf2: Pad size of .debug_line section Christian Eggers
  2019-03-10 18:22 ` [PATCH 7/7] [gas] dwarf2: Align relocation within " Christian Eggers
@ 2019-03-10 18:22 ` Christian Eggers
  2019-03-10 18:22 ` [PATCH 1/7] [gas] dwarf2: Fix calculation of line info offset Christian Eggers
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:22 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

The content of the dwarf2 sections .debug_line, .debug_aranges and
.debug_info starts with an u32 containing the the size of the remaining
data. According to the dwarf2 specification this value must be expressed
in octets instead of bytes.

This change should not affect existing targets as all targets currently
using DWARF2 have 8 bit per byte.

Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
 gas/ChangeLog   | 7 +++++++
 gas/dwarf2dbg.c | 8 ++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index be1c6d99b0..08dd959afd 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,10 @@
+2019-03-10  Christian Eggers  <ceggers@gmx.de>
+
+	* dwarf2dbg.c: Use octets for dwarf2 headers.
+	(out_debug_line): symbol_set_value_now() --> symbol_set_value_now_octets()
+	(out_debug_aranges): Likewise.
+	(out_debug_info): Likewise.
+
 2019-03-10  Christian Eggers  <ceggers@gmx.de>
 
 	* symbols.h: New functions.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 45d86a6ee3..7b0e8fdc4a 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1745,7 +1745,7 @@ out_header (asection *sec, expressionS *exp)
     }
   else
     {
-      start_sym = symbol_temp_new_now ();
+      start_sym = symbol_temp_new_now_octets ();
       end_sym = symbol_temp_make ();
     }
 
@@ -1848,7 +1848,7 @@ out_debug_line (segT line_seg)
        in the DWARF Line Number header.  */
     subseg_set (subseg_get (".debug_line_end", FALSE), 0);
 
-  symbol_set_value_now (line_end);
+  symbol_set_value_now_octets (line_end);
 }
 
 static void
@@ -1967,7 +1967,7 @@ out_debug_aranges (segT aranges_seg, segT info_seg)
   md_number_to_chars (p, 0, addr_size);
   md_number_to_chars (p + addr_size, 0, addr_size);
 
-  symbol_set_value_now (aranges_end);
+  symbol_set_value_now_octets (aranges_end);
 }
 
 /* Emit data for .debug_abbrev.  Note that this must be kept in
@@ -2082,7 +2082,7 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg,
      dwarf2 draft has no standard code for assembler.  */
   out_two (DW_LANG_Mips_Assembler);
 
-  symbol_set_value_now (info_end);
+  symbol_set_value_now_octets (info_end);
 }
 
 /* Emit the three debug strings needed in .debug_str and setup symbols
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/7] [gas] Allow to create symbols with octets value
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
                   ` (5 preceding siblings ...)
  2019-03-10 18:22 ` [PATCH 5/7] [gas] dwarf2: Use octets for .debug_string offsets Christian Eggers
@ 2019-03-10 18:27 ` Christian Eggers
  2019-03-13  4:49 ` [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Alan Modra
  7 siblings, 0 replies; 9+ messages in thread
From: Christian Eggers @ 2019-03-10 18:27 UTC (permalink / raw)
  To: binutils; +Cc: Christian Eggers

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(-)

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 *);
-- 
2.16.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1
  2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
                   ` (6 preceding siblings ...)
  2019-03-10 18:27 ` [PATCH 2/7] [gas] Allow to create symbols with octets value Christian Eggers
@ 2019-03-13  4:49 ` Alan Modra
  7 siblings, 0 replies; 9+ messages in thread
From: Alan Modra @ 2019-03-13  4:49 UTC (permalink / raw)
  To: Christian Eggers; +Cc: binutils

On Sun, Mar 10, 2019 at 07:21:51PM +0100, Christian Eggers wrote:
> I'm working on a binutils port for the SDMA controller which is inside many
> of NXP's i.MX SOCs. In contrast to most other architectures, the SDMA has
> 16 bit per instruction address (OCTETS_PER_BYTE=2). Up to now, no architecture
> with OCTETS_PER_BYTE>1 uses DWARF debug information (tic4x and tic54x use
> stabs).
> 
> With OCTETS_PER_BYTE=2, the smallest addressable unit is 16 bit. This is
> problematic with DWARF2 debug information, as this format always uses 8 bit
> quantities. Resulting problems can be truncated sections and displaced
> relocations.
> 
> These patch series fixes the generation of DWARF debug information in gas for
> these architectures, which is a prerequisite for the SDMA port.

I've pushed this series after fixing a number of formatting issues.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-03-13  4:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-10 18:22 [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Christian Eggers
2019-03-10 18:22 ` [PATCH 6/7] [gas] dwarf2: Pad size of .debug_line section Christian Eggers
2019-03-10 18:22 ` [PATCH 7/7] [gas] dwarf2: Align relocation within " Christian Eggers
2019-03-10 18:22 ` [PATCH 3/7] [gas] dwarf2: Use octets for dwarf2 headers Christian Eggers
2019-03-10 18:22 ` [PATCH 1/7] [gas] dwarf2: Fix calculation of line info offset Christian Eggers
2019-03-10 18:22 ` [PATCH 4/7] [gas] dwarf2: Use octets for .debug_line prologue Christian Eggers
2019-03-10 18:22 ` [PATCH 5/7] [gas] dwarf2: Use octets for .debug_string offsets Christian Eggers
2019-03-10 18:27 ` [PATCH 2/7] [gas] Allow to create symbols with octets value Christian Eggers
2019-03-13  4:49 ` [PATCH 0/7] gas: Fixes for DWARF2 debug info with OCTETS_PER_BYTE>1 Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).