[PATCH 7/7] [gas] dwarf2: Align relocation within .debug_line section

Christian Eggers ceggers@gmx.de
Sun Mar 10 18:22:00 GMT 2019


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



More information about the Binutils mailing list