This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Introduce support for location views


On Jul 17, 2017, Nick Clifton <nickc@redhat.com> wrote:

> Hi Alex,
>> Fixed with the incremental patch below.

> Would you mind having a look and fixing them please.  Feel free to ping me if you
> want to have a look at the full logs of the failures.

Here's a consolidated patch that combines the original patch with all of
the incremental changes posted so far (minus the riscv patchlets), and
one extra patch that moves the leb128 operand-is-defined check to a IMHO
more suitable place.



This patch introduces support for specifing views in .loc directives,
so that the compiler can use the assembler to generate line number
information and have the assembler determine view numbers to multiple
views at the same program counter.  Three forms are supported:

  .loc ... view -0   ; (e.g. at a function start) force view to zero
  .loc ... view 0    ; (after a PC change) assert view is zero
  .loc ... view .Lvu ; (at the Nth view at PC) set .Lvu to N-1

As in https://people.redhat.com/aoliva/papers/sfn/dwarf6-sfn-lvu.txt
view numbers are NOT encoded explicitly in line number programs;
they're rather inferred from the program.  So, instead of having the
compiler supply the assembler with view numbers, we let the assembler
compute them according to the line number program implicit rules, and
allow the compiler to refer to the computed numbers by storing the
numbers in label-like view numbers.  Since the compiler can in many
cases know about PC changes, we allow the compiler to assert that the
view is reset at such points, so that it can safely assume the view
number is zero at them: the assembler will error out if the assumption
is incorrect.

View labels are meant to be used in location lists, as proposed for
DWARF6, or in view lists and augment location lists, a
backward-compatible extension.  We do NOT have code to dump either
list yet.  In either case, the view numbers are encoded as uleb128
sequences, which required the possibility of deferring the resolution
of uleb128 operands (we'd previously emit undefined or
not-yet-computed symbols as if they were zero).  Nothing prevents
other uses of the view counters stored in view label symbols.

I've added code to dump (nonzero) view numbers in raw line number
programs and in decoded line number tables, and adjusted all tests
that, under the implicit view computation rules, had nonzero views in
them, so that their expected dumps would match the modified outputs.

I've added plenty of tests for view numbering, testing cases involving
alignment pseudo_ops that either change or don't change PC.  I found
several cases in which I had to emit pending line number directives
before the pseudo_op takes effect, otherwise the view number would end
up being computed at the wrong PC, or even at the wrong section.

GCC has been modified to use the assembler to emit view-aware line
number programs, when it supports .loc views, and that compiler has
successfully bootstrapped using an assembler with this patch.


for  binutils/ChangeLog

	* dwarf.c (struct State_Machine_Registers): Add view field.
	(reset_state_machine): Reset view.
	(process_extended_line_op): Reset view when appropriate.
	(display_debug_lines_raw): Increment or reset view when appropriate.
	Print nonzero views.  Support print view resets, disabled by default.
	(display_debug_lines_decoded): Likewise.  Disambiguate op_code tests,
	enabling printing of end_sequence.
	* testsuite/binutils-all/dw2-1.W: Add nonzero views.
	* testsuite/binutils-all/dw2-3.W: Likewise.
	* testsuite/binutils-all/dw2-3gabi.W: Likewise.
	* testsuite/binutils-all/dw5.W: Add end sequence lines.
	* testsuite/binutils-all/i386/compressed-1a.d: Add nonzero views.
	* testsuite/binutils-all/libdw2-compressedgabi.out: Likewise.
	* testsuite/binutils-all/objdump.W: Likewise.
	* testsuite/binutils-all/objdump.WL: Add end sequence lines.
	* testsuite/binutils-all/x86-64/compressed-1a.d: Add nonzero views.

for  gas/ChangeLog

	* doc/as.texinfo (.loc): Document view support.
	* dwarf2dbg.c (unused): Check offset of next in struct line_entry.
	(current): Initialize view.
	(force_reset_view, view_assert_failed): New variables.
	(reverse_line_entry_list): New function.
	(set_or_check_view): Likewise.
	(dwarf2_gen_line_info_1): Call it.
	(dwarf2_where): Set view to NULL.
	(dwarf2_emit_insn): Return early when called before first file.
	(dwarf2_directive_loc): Add view support.  Emit insn
	immediately when view option is given.
	(process_entries): Avoid set_address to reset view when a known
	address change already implies the view reset.
	(dwarf2dbg_final_check): New function.
	* dwarf2dbg.h (struct dwarf2_line_info): Add view.
	(dwarf2dbg_final_check): Declare.
	* read.c (s_leb128): Parse expression as deferred.
	* testsuite/gas/all/gas.exp: Run sleb128-9.
	* testsuite/gas/all/sleb128-9.d: New.
	* testsuite/gas/all/sleb128-9.l: New.
	* testsuite/gas/all/sleb128-9.s: New.
	* testsuite/gas/elf/dwarf2-1.d: Add nonzero views.
	* testsuite/gas/elf/dwarf2-2.d: Likewise.
	* testsuite/gas/elf/dwarf2-5.d: New.
	* testsuite/gas/elf/dwarf2-5.s: New.
	* testsuite/gas/elf/dwarf2-6.d: New.
	* testsuite/gas/elf/dwarf2-6.s: New.
	* testsuite/gas/elf/dwarf2-7.d: New.
	* testsuite/gas/elf/dwarf2-7.s: New.
	* testsuite/gas/elf/dwarf2-8.d: New.
	* testsuite/gas/elf/dwarf2-8.l: New.
	* testsuite/gas/elf/dwarf2-8.s: New.
	* testsuite/gas/elf/dwarf2-9.d: New.
	* testsuite/gas/elf/dwarf2-9.l: New.
	* testsuite/gas/elf/dwarf2-9.s: New.
	* testsuite/gas/elf/dwarf2-10.d: New.
	* testsuite/gas/elf/dwarf2-10.l: New.
	* testsuite/gas/elf/dwarf2-10.s: New.
	* testsuite/gas/elf/dwarf2-11.d: New.
	* testsuite/gas/elf/dwarf2-11.s: New.
	* testsuite/gas/elf/dwarf2-12.d: New.
	* testsuite/gas/elf/dwarf2-12.s: New.
	* testsuite/gas/elf/dwarf2-13.d: New.
	* testsuite/gas/elf/dwarf2-13.s: New.
	* testsuite/gas/elf/dwarf2-14.d: New.
	* testsuite/gas/elf/dwarf2-14.s: New.
	* testsuite/gas/elf/dwarf2-15.d: New.
	* testsuite/gas/elf/dwarf2-15.s: New.
	* testsuite/gas/elf/dwarf2-16.d: New.
	* testsuite/gas/elf/dwarf2-16.s: New.
	* testsuite/gas/elf/dwarf2-17.d: New.
	* testsuite/gas/elf/dwarf2-17.s: New.
	* testsuite/gas/elf/dwarf2-18.d: New.
	* testsuite/gas/elf/dwarf2-18.s: New.
	* testsuite/gas/elf/elf.exp: Run dwarf2-5..18 tests.
	* testsuite/gas/i386/dw2-compress-1.d: Add nonzero views.
	* testsuite/gas/i386/dw2-compressed-1.d: Likewise.
	* testsuite/gas/i386/ilp32/lns/lns-duplicate.d: Likewise.
	* testsuite/gas/lns/lns-big-delta.d: Likewise.
	* testsuite/gas/lns/lns-duplicate.d: Likewise.
	* testsuite/gas/mips/loc-swap-2.d: Likewise.
	* testsuite/gas/mips/loc-swap-3.d: Likewise.
	* testsuite/gas/mips/loc-swap.d: Likewise.
	* testsuite/gas/mips/micromips@loc-swap-2.d: Likewise.
	* testsuite/gas/mips/micromips@loc-swap.d: Likewise.
	* testsuite/gas/mips/mips16@loc-swap-2.d: Likewise.
	* testsuite/gas/mips/mips16@loc-swap.d: Likewise.
	* testsuite/gas/mips/mips16e@loc-swap.d: Likewise.
	* write.c (write_object_file): Check pending view asserts.
	(cvt_frag_to_fill): Complain about undefined leb128 operand.
---
 binutils/dwarf.c                                   |  162 +++++++++---
 binutils/testsuite/binutils-all/dw2-1.W            |    2 
 binutils/testsuite/binutils-all/dw2-3.W            |    2 
 binutils/testsuite/binutils-all/dw2-3gabi.W        |    2 
 binutils/testsuite/binutils-all/dw5.W              |    4 
 .../testsuite/binutils-all/i386/compressed-1a.d    |    2 
 .../binutils-all/libdw2-compressedgabi.out         |    6 
 binutils/testsuite/binutils-all/objdump.W          |    2 
 binutils/testsuite/binutils-all/objdump.WL         |    3 
 .../testsuite/binutils-all/x86-64/compressed-1a.d  |    4 
 gas/doc/as.texinfo                                 |   13 +
 gas/dwarf2dbg.c                                    |  280 ++++++++++++++++++++
 gas/dwarf2dbg.h                                    |    3 
 gas/read.c                                         |    2 
 gas/testsuite/gas/all/gas.exp                      |    1 
 gas/testsuite/gas/all/sleb128-9.d                  |    4 
 gas/testsuite/gas/all/sleb128-9.l                  |    3 
 gas/testsuite/gas/all/sleb128-9.s                  |    3 
 gas/testsuite/gas/elf/dwarf2-1.d                   |    2 
 gas/testsuite/gas/elf/dwarf2-10.d                  |    3 
 gas/testsuite/gas/elf/dwarf2-10.l                  |    2 
 gas/testsuite/gas/elf/dwarf2-10.s                  |   32 ++
 gas/testsuite/gas/elf/dwarf2-11.d                  |   11 +
 gas/testsuite/gas/elf/dwarf2-11.s                  |   28 ++
 gas/testsuite/gas/elf/dwarf2-12.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-12.s                  |   31 ++
 gas/testsuite/gas/elf/dwarf2-13.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-13.s                  |   33 ++
 gas/testsuite/gas/elf/dwarf2-14.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-14.s                  |   32 ++
 gas/testsuite/gas/elf/dwarf2-15.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-15.s                  |   32 ++
 gas/testsuite/gas/elf/dwarf2-16.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-16.s                  |   33 ++
 gas/testsuite/gas/elf/dwarf2-17.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-17.s                  |   33 ++
 gas/testsuite/gas/elf/dwarf2-18.d                  |   15 +
 gas/testsuite/gas/elf/dwarf2-18.s                  |   33 ++
 gas/testsuite/gas/elf/dwarf2-2.d                   |    2 
 gas/testsuite/gas/elf/dwarf2-5.d                   |   74 +++++
 gas/testsuite/gas/elf/dwarf2-5.s                   |   58 ++++
 gas/testsuite/gas/elf/dwarf2-6.d                   |   76 +++++
 gas/testsuite/gas/elf/dwarf2-6.s                   |  101 +++++++
 gas/testsuite/gas/elf/dwarf2-7.d                   |   15 +
 gas/testsuite/gas/elf/dwarf2-7.s                   |   36 +++
 gas/testsuite/gas/elf/dwarf2-8.d                   |    3 
 gas/testsuite/gas/elf/dwarf2-8.l                   |    2 
 gas/testsuite/gas/elf/dwarf2-8.s                   |   27 ++
 gas/testsuite/gas/elf/dwarf2-9.d                   |    3 
 gas/testsuite/gas/elf/dwarf2-9.l                   |    2 
 gas/testsuite/gas/elf/dwarf2-9.s                   |   32 ++
 gas/testsuite/gas/elf/elf.exp                      |   14 +
 gas/testsuite/gas/i386/dw2-compress-1.d            |    2 
 gas/testsuite/gas/i386/dw2-compressed-1.d          |    2 
 gas/testsuite/gas/i386/ilp32/lns/lns-duplicate.d   |    2 
 gas/testsuite/gas/lns/lns-big-delta.d              |    2 
 gas/testsuite/gas/lns/lns-duplicate.d              |    2 
 gas/testsuite/gas/mips/loc-swap-2.d                |    6 
 gas/testsuite/gas/mips/loc-swap-3.d                |    2 
 gas/testsuite/gas/mips/loc-swap.d                  |    6 
 gas/testsuite/gas/mips/micromips@loc-swap-2.d      |    6 
 gas/testsuite/gas/mips/micromips@loc-swap.d        |    4 
 gas/testsuite/gas/mips/mips16@loc-swap-2.d         |    6 
 gas/testsuite/gas/mips/mips16@loc-swap.d           |    6 
 gas/testsuite/gas/mips/mips16e@loc-swap.d          |    6 
 gas/write.c                                        |    9 +
 66 files changed, 1329 insertions(+), 85 deletions(-)
 create mode 100644 gas/testsuite/gas/all/sleb128-9.d
 create mode 100644 gas/testsuite/gas/all/sleb128-9.l
 create mode 100644 gas/testsuite/gas/all/sleb128-9.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-10.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-10.l
 create mode 100644 gas/testsuite/gas/elf/dwarf2-10.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-11.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-11.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-12.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-12.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-13.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-13.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-14.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-14.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-15.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-15.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-16.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-16.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-17.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-17.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-18.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-18.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-5.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-5.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-6.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-6.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-7.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-7.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-8.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-8.l
 create mode 100644 gas/testsuite/gas/elf/dwarf2-8.s
 create mode 100644 gas/testsuite/gas/elf/dwarf2-9.d
 create mode 100644 gas/testsuite/gas/elf/dwarf2-9.l
 create mode 100644 gas/testsuite/gas/elf/dwarf2-9.s

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 5cada37..4e96b32 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -423,6 +423,7 @@ read_uleb128 (unsigned char * data,
 typedef struct State_Machine_Registers
 {
   dwarf_vma address;
+  unsigned int view;
   unsigned int file;
   unsigned int line;
   unsigned int column;
@@ -441,6 +442,7 @@ static void
 reset_state_machine (int is_stmt)
 {
   state_machine_regs.address = 0;
+  state_machine_regs.view = 0;
   state_machine_regs.op_index = 0;
   state_machine_regs.file = 1;
   state_machine_regs.line = 1;
@@ -499,6 +501,7 @@ process_extended_line_op (unsigned char * data,
 	SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
       printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
       state_machine_regs.address = adr;
+      state_machine_regs.view = 0;
       state_machine_regs.op_index = 0;
       break;
 
@@ -3187,6 +3190,7 @@ display_debug_lines_raw (struct dwarf_section *section,
 			 unsigned char *end, void *file)
 {
   unsigned char *start = section->start;
+  int verbose_view = 0;
 
   printf (_("Raw dump of debug contents of section %s:\n\n"),
 	  section->name);
@@ -3378,30 +3382,45 @@ display_debug_lines_raw (struct dwarf_section *section,
 		    {
 		      uladv *= linfo.li_min_insn_length;
 		      state_machine_regs.address += uladv;
+		      if (uladv)
+			state_machine_regs.view = 0;
 		      printf (_("  Special opcode %d: "
-				"advance Address by %s to 0x%s"),
+				"advance Address by %s to 0x%s%s"),
 			      op_code, dwarf_vmatoa ("u", uladv),
-			      dwarf_vmatoa ("x", state_machine_regs.address));
+			      dwarf_vmatoa ("x", state_machine_regs.address),
+			      verbose_view && uladv
+			      ? _(" (reset view)") : "");
 		    }
 		  else
 		    {
-		      state_machine_regs.address
-			+= ((state_machine_regs.op_index + uladv)
+		      unsigned addrdelta
+			= ((state_machine_regs.op_index + uladv)
 			    / linfo.li_max_ops_per_insn)
 			* linfo.li_min_insn_length;
+		      state_machine_regs.address
+			+= addrdelta;
 		      state_machine_regs.op_index
 			= (state_machine_regs.op_index + uladv)
 			% linfo.li_max_ops_per_insn;
+		      if (addrdelta)
+			state_machine_regs.view = 0;
 		      printf (_("  Special opcode %d: "
-				"advance Address by %s to 0x%s[%d]"),
+				"advance Address by %s to 0x%s[%d]%s"),
 			      op_code, dwarf_vmatoa ("u", uladv),
 			      dwarf_vmatoa ("x", state_machine_regs.address),
-			      state_machine_regs.op_index);
+			      state_machine_regs.op_index,
+			      verbose_view && addrdelta
+			      ? _(" (reset view)") : "");
 		    }
 		  adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
 		  state_machine_regs.line += adv;
-		  printf (_(" and Line by %s to %d\n"),
+		  printf (_(" and Line by %s to %d"),
 			  dwarf_vmatoa ("d", adv), state_machine_regs.line);
+		  if (verbose_view || state_machine_regs.view)
+		    printf (_(" (view %u)\n"), state_machine_regs.view);
+		  else
+		    putchar ('\n');
+		  state_machine_regs.view++;
 		}
 	      else switch (op_code)
 		     {
@@ -3410,7 +3429,12 @@ display_debug_lines_raw (struct dwarf_section *section,
 		       break;
 
 		     case DW_LNS_copy:
-		       printf (_("  Copy\n"));
+		       printf (_("  Copy"));
+		       if (verbose_view || state_machine_regs.view)
+			 printf (_(" (view %u)\n"), state_machine_regs.view);
+		       else
+			 putchar ('\n');
+		       state_machine_regs.view++;
 		       break;
 
 		     case DW_LNS_advance_pc:
@@ -3420,23 +3444,33 @@ display_debug_lines_raw (struct dwarf_section *section,
 			 {
 			   uladv *= linfo.li_min_insn_length;
 			   state_machine_regs.address += uladv;
-			   printf (_("  Advance PC by %s to 0x%s\n"),
+			   if (uladv)
+			     state_machine_regs.view = 0;
+			   printf (_("  Advance PC by %s to 0x%s%s\n"),
 				   dwarf_vmatoa ("u", uladv),
-				   dwarf_vmatoa ("x", state_machine_regs.address));
+				   dwarf_vmatoa ("x", state_machine_regs.address),
+				   verbose_view && uladv
+				   ? _(" (reset view)") : "");
 			 }
 		       else
 			 {
-			   state_machine_regs.address
-			     += ((state_machine_regs.op_index + uladv)
-				 / linfo.li_max_ops_per_insn)
+			   unsigned addrdelta
+			     = ((state_machine_regs.op_index + uladv)
+				/ linfo.li_max_ops_per_insn)
 			     * linfo.li_min_insn_length;
+			   state_machine_regs.address
+			     += addrdelta;
 			   state_machine_regs.op_index
 			     = (state_machine_regs.op_index + uladv)
 			     % linfo.li_max_ops_per_insn;
-			   printf (_("  Advance PC by %s to 0x%s[%d]\n"),
+			   if (addrdelta)
+			     state_machine_regs.view = 0;
+			   printf (_("  Advance PC by %s to 0x%s[%d]%s\n"),
 				   dwarf_vmatoa ("u", uladv),
 				   dwarf_vmatoa ("x", state_machine_regs.address),
-				   state_machine_regs.op_index);
+				   state_machine_regs.op_index,
+				   verbose_view && addrdelta
+				   ? _(" (reset view)") : "");
 			 }
 		       break;
 
@@ -3483,23 +3517,33 @@ display_debug_lines_raw (struct dwarf_section *section,
 			 {
 			   uladv *= linfo.li_min_insn_length;
 			   state_machine_regs.address += uladv;
-			   printf (_("  Advance PC by constant %s to 0x%s\n"),
+			   if (uladv)
+			     state_machine_regs.view = 0;
+			   printf (_("  Advance PC by constant %s to 0x%s%s\n"),
 				   dwarf_vmatoa ("u", uladv),
-				   dwarf_vmatoa ("x", state_machine_regs.address));
+				   dwarf_vmatoa ("x", state_machine_regs.address),
+				   verbose_view && uladv
+				   ? _(" (reset view)") : "");
 			 }
 		       else
 			 {
-			   state_machine_regs.address
-			     += ((state_machine_regs.op_index + uladv)
-				 / linfo.li_max_ops_per_insn)
+			   unsigned addrdelta
+			     = ((state_machine_regs.op_index + uladv)
+				/ linfo.li_max_ops_per_insn)
 			     * linfo.li_min_insn_length;
+			   state_machine_regs.address
+			     += addrdelta;
 			   state_machine_regs.op_index
 			     = (state_machine_regs.op_index + uladv)
 			     % linfo.li_max_ops_per_insn;
-			   printf (_("  Advance PC by constant %s to 0x%s[%d]\n"),
+			   if (addrdelta)
+			     state_machine_regs.view = 0;
+			   printf (_("  Advance PC by constant %s to 0x%s[%d]%s\n"),
 				   dwarf_vmatoa ("u", uladv),
 				   dwarf_vmatoa ("x", state_machine_regs.address),
-				   state_machine_regs.op_index);
+				   state_machine_regs.op_index,
+				   verbose_view && addrdelta
+				   ? _(" (reset view)") : "");
 			 }
 		       break;
 
@@ -3510,6 +3554,7 @@ display_debug_lines_raw (struct dwarf_section *section,
 		       printf (_("  Advance PC by fixed size amount %s to 0x%s\n"),
 			       dwarf_vmatoa ("u", uladv),
 			       dwarf_vmatoa ("x", state_machine_regs.address));
+		       /* Do NOT reset view.  */
 		       break;
 
 		     case DW_LNS_set_prologue_end:
@@ -3922,7 +3967,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		printf ("%s:\n", file_table[0].name);
 	    }
 
-	  printf (_("File name                            Line number    Starting address\n"));
+	  printf (_("File name                            Line number    Starting address    View\n"));
 	  saved_linfo = linfo;
 	}
 
@@ -3930,12 +3975,14 @@ display_debug_lines_decoded (struct dwarf_section *section,
       while (data < end_of_sequence)
 	{
 	  unsigned char op_code;
+	  int xop;
 	  int adv;
 	  unsigned long int uladv;
 	  unsigned int bytes_read;
 	  int is_special_opcode = 0;
 
 	  op_code = *data++;
+	  xop = op_code;
 
 	  if (op_code >= linfo.li_opcode_base)
 	    {
@@ -3945,21 +3992,28 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		{
 		  uladv *= linfo.li_min_insn_length;
 		  state_machine_regs.address += uladv;
+		  if (uladv)
+		    state_machine_regs.view = 0;
 		}
 	      else
 		{
-		  state_machine_regs.address
-		    += ((state_machine_regs.op_index + uladv)
-			/ linfo.li_max_ops_per_insn)
+		  unsigned addrdelta
+		    = ((state_machine_regs.op_index + uladv)
+		       / linfo.li_max_ops_per_insn)
 		    * linfo.li_min_insn_length;
+		  state_machine_regs.address
+		    += addrdelta;
 		  state_machine_regs.op_index
 		    = (state_machine_regs.op_index + uladv)
 		    % linfo.li_max_ops_per_insn;
+		  if (addrdelta)
+		    state_machine_regs.view = 0;
 		}
 
 	      adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
 	      state_machine_regs.line += adv;
 	      is_special_opcode = 1;
+	      /* Increment view after printing this row.  */
 	    }
 	  else switch (op_code)
 		 {
@@ -3980,11 +4034,13 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		       }
 		     ext_op_code_len += bytes_read;
 		     ext_op_code = *op_code_data++;
+		     xop = ext_op_code;
+		     xop = -xop;
 
 		     switch (ext_op_code)
 		       {
 		       case DW_LNE_end_sequence:
-			 reset_state_machine (linfo.li_default_is_stmt);
+			 /* Reset stuff after printing this row.  */
 			 break;
 		       case DW_LNE_set_address:
 			 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
@@ -3992,6 +4048,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
 						ext_op_code_len - bytes_read - 1,
 						end);
 			 state_machine_regs.op_index = 0;
+			 state_machine_regs.view = 0;
 			 break;
 		       case DW_LNE_define_file:
 			 {
@@ -4034,6 +4091,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		     break;
 		   }
 		 case DW_LNS_copy:
+		   /* Increment view after printing this row.  */
 		   break;
 
 		 case DW_LNS_advance_pc:
@@ -4043,16 +4101,22 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		     {
 		       uladv *= linfo.li_min_insn_length;
 		       state_machine_regs.address += uladv;
+		       if (uladv)
+			 state_machine_regs.view = 0;
 		     }
 		   else
 		     {
-		       state_machine_regs.address
-			 += ((state_machine_regs.op_index + uladv)
-			     / linfo.li_max_ops_per_insn)
+		       unsigned addrdelta
+			 = ((state_machine_regs.op_index + uladv)
+			    / linfo.li_max_ops_per_insn)
 			 * linfo.li_min_insn_length;
+		       state_machine_regs.address
+			 += addrdelta;
 		       state_machine_regs.op_index
 			 = (state_machine_regs.op_index + uladv)
 			 % linfo.li_max_ops_per_insn;
+		       if (addrdelta)
+			 state_machine_regs.view = 0;
 		     }
 		   break;
 
@@ -4121,16 +4185,22 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		     {
 		       uladv *= linfo.li_min_insn_length;
 		       state_machine_regs.address += uladv;
+		       if (uladv)
+			 state_machine_regs.view = 0;
 		     }
 		   else
 		     {
-		       state_machine_regs.address
-			 += ((state_machine_regs.op_index + uladv)
-			     / linfo.li_max_ops_per_insn)
+		       unsigned addrdelta
+			 = ((state_machine_regs.op_index + uladv)
+			    / linfo.li_max_ops_per_insn)
 			 * linfo.li_min_insn_length;
+		       state_machine_regs.address
+			 += addrdelta;
 		       state_machine_regs.op_index
 			 = (state_machine_regs.op_index + uladv)
 			 % linfo.li_max_ops_per_insn;
+		       if (addrdelta)
+			 state_machine_regs.view = 0;
 		     }
 		   break;
 
@@ -4138,6 +4208,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
 		   SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
 		   state_machine_regs.address += uladv;
 		   state_machine_regs.op_index = 0;
+		   /* Do NOT reset view.  */
 		   break;
 
 		 case DW_LNS_set_prologue_end:
@@ -4169,8 +4240,8 @@ display_debug_lines_decoded (struct dwarf_section *section,
 
 	  /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
 	     to the DWARF address/line matrix.  */
-	  if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
-	      || (op_code == DW_LNS_copy))
+	  if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
+	      || (xop == DW_LNS_copy))
 	    {
 	      const unsigned int MAX_FILENAME_LENGTH = 35;
 	      char *fileName;
@@ -4211,11 +4282,11 @@ display_debug_lines_decoded (struct dwarf_section *section,
 	      if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
 		{
 		  if (linfo.li_max_ops_per_insn == 1)
-		    printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x\n",
+		    printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x",
 			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address);
 		  else
-		    printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x[%d]\n",
+		    printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x[%d]",
 			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address,
 			    state_machine_regs.op_index);
@@ -4223,18 +4294,27 @@ display_debug_lines_decoded (struct dwarf_section *section,
 	      else
 		{
 		  if (linfo.li_max_ops_per_insn == 1)
-		    printf ("%s  %11d  %#18" DWARF_VMA_FMT "x\n",
+		    printf ("%s  %11d  %#18" DWARF_VMA_FMT "x",
 			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address);
 		  else
-		    printf ("%s  %11d  %#18" DWARF_VMA_FMT "x[%d]\n",
+		    printf ("%s  %11d  %#18" DWARF_VMA_FMT "x[%d]",
 			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address,
 			    state_machine_regs.op_index);
 		}
 
-	      if (op_code == DW_LNE_end_sequence)
-		printf ("\n");
+	      if (state_machine_regs.view)
+		printf ("  %6u\n", state_machine_regs.view);
+	      else
+		putchar ('\n');
+	      state_machine_regs.view++;
+
+	      if (xop == -DW_LNE_end_sequence)
+		{
+		  reset_state_machine (linfo.li_default_is_stmt);
+		  putchar ('\n');
+		}
 
 	      free (newFileName);
 	    }
diff --git a/binutils/testsuite/binutils-all/dw2-1.W b/binutils/testsuite/binutils-all/dw2-1.W
index d70581b..fb9c798 100644
--- a/binutils/testsuite/binutils-all/dw2-1.W
+++ b/binutils/testsuite/binutils-all/dw2-1.W
@@ -69,7 +69,7 @@ Raw dump of debug contents of section .z?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to 0x4
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to 0x8
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/binutils/testsuite/binutils-all/dw2-3.W b/binutils/testsuite/binutils-all/dw2-3.W
index 08a7f35..af77f87 100644
--- a/binutils/testsuite/binutils-all/dw2-3.W
+++ b/binutils/testsuite/binutils-all/dw2-3.W
@@ -149,7 +149,7 @@ Raw dump of debug contents of section .z?debug_line:
   \[0x0000002d\]  Extended opcode 2: set Address to 0x0
   \[0x00000034\]  Advance Line by 3 to 4
   \[0x00000036\]  Copy
-  \[0x00000037\]  Copy
+  \[0x00000037\]  Copy \(view 1\)
   \[0x00000038\]  Extended opcode 2: set Address to 0x4
   \[0x0000003f\]  Extended opcode 1: End of Sequence
 
diff --git a/binutils/testsuite/binutils-all/dw2-3gabi.W b/binutils/testsuite/binutils-all/dw2-3gabi.W
index 0d0fe6a..4a79260 100644
--- a/binutils/testsuite/binutils-all/dw2-3gabi.W
+++ b/binutils/testsuite/binutils-all/dw2-3gabi.W
@@ -149,7 +149,7 @@ Raw dump of debug contents of section .debug_line:
   \[0x0000002d\]  Extended opcode 2: set Address to 0x0
   \[0x00000034\]  Advance Line by 3 to 4
   \[0x00000036\]  Copy
-  \[0x00000037\]  Copy
+  \[0x00000037\]  Copy \(view 1\)
   \[0x00000038\]  Extended opcode 2: set Address to 0x4
   \[0x0000003f\]  Extended opcode 1: End of Sequence
 
diff --git a/binutils/testsuite/binutils-all/dw5.W b/binutils/testsuite/binutils-all/dw5.W
index 6f3f8ef..1fa0d5d 100644
--- a/binutils/testsuite/binutils-all/dw5.W
+++ b/binutils/testsuite/binutils-all/dw5.W
@@ -345,11 +345,13 @@ Raw dump of debug contents of section .debug_line:
 Decoded dump of debug contents of section .debug_line:
 
 CU: ./main.c:
-File name                            Line number    Starting address
+File name                            Line number    Starting address    View
 main.c                                         6              0x1234
 main.c                                         6             0x12346
+main.c                                         6              0x1234
 
 main.c                                         5              0x1234
 main.c                                         5              0x1234
+main.c                                         5              0x1234
 
 
diff --git a/binutils/testsuite/binutils-all/i386/compressed-1a.d b/binutils/testsuite/binutils-all/i386/compressed-1a.d
index 5f02def..a45c6b8 100644
--- a/binutils/testsuite/binutils-all/i386/compressed-1a.d
+++ b/binutils/testsuite/binutils-all/i386/compressed-1a.d
@@ -96,7 +96,7 @@ Raw dump of debug contents of section .[z]?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to 0x0
   \[0x.*\]  Advance Line by 10 to 11
   \[0x.*\]  Copy
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 12
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 12 \(view 1\)
   \[0x.*\]  Advance Line by -7 to 5
   \[0x.*\]  Special opcode 229: advance Address by 16 to 0x10 and Line by 0 to 5
   \[0x.*\]  Special opcode 49: advance Address by 3 to 0x13 and Line by 2 to 7
diff --git a/binutils/testsuite/binutils-all/libdw2-compressedgabi.out b/binutils/testsuite/binutils-all/libdw2-compressedgabi.out
index 3baa42a..ab456d5 100644
--- a/binutils/testsuite/binutils-all/libdw2-compressedgabi.out
+++ b/binutils/testsuite/binutils-all/libdw2-compressedgabi.out
@@ -70,7 +70,7 @@ Raw dump of debug contents of section .debug_line:
   \[0x.*\]  Extended opcode 2: set Address to 0x4
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to 0x8
   \[0x.*\]  Extended opcode 1: End of Sequence
 
@@ -172,7 +172,7 @@ Raw dump of debug contents of section .debug_line:
   \[0x0000002d\]  Extended opcode 2: set Address to 0x0
   \[0x00000034\]  Advance Line by 3 to 4
   \[0x00000036\]  Copy
-  \[0x00000037\]  Copy
+  \[0x00000037\]  Copy \(view 1\)
   \[0x00000038\]  Extended opcode 2: set Address to 0x4
   \[0x0000003f\]  Extended opcode 1: End of Sequence
 
@@ -355,7 +355,7 @@ Raw dump of debug contents of section .debug_line:
   \[0x0000002d\]  Extended opcode 2: set Address to 0x0
   \[0x00000034\]  Advance Line by 3 to 4
   \[0x00000036\]  Copy
-  \[0x00000037\]  Copy
+  \[0x00000037\]  Copy \(view 1\)
   \[0x00000038\]  Extended opcode 2: set Address to 0x4
   \[0x0000003f\]  Extended opcode 1: End of Sequence
 
diff --git a/binutils/testsuite/binutils-all/objdump.W b/binutils/testsuite/binutils-all/objdump.W
index a5379d0..5f977ee 100644
--- a/binutils/testsuite/binutils-all/objdump.W
+++ b/binutils/testsuite/binutils-all/objdump.W
@@ -69,7 +69,7 @@ Raw dump of debug contents of section .z?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/binutils/testsuite/binutils-all/objdump.WL b/binutils/testsuite/binutils-all/objdump.WL
index 3846f4f..7c5a591 100644
--- a/binutils/testsuite/binutils-all/objdump.WL
+++ b/binutils/testsuite/binutils-all/objdump.WL
@@ -4,7 +4,7 @@
 Decoded dump of debug contents of section \.debug_line:
 
 CU: \./dw2-decodedline\.c:
-File name                            Line number    Starting address
+File name                            Line number    Starting address    View
 
 directory/file1\.c:
 file1\.c                                        1 .*
@@ -12,4 +12,5 @@ file1\.c                                        1 .*
 
 \./dw2-decodedline\.c:\[\+\+\]
 dw2-decodedline\.c                              2 .*
+dw2-decodedline\.c                              2 .*
 
diff --git a/binutils/testsuite/binutils-all/x86-64/compressed-1a.d b/binutils/testsuite/binutils-all/x86-64/compressed-1a.d
index 574b719..75b8ce5 100644
--- a/binutils/testsuite/binutils-all/x86-64/compressed-1a.d
+++ b/binutils/testsuite/binutils-all/x86-64/compressed-1a.d
@@ -96,10 +96,10 @@ Raw dump of debug contents of section .[z]?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to 0x0
   \[0x.*\]  Advance Line by 10 to 11
   \[0x.*\]  Copy
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 12
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 12 \(view 1\)
   \[0x.*\]  Advance Line by -7 to 5
   \[0x.*\]  Special opcode 229: advance Address by 16 to 0x10 and Line by 0 to 5
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x10 and Line by 1 to 6
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x10 and Line by 1 to 6 \(view 1\)
   \[0x.*\]  Advance PC by 5 to 0x15
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/gas/doc/as.texinfo b/gas/doc/as.texinfo
index e0637c7..65b14a4 100644
--- a/gas/doc/as.texinfo
+++ b/gas/doc/as.texinfo
@@ -5833,6 +5833,19 @@ state machine to @var{value}, which must be an unsigned integer.
 This directive will set the @code{discriminator} register in the @code{.debug_line}
 state machine to @var{value}, which must be an unsigned integer.
 
+@item view @var{value}
+This option causes a row to be added to @code{.debug_line} in reference to the
+current address (which might not be the same as that of the following assembly
+instruction), and to associate @var{value} with the @code{view} register in the
+@code{.debug_line} state machine.  If @var{value} is a label, both the
+@code{view} register and the label are set to the number of prior @code{.loc}
+directives at the same program location.  If @var{value} is the literal
+@code{0}, the @code{view} register is set to zero, and the assembler asserts
+that there aren't any prior @code{.loc} directives at the same program
+location.  If @var{value} is the literal @code{-0}, the assembler arrange for
+the @code{view} register to be reset in this row, even if there are prior
+@code{.loc} directives at the same program location.
+
 @end table
 
 @node Loc_mark_labels
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index e02b6e8..c3d6043 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -168,6 +168,11 @@ struct line_entry {
   struct dwarf2_line_info loc;
 };
 
+/* Don't change the offset of next in line_entry.  set_or_check_view
+   calls in dwarf2_gen_line_info_1 depend on it.  */
+static char unused[offsetof(struct line_entry, next) ? -1 : 1]
+ATTRIBUTE_UNUSED;
+
 struct line_subseg {
   struct line_subseg *next;
   subsegT subseg;
@@ -215,9 +220,17 @@ bfd_boolean dwarf2_loc_mark_labels;
 static struct dwarf2_line_info current = {
   1, 1, 0, 0,
   DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0,
-  0
+  0, NULL
 };
 
+/* This symbol is used to recognize view number forced resets in loc
+   lists.  */
+static symbolS *force_reset_view;
+
+/* This symbol evaluates to an expression that, if nonzero, indicates
+   some view assert check failed.  */
+static symbolS *view_assert_failed;
+
 /* The size of an address on the target.  */
 static unsigned int sizeof_address;
 
@@ -283,6 +296,162 @@ get_line_subseg (segT seg, subsegT subseg, bfd_boolean create_p)
   return lss;
 }
 
+/* (Un)reverse the line_entry list starting from H.  */
+
+static struct line_entry *
+reverse_line_entry_list (struct line_entry *h)
+{
+  struct line_entry *p = NULL, *e, *n;
+  for (e = h; e; e = n)
+    {
+      n = e->next;
+      e->next = p;
+      p = e;
+    }
+  return p;
+}
+
+/* Compute the view for E based on the previous entry P.  If we
+   introduce an (undefined) view symbol for P, and H is given (P must
+   be the tail in this case), introduce view symbols for earlier list
+   entries as well, until one of them is constant.
+ */
+
+static void
+set_or_check_view (struct line_entry *e, struct line_entry *p,
+		   struct line_entry *h)
+{
+  expressionS viewx;
+  memset (&viewx, 0, sizeof (viewx));
+  viewx.X_unsigned = 1;
+
+  /* First, compute !(E->label > P->label), to tell whether or not
+     we're to reset the view number.  If we can't resolve it to a
+     constant, keep it symbolic.  */
+  if (!p || (e->loc.view == force_reset_view && force_reset_view))
+    {
+      viewx.X_op = O_constant;
+      viewx.X_add_number = 0;
+      viewx.X_add_symbol = NULL;
+      viewx.X_op_symbol = NULL;
+    }
+  else
+    {
+      viewx.X_op = O_gt;
+      viewx.X_add_number = 0;
+      viewx.X_add_symbol = e->label;
+      viewx.X_op_symbol = p->label;
+      resolve_expression (&viewx);
+      if (viewx.X_op == O_constant)
+	viewx.X_add_number = !viewx.X_add_number;
+      else
+	{
+	  viewx.X_add_symbol = make_expr_symbol (&viewx);
+	  viewx.X_add_number = 0;
+	  viewx.X_op_symbol = NULL;
+	  viewx.X_op = O_logical_not;
+	}
+    }
+
+  if (S_IS_DEFINED (e->loc.view) && symbol_constant_p (e->loc.view))
+    {
+      expressionS *value = symbol_get_value_expression (e->loc.view);
+      /* We can't compare the view numbers at this point, because in
+	 VIEWX we've only determined whether we're to reset it so
+	 far.  */
+      if (viewx.X_op == O_constant)
+	{
+	  if (!value->X_add_number != !viewx.X_add_number)
+	    as_bad (_("view number mismatch"));
+	}
+      /* Record the expression to check it later.  It is the result of
+	 a logical not, thus 0 or 1.  We just add up all such deferred
+	 expressions, and resolve it at the end.  */
+      else if (!value->X_add_number)
+	{
+	  symbolS *deferred = make_expr_symbol (&viewx);
+	  if (view_assert_failed)
+	    {
+	      expressionS chk;
+	      memset (&chk, 0, sizeof (chk));
+	      chk.X_unsigned = 1;
+	      chk.X_op = O_add;
+	      chk.X_add_number = 0;
+	      chk.X_add_symbol = view_assert_failed;
+	      chk.X_op_symbol = deferred;
+	      deferred = make_expr_symbol (&chk);
+	    }
+	  view_assert_failed = deferred;
+	}
+    }
+
+  if (viewx.X_op != O_constant || viewx.X_add_number)
+    {
+      if (!p->loc.view)
+	{
+	  p->loc.view = symbol_temp_make ();
+	  gas_assert (!S_IS_DEFINED (p->loc.view));
+	}
+
+      expressionS incv;
+      memset (&incv, 0, sizeof (incv));
+      incv.X_unsigned = 1;
+      incv.X_op = O_symbol;
+      incv.X_add_symbol = p->loc.view;
+      incv.X_add_number = 1;
+
+      if (viewx.X_op == O_constant)
+	{
+	  gas_assert (viewx.X_add_number == 1);
+	  viewx = incv;
+	}
+      else
+	{
+	  viewx.X_add_symbol = make_expr_symbol (&viewx);
+	  viewx.X_add_number = 0;
+	  viewx.X_op_symbol = make_expr_symbol (&incv);
+	  viewx.X_op = O_multiply;
+	}
+    }
+
+  if (!S_IS_DEFINED (e->loc.view))
+    {
+      symbol_set_value_expression (e->loc.view, &viewx);
+      S_SET_SEGMENT (e->loc.view, absolute_section);
+      symbol_set_frag (e->loc.view, &zero_address_frag);
+    }
+
+  /* Define and attempt to simplify any earlier views needed to
+     compute E's.  */
+  if (h && p && p->loc.view && !S_IS_DEFINED (p->loc.view))
+    {
+      /* Reverse the list to avoid quadratic behavior going backwards
+	 in a single-linked list.  */
+      struct line_entry *r = reverse_line_entry_list (h);
+      gas_assert (r == p);
+      /* Set or check views until we find a defined or absent view.  */
+      do
+	set_or_check_view (r, r->next, NULL);
+      while (r->next && r->next->loc.view && !S_IS_DEFINED (r->next->loc.view)
+	     && (r = r->next));
+      /* Unreverse the list, so that we can go forward again.  */
+      struct line_entry *h2 = reverse_line_entry_list (p);
+      gas_assert (h2 == h);
+      /* Starting from the last view we just defined, attempt to
+	 simplify the view expressions, until we do so to P.  */
+      do
+	{
+	  gas_assert (S_IS_DEFINED (r->loc.view));
+	  resolve_expression (symbol_get_value_expression (r->loc.view));
+	}
+      while (r != p && (r = r->next));
+
+      /* Now that we've defined and computed all earlier views that might
+	 be needed to compute E's, attempt to simplify it.  */
+      resolve_expression (symbol_get_value_expression (e->loc.view));
+    }
+}
+
 /* Record an entry for LOC occurring at LABEL.  */
 
 static void
@@ -297,6 +466,12 @@ dwarf2_gen_line_info_1 (symbolS *label, struct dwarf2_line_info *loc)
   e->loc = *loc;
 
   lss = get_line_subseg (now_seg, now_subseg, TRUE);
+
+  if (loc->view)
+    set_or_check_view (e,
+		       !lss->head ? NULL : (struct line_entry *)lss->ptail,
+		       lss->head);
+
   *lss->ptail = e;
   lss->ptail = &e->next;
 }
@@ -350,12 +525,14 @@ dwarf2_where (struct dwarf2_line_info *line)
 {
   if (debug_type == DEBUG_DWARF2)
     {
+      memset (line, 0, sizeof (*line));
       const char *filename = as_where (&line->line);
       line->filenum = get_filenum (filename, 0);
       line->column = 0;
       line->flags = DWARF2_FLAG_IS_STMT;
       line->isa = current.isa;
       line->discriminator = current.discriminator;
+      line->view = NULL;
     }
   else
     *line = current;
@@ -380,7 +557,9 @@ dwarf2_emit_insn (int size)
 {
   struct dwarf2_line_info loc;
 
-  if (!dwarf2_loc_directive_seen && debug_type != DEBUG_DWARF2)
+  if (debug_type != DEBUG_DWARF2
+      ? !dwarf2_loc_directive_seen
+      : !seen_at_least_1_file ())
     return;
 
   dwarf2_where (&loc);
@@ -721,6 +900,50 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
 	      return;
 	    }
 	}
+      else if (strcmp (p, "view") == 0)
+	{
+	  (void) restore_line_pointer (c);
+	  symbolS *sym;
+	  SKIP_WHITESPACE ();
+	  if (ISDIGIT (*input_line_pointer)
+	      || *input_line_pointer == '-')
+	    {
+	      bfd_boolean force_reset = *input_line_pointer == '-';
+	      value = get_absolute_expression ();
+	      if (value != 0)
+		{
+		  as_bad (_("numeric view can only be asserted to zero"));
+		  return;
+		}
+	      if (force_reset && force_reset_view)
+		sym = force_reset_view;
+	      else
+		{
+		  sym = symbol_temp_new (absolute_section, value,
+					 &zero_address_frag);
+		  if (force_reset)
+		    force_reset_view = sym;
+		}
+	    }
+	  else
+	    {
+	      char *name = read_symbol_name ();
+	      if (!name)
+		return;
+	      sym = symbol_find_or_make (name);
+	      if (S_IS_DEFINED (sym))
+		{
+		  if (!S_CAN_BE_REDEFINED (sym))
+		    as_bad (_("symbol `%s' is already defined"), name);
+		  else
+		    sym = symbol_clone (sym, 1);
+		  S_SET_SEGMENT (sym, undefined_section);
+		  S_SET_VALUE (sym, 0);
+		  symbol_set_frag (sym, &zero_address_frag);
+		}
+	    }
+	  current.view = sym;
+	}
       else
 	{
 	  as_bad (_("unknown .loc sub-directive `%s'"), p);
@@ -734,6 +957,10 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
   dwarf2_loc_directive_seen = TRUE;
   debug_type = DEBUG_NONE;
+
+  /* If we were given a view id, emit the row right away.  */
+  if (current.view)
+    dwarf2_emit_insn (0);
 }
 
 void
@@ -1362,7 +1589,19 @@ process_entries (segT seg, struct line_entry *e)
       frag = symbol_get_frag (lab);
       frag_ofs = S_GET_VALUE (lab);
 
-      if (last_frag == NULL)
+      if (last_frag == NULL
+	  || (e->loc.view == force_reset_view && force_reset_view
+	      /* If we're to reset the view, but we know we're
+		 advancing PC, we don't have to force with
+		 set_address.  We know we do when we're at the same
+		 address of the same frag, and we know we might when
+		 we're in the beginning of a frag, and we were at the
+		 end of the previous frag.  */
+	      && (frag == last_frag
+		  ? (last_frag_ofs == frag_ofs)
+		  : (frag_ofs == 0
+		     && ((offsetT)last_frag_ofs
+			 >= get_frag_fix (last_frag, seg))))))
 	{
 	  out_set_addr (lab);
 	  out_inc_line_addr (line_delta, 0);
@@ -1975,3 +2214,38 @@ dwarf2_finish (void)
 		      name_sym, comp_dir_sym, producer_sym);
     }
 }
+
+/* Perform any deferred checks pertaining to debug information.  */
+
+void
+dwarf2dbg_final_check (void)
+{
+  /* Perform reset-view checks.  Don't evaluate view_assert_failed
+     recursively: it could be very deep.  It's a chain of adds, with
+     each chain element pointing to the next in X_add_symbol, and
+     holding the check value in X_op_symbol.  */
+  while (view_assert_failed)
+    {
+      gas_assert (!symbol_resolved_p (view_assert_failed));
+
+      expressionS *expr = symbol_get_value_expression (view_assert_failed);
+      symbolS *sym = view_assert_failed;
+
+      /* If view_assert_failed looks like a compound check in the
+	 chain, break it up.  */
+      if (expr->X_op == O_add && expr->X_add_number == 0 && expr->X_unsigned)
+	{
+	  view_assert_failed = expr->X_add_symbol;
+	  sym = expr->X_op_symbol;
+	}
+      else
+	view_assert_failed = NULL;
+
+      offsetT failed = resolve_symbol_value (sym);
+      if (!symbol_resolved_p (sym) || failed)
+	{
+	  as_bad (_("view number mismatch"));
+	  break;
+	}
+    }
+}
diff --git a/gas/dwarf2dbg.h b/gas/dwarf2dbg.h
index 9e2cead..49826fd 100644
--- a/gas/dwarf2dbg.h
+++ b/gas/dwarf2dbg.h
@@ -35,6 +35,7 @@ struct dwarf2_line_info {
   unsigned int isa;
   unsigned int flags;
   unsigned int discriminator;
+  symbolS *view;
 };
 
 /* Implements the .file FILENO "FILENAME" directive.  FILENO can be 0
@@ -99,6 +100,8 @@ extern int dwarf2dbg_estimate_size_before_relax (fragS *);
 extern int dwarf2dbg_relax_frag (fragS *);
 extern void dwarf2dbg_convert_frag (fragS *);
 
+extern void dwarf2dbg_final_check (void);
+
 /* An enumeration which describes the sizes of offsets (to DWARF sections)
    and the mechanism by which the size is indicated.  */
 enum dwarf2_format {
diff --git a/gas/read.c b/gas/read.c
index a26d4fe..9627ef5 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -5384,7 +5384,7 @@ s_leb128 (int sign)
 
   do
     {
-      expression (&exp);
+      deferred_expression (&exp);
       emit_leb128_expr (&exp, sign);
     }
   while (*input_line_pointer++ == ',');
diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
index b5b0beb..e43947d4 100644
--- a/gas/testsuite/gas/all/gas.exp
+++ b/gas/testsuite/gas/all/gas.exp
@@ -394,6 +394,7 @@ if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] } {
     run_dump_test sleb128-7
     run_dump_test sleb128-8
 }
+run_dump_test sleb128-9
 
 # .byte is 32 bits on tic4x, and .p2align isn't supported on tic54x
 # .space is different on hppa*-hpux.
diff --git a/gas/testsuite/gas/all/sleb128-9.d b/gas/testsuite/gas/all/sleb128-9.d
new file mode 100644
index 0000000..16f81ca
--- /dev/null
+++ b/gas/testsuite/gas/all/sleb128-9.d
@@ -0,0 +1,4 @@
+#name: undefined symbols in sleb128 directive
+#source: sleb128-9.s
+#error-output: sleb128-9.l
+#target: *-*-*
diff --git a/gas/testsuite/gas/all/sleb128-9.l b/gas/testsuite/gas/all/sleb128-9.l
new file mode 100644
index 0000000..19842fa
--- /dev/null
+++ b/gas/testsuite/gas/all/sleb128-9.l
@@ -0,0 +1,3 @@
+[^:]*: Assembler messages:
+[^:]*:2: Error: leb128 operand is an undefined symbol: \.Lundef
+[^:]*:3: Error: leb128 operand is an undefined symbol: undef
diff --git a/gas/testsuite/gas/all/sleb128-9.s b/gas/testsuite/gas/all/sleb128-9.s
new file mode 100644
index 0000000..87cb955
--- /dev/null
+++ b/gas/testsuite/gas/all/sleb128-9.s
@@ -0,0 +1,3 @@
+	.data
+	.sleb128 .Lundef
+	.sleb128 undef
diff --git a/gas/testsuite/gas/elf/dwarf2-1.d b/gas/testsuite/gas/elf/dwarf2-1.d
index bae2f63..d8b79ef 100644
--- a/gas/testsuite/gas/elf/dwarf2-1.d
+++ b/gas/testsuite/gas/elf/dwarf2-1.d
@@ -71,7 +71,7 @@ Raw dump of debug contents of section .[z]?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/gas/testsuite/gas/elf/dwarf2-10.d b/gas/testsuite/gas/elf/dwarf2-10.d
new file mode 100644
index 0000000..4a4ef2c
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-10.d
@@ -0,0 +1,3 @@
+#as:
+#name: DWARF2 10
+#error-output: dwarf2-10.l
diff --git a/gas/testsuite/gas/elf/dwarf2-10.l b/gas/testsuite/gas/elf/dwarf2-10.l
new file mode 100644
index 0000000..b5f1f65
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-10.l
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*: Error: view number mismatch
diff --git a/gas/testsuite/gas/elf/dwarf2-10.s b/gas/testsuite/gas/elf/dwarf2-10.s
new file mode 100644
index 0000000..d159d43
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-10.s
@@ -0,0 +1,32 @@
+/* Test view numbering zero-assert checking with zero-sized align.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-10.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-10.c"
+	.loc 1 1 view 0
+	.balign 4	/* No skip needed here...  */
+	.loc 1 2 view 0	/* so this zero-view check fails.  */
+	.int 0
+	.loc 1 3 view 0
+	.balign 8	/* Skip 4 more bytes after .int...  */
+	.loc 1 4 view 0	/* so this is a zero view indeed.  */
+	.int 0
+	.size _start, .-_start
diff --git a/gas/testsuite/gas/elf/dwarf2-11.d b/gas/testsuite/gas/elf/dwarf2-11.d
new file mode 100644
index 0000000..04d4473
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-11.d
@@ -0,0 +1,11 @@
+#as:
+#readelf: -wL
+#name: DWARF2 11
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-11\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-11\.c  *1  *0x4
+dwarf2-11\.c  *2  *0x8
+dwarf2-11\.c  *2  *0x8  *1
diff --git a/gas/testsuite/gas/elf/dwarf2-11.s b/gas/testsuite/gas/elf/dwarf2-11.s
new file mode 100644
index 0000000..187def5
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-11.s
@@ -0,0 +1,28 @@
+/* Test view numbering zero-assert checking with nonzero-sized align.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-11.c"
+	.text
+	.balign 8
+	.globl _start
+_start:
+	.file 1 "dwarf2-11.c"
+	.int 0
+	.loc 1 1 view 0
+	.balign 8
+	.loc 1 2 view 0
+	.size _start, .-_start
diff --git a/gas/testsuite/gas/elf/dwarf2-12.d b/gas/testsuite/gas/elf/dwarf2-12.d
new file mode 100644
index 0000000..a58e374
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-12.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 12
+
+Hex dump of section '\.rodata':
+  0x00000000 01 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-12\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-12\.c  *1  *0
+dwarf2-12\.c  *2  *0
+dwarf2-12\.c  *3  *0  *1
+dwarf2-12\.c  *3  *0x4
diff --git a/gas/testsuite/gas/elf/dwarf2-12.s b/gas/testsuite/gas/elf/dwarf2-12.s
new file mode 100644
index 0000000..1a851d6
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-12.s
@@ -0,0 +1,31 @@
+/* Test view numbering forced reset in a single frag.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-12.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-12.c"
+	.loc 1 1 view 0
+	.loc 1 2 view -0
+	.loc 1 3 view .L1
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
diff --git a/gas/testsuite/gas/elf/dwarf2-13.d b/gas/testsuite/gas/elf/dwarf2-13.d
new file mode 100644
index 0000000..d8b6aba
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-13.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 13
+
+Hex dump of section '\.rodata':
+  0x00000000 01 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-13\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-13\.c  *1  *0x4
+dwarf2-13\.c  *2  *0x8
+dwarf2-13\.c  *3  *0x8  *1
+dwarf2-13\.c  *3  *0xc
diff --git a/gas/testsuite/gas/elf/dwarf2-13.s b/gas/testsuite/gas/elf/dwarf2-13.s
new file mode 100644
index 0000000..c13f9d4
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-13.s
@@ -0,0 +1,33 @@
+/* Test view numbering forced reset after a nonzero-sized align.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-13.c"
+	.text
+	.balign 8
+	.globl _start
+_start:
+	.file 1 "dwarf2-13.c"
+	.int 0
+	.loc 1 1 view 0
+	.balign 8
+	.loc 1 2 view -0
+	.loc 1 3 view .L1
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
diff --git a/gas/testsuite/gas/elf/dwarf2-14.d b/gas/testsuite/gas/elf/dwarf2-14.d
new file mode 100644
index 0000000..dfb3c3b
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-14.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 14
+
+Hex dump of section '\.rodata':
+  0x00000000 01 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-14\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-14\.c  *1  *0
+dwarf2-14\.c  *2  *0
+dwarf2-14\.c  *3  *0  *1
+dwarf2-14\.c  *3  *0x4
diff --git a/gas/testsuite/gas/elf/dwarf2-14.s b/gas/testsuite/gas/elf/dwarf2-14.s
new file mode 100644
index 0000000..4dde965
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-14.s
@@ -0,0 +1,32 @@
+/* Test view numbering forced reset after a zero-sized align.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-14.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-14.c"
+	.loc 1 1 view 0
+	.balign 4
+	.loc 1 2 view -0
+	.loc 1 3 view .L1
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
diff --git a/gas/testsuite/gas/elf/dwarf2-15.d b/gas/testsuite/gas/elf/dwarf2-15.d
new file mode 100644
index 0000000..eaf50c4
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-15.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 15
+
+Hex dump of section '\.rodata':
+  0x00000000 01 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-15\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-15\.c  *1  *0
+dwarf2-15\.c  *2  *0x4
+dwarf2-15\.c  *3  *0x4  *1
+dwarf2-15\.c  *3  *0x8
diff --git a/gas/testsuite/gas/elf/dwarf2-15.s b/gas/testsuite/gas/elf/dwarf2-15.s
new file mode 100644
index 0000000..1fbd594
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-15.s
@@ -0,0 +1,32 @@
+/* Test view numbering forced reset in a single frag.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-15.c"
+	.text
+	.balign 8
+	.globl _start
+_start:
+	.file 1 "dwarf2-15.c"
+	.loc 1 1 view 0
+	.int 0
+	.loc 1 2 view -0
+	.loc 1 3 view .L1
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
diff --git a/gas/testsuite/gas/elf/dwarf2-16.d b/gas/testsuite/gas/elf/dwarf2-16.d
new file mode 100644
index 0000000..44301a7
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-16.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 16
+
+Hex dump of section '\.rodata':
+  0x00000000 01 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-16\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-16\.c  *1  *0
+dwarf2-16\.c  *2  *0x4
+dwarf2-16\.c  *3  *0x4  *1
+dwarf2-16\.c  *3  *0x8
diff --git a/gas/testsuite/gas/elf/dwarf2-16.s b/gas/testsuite/gas/elf/dwarf2-16.s
new file mode 100644
index 0000000..7976614
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-16.s
@@ -0,0 +1,33 @@
+/* Test view numbering after a zero-sized align.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-16.c"
+	.text
+	.balign 8
+	.globl _start
+_start:
+	.file 1 "dwarf2-16.c"
+	.loc 1 1 view 0
+	.int 0
+	.loc 1 2 view 0
+	.balign 4
+	.loc 1 3 view .L1
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
diff --git a/gas/testsuite/gas/elf/dwarf2-17.d b/gas/testsuite/gas/elf/dwarf2-17.d
new file mode 100644
index 0000000..5e7ccdc
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-17.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 17
+
+Hex dump of section '\.rodata':
+  0x00000000 00 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-17\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-17\.c  *1  *0
+dwarf2-17\.c  *2  *0x4
+dwarf2-17\.c  *3  *0x8
+dwarf2-17\.c  *3  *0xc
diff --git a/gas/testsuite/gas/elf/dwarf2-17.s b/gas/testsuite/gas/elf/dwarf2-17.s
new file mode 100644
index 0000000..26c24cb
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-17.s
@@ -0,0 +1,33 @@
+/* Test view numbering after a nonzero-sized align.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-17.c"
+	.text
+	.balign 8
+	.globl _start
+_start:
+	.file 1 "dwarf2-17.c"
+	.loc 1 1 view 0
+	.int 0
+	.loc 1 2 view 0
+	.balign 8
+	.loc 1 3 view .L1
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
diff --git a/gas/testsuite/gas/elf/dwarf2-18.d b/gas/testsuite/gas/elf/dwarf2-18.d
new file mode 100644
index 0000000..d695072
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-18.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 18
+
+Hex dump of section '\.rodata':
+  0x00000000 0100 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-18\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-18\.c  *1  *0
+dwarf2-18\.c  *2  *0  *1
+dwarf2-18\.c  *3  *0x4
+dwarf2-18\.c  *3  *0x8
diff --git a/gas/testsuite/gas/elf/dwarf2-18.s b/gas/testsuite/gas/elf/dwarf2-18.s
new file mode 100644
index 0000000..f32b3b3
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-18.s
@@ -0,0 +1,33 @@
+/* Test view numbering after view-less .loc.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-18.c"
+	.text
+	.balign 8
+	.globl _start
+_start:
+	.file 1 "dwarf2-18.c"
+	.loc 1 1
+	.loc 1 2 view .L1
+	.int 0
+	.loc 1 3 view .L2
+	.int 0
+	.size _start, .-_start
+
+	.section .rodata
+	.uleb128 .L1
+	.uleb128 .L2
diff --git a/gas/testsuite/gas/elf/dwarf2-2.d b/gas/testsuite/gas/elf/dwarf2-2.d
index b42a2ec..8cc1c3bb 100644
--- a/gas/testsuite/gas/elf/dwarf2-2.d
+++ b/gas/testsuite/gas/elf/dwarf2-2.d
@@ -71,7 +71,7 @@ Raw dump of debug contents of section .[z]?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/gas/testsuite/gas/elf/dwarf2-5.d b/gas/testsuite/gas/elf/dwarf2-5.d
new file mode 100644
index 0000000..a4598ba
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-5.d
@@ -0,0 +1,74 @@
+#as:
+#readelf: -x.rodata -wlL
+#name: DWARF2 5
+
+Hex dump of section '\.rodata':
+  0x00000000 01010201 010203 *.*
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      [0-9]*
+  DWARF Version:               2
+  Prologue Length:             [0-9]*
+  Minimum Instruction Length:  [0-9]*
+  Initial value of 'is_stmt':  1
+  Line Base:                   [-0-9]*
+  Line Range:                  [0-9]*
+  Opcode Base:                 [0-9]*
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table is empty.
+
+ The File Name Table \(offset 0x1c\):
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	dwarf2-5\.c
+
+ Line Number Statements:
+  \[0x.*\]  Extended opcode 2: set Address to 0x0
+  \[0x.*\]  Copy
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0x0 and Line by 1 to 2 \(view 1\)
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 4 to 0x4 and Line by 1 to 3
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0x4 and Line by 1 to 4 \(view 1\)
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0x4 and Line by 1 to 5 \(view 2\)
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 4 to 0x8 and Line by 1 to 6
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 4 to 0xc and Line by 1 to 7
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0xc and Line by 1 to 8 \(view 1\)
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 4 to 0x10 and Line by 1 to 9
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0x10 and Line by 1 to 10 \(view 1\)
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0x10 and Line by 1 to 11 \(view 2\)
+  \[0x.*\]  Special opcode [0-9]*: advance Address by 0 to 0x10 and Line by 1 to 12 \(view 3\)
+  \[0x.*\]  Advance PC by 4 to 0x14
+  \[0x.*\]  Extended opcode 1: End of Sequence
+
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-5\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-5\.c  *1  *0
+dwarf2-5\.c  *2  *0  *1
+dwarf2-5\.c  *3  *0x4
+dwarf2-5\.c  *4  *0x4  *1
+dwarf2-5\.c  *5  *0x4  *2
+dwarf2-5\.c  *6  *0x8
+dwarf2-5\.c  *7  *0xc
+dwarf2-5\.c  *8  *0xc  *1
+dwarf2-5\.c  *9  *0x10
+dwarf2-5\.c  *10  *0x10  *1
+dwarf2-5\.c  *11  *0x10  *2
+dwarf2-5\.c  *12  *0x10  *3
+dwarf2-5\.c  *12  *0x14
diff --git a/gas/testsuite/gas/elf/dwarf2-5.s b/gas/testsuite/gas/elf/dwarf2-5.s
new file mode 100644
index 0000000..91b9f95
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-5.s
@@ -0,0 +1,58 @@
+/* Test view numbering.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-5.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-5.c"
+	.loc 1 1 view 0
+	.loc 1 2 view .L2
+	.int 0
+	.loc 1 3 view 0
+	.balign 4
+	.loc 1 4 view .L4
+	.loc 1 5 view .L5
+	.org .+1
+	.balign 4
+	.loc 1 6 view 0
+	.int 0
+	.text
+	.globl func
+	.type func, %function
+func:
+	.loc 1 7 view 0
+	.loc 1 8 view .L8
+	.int 0
+	.loc 1 9 view 0
+	.loc 1 10 view .L10
+	.pushsection .text
+	.loc 1 11 view .L11
+	.popsection
+	.loc 1 12 view .L12
+	.int 0
+	.size func, .-func
+
+	.section .rodata
+	.uleb128 .L2
+	.uleb128 .L4
+	.uleb128 .L5
+	.uleb128 .L8
+	.uleb128 .L10
+	.uleb128 .L11
+	.uleb128 .L12
diff --git a/gas/testsuite/gas/elf/dwarf2-6.d b/gas/testsuite/gas/elf/dwarf2-6.d
new file mode 100644
index 0000000..39557e1
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-6.d
@@ -0,0 +1,76 @@
+#as:
+#readelf: -wlL
+#name: DWARF2 6
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      84
+  DWARF Version:               2
+  Prologue Length:             36
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table \(offset 0x1f\):
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	dwarf2-6\.c
+
+
+ Line Number Statements:
+  \[0x.*\]  Extended opcode 2: set Address to 0x0
+  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
+  \[0x.*\]  Extended opcode 2: set Address to 0x1
+  \[0x.*\]  Copy
+  \[0x.*\]  Advance PC by 0 to 0x1
+  \[0x.*\]  Copy \(view 1\)
+  \[0x.*\]  Advance PC by 1 to 0x2
+  \[0x.*\]  Copy
+  \[0x.*\]  Advance PC by fixed size amount 1 to 0x3
+  \[0x.*\]  Copy \(view 1\)
+  \[0x.*\]  Special opcode 0: advance Address by 0 to 0x3 and Line by 1 to 2 \(view 2\)
+  \[0x.*\]  Special opcode 1: advance Address by 1 to 0x4 and Line by 1 to 3
+  \[0x.*\]  Copy \(view 1\)
+  \[0x.*\]  Advance PC by constant 239 to 0xf3
+  \[0x.*\]  Copy
+  \[0x.*\]  Extended opcode 2: set Address to 0x100
+  \[0x.*\]  Extended opcode 1: End of Sequence
+
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-6\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-6\.c  *1  *0
+dwarf2-6\.c  *1  *0  *1
+dwarf2-6\.c  *1  *0x1
+dwarf2-6\.c  *1  *0x1  *1
+dwarf2-6\.c  *1  *0x2
+dwarf2-6\.c  *1  *0x3  *1
+dwarf2-6\.c  *2  *0x3  *2
+dwarf2-6\.c  *3  *0x4
+dwarf2-6\.c  *3  *0x4  *1
+dwarf2-6\.c  *3  *0xf3
+dwarf2-6\.c  *3  *0x100
diff --git a/gas/testsuite/gas/elf/dwarf2-6.s b/gas/testsuite/gas/elf/dwarf2-6.s
new file mode 100644
index 0000000..28b1829
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-6.s
@@ -0,0 +1,101 @@
+/* Test view number decoding.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-6.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+.L_start:
+	.org .+256
+.Lend_start:
+
+	.section .debug_line,"",%progbits
+	.4byte .Lline_end - .Lline_start  /* Initial length.  */
+.Lline_start:
+	.2byte 2 /* Dwarf Version.  */
+	.4byte .Lline_lines - .Lline_hdr
+.Lline_hdr:
+	.byte 1 /* Minimum insn length.  */
+	.byte 1 /* Default is_stmt.  */
+	.byte 1 /* Line base.  */
+	.byte 1 /* Line range.  */
+	.byte 0x10 /* Opcode base.  */
+
+	/* Standard lengths.  */
+	.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0
+
+	.byte 0 /* Include directories.  */
+
+	/* File names.  */
+	.ascii "dwarf2-6.c\0"
+	.uleb128 0, 0, 0
+
+	.byte 0
+
+.Lline_lines:
+	.byte 0 /* DW_LNS_extended_op.  */
+	.uleb128 5
+	.byte 2 /* DW_LNE_set_address.  */
+	.4byte .L_start
+
+	.byte 1 /* DW_LNS_copy view 0.  */
+
+	.byte 1 /* DW_LNS_copy view 1.  */
+
+	.byte 0 /* DW_LNS_extended_op.  */
+	.uleb128 5
+	.byte 2 /* DW_LNE_set_address.  */
+	.4byte .L_start+1
+
+	.byte 1 /* DW_LNS_copy view 0.  */
+
+	.byte 2 /* DW_LNS_advance_pc by 0.  */
+	.uleb128 0
+
+	.byte 1 /* DW_LNS_copy view 1.  */
+
+	.byte 2 /* DW_LNS_advance_pc by 1 (reset view).  */
+	.uleb128 1
+
+	.byte 1 /* DW_LNS_copy view 0.  */
+
+	.byte 9 /* DW_LNS_fixed_advance_pc by 1.  */
+	.2byte 1 /* This opcode does NOT reset view.  */
+
+	.byte 1 /* DW_LNS_copy view 1.  */
+
+	.byte 16 /* Special opcode 0, PC+=0, Line+=1, view 2.  */
+
+	.byte 17 /* Special opcode 1, PC+=1 (reset view), Line+=1.  */
+
+	.byte 1 /* DW_LNS_copy view 1.  */
+
+	.byte 8 /* DW_LNS_const_add_pc by 239 (reset view).  */
+
+	.byte 1 /* DW_LNS_copy view 0.  */
+
+	.byte 0 /* DW_LNS_extended_op.  */
+	.uleb128 5
+	.byte 2 /* DW_LNE_set_address.  */
+	.4byte .Lend_start
+
+	.byte 0 /* DW_LNS_extended_op.  */
+	.uleb128 1
+	.byte 1 /* DW_LEN_end_of_sequence.  */
+
+.Lline_end:
diff --git a/gas/testsuite/gas/elf/dwarf2-7.d b/gas/testsuite/gas/elf/dwarf2-7.d
new file mode 100644
index 0000000..d78d91e
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-7.d
@@ -0,0 +1,15 @@
+#as:
+#readelf: -x.rodata -wL
+#name: DWARF2 7
+
+Hex dump of section '\.rodata':
+  0x00000000 01 *.*
+
+Decoded dump of debug contents of section \.debug_line:
+
+CU: dwarf2-7\.c:
+File name  *Line number  *Starting address  *View
+dwarf2-7\.c  *1  *0
+dwarf2-7\.c  *2  *0
+dwarf2-7\.c  *3  *0  *1
+dwarf2-7\.c  *3  *0x4
diff --git a/gas/testsuite/gas/elf/dwarf2-7.s b/gas/testsuite/gas/elf/dwarf2-7.s
new file mode 100644
index 0000000..d8fd007
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-7.s
@@ -0,0 +1,36 @@
+/* Test view numbering forced reset.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-7.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-7.c"
+	.loc 1 1 view 0
+
+	.section .rodata
+	.uleb128 .L1
+
+	.text
+	.globl func
+	.type func, %function
+func:
+	.loc 1 2 view -0
+	.loc 1 3 view .L1
+	.int 0
+	.size func, .-func
diff --git a/gas/testsuite/gas/elf/dwarf2-8.d b/gas/testsuite/gas/elf/dwarf2-8.d
new file mode 100644
index 0000000..a28d613
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-8.d
@@ -0,0 +1,3 @@
+#as:
+#name: DWARF2 8
+#error-output: dwarf2-8.l
diff --git a/gas/testsuite/gas/elf/dwarf2-8.l b/gas/testsuite/gas/elf/dwarf2-8.l
new file mode 100644
index 0000000..60c73e5
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-8.l
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*:25: Error: view number mismatch
diff --git a/gas/testsuite/gas/elf/dwarf2-8.s b/gas/testsuite/gas/elf/dwarf2-8.s
new file mode 100644
index 0000000..228063c
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-8.s
@@ -0,0 +1,27 @@
+/* Test view numbering zero-assert checking, same frag.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-8.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-8.c"
+	.loc 1 1 view 0
+	.loc 1 2 view 0
+	.int 0
+	.size _start, .-_start
diff --git a/gas/testsuite/gas/elf/dwarf2-9.d b/gas/testsuite/gas/elf/dwarf2-9.d
new file mode 100644
index 0000000..7e40858
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-9.d
@@ -0,0 +1,3 @@
+#as:
+#name: DWARF2 9
+#error-output: dwarf2-9.l
diff --git a/gas/testsuite/gas/elf/dwarf2-9.l b/gas/testsuite/gas/elf/dwarf2-9.l
new file mode 100644
index 0000000..7f107fa
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-9.l
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*:30: Error: view number mismatch
diff --git a/gas/testsuite/gas/elf/dwarf2-9.s b/gas/testsuite/gas/elf/dwarf2-9.s
new file mode 100644
index 0000000..afc2019
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-9.s
@@ -0,0 +1,32 @@
+/* Test view numbering zero-assert checking, different frag.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.file "dwarf2-9.c"
+	.text
+	.balign 4
+	.globl _start
+_start:
+	.file 1 "dwarf2-9.c"
+	.loc 1 1 view 0
+
+	.section .rodata
+	.uleb128 0
+
+	.text
+	.loc 1 2 view 0
+	.int 0
+	.size _start, .-_start
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index 6b2b31a0..c04c74b 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -220,6 +220,20 @@ if { [is_elf_format] } then {
     run_dump_test "dwarf2-2"
     run_dump_test "dwarf2-3"
     run_dump_test "dwarf2-4"
+    run_dump_test "dwarf2-5"
+    run_dump_test "dwarf2-6"
+    run_dump_test "dwarf2-7"
+    run_dump_test "dwarf2-8"
+    run_dump_test "dwarf2-9"
+    run_dump_test "dwarf2-10"
+    run_dump_test "dwarf2-11"
+    run_dump_test "dwarf2-12"
+    run_dump_test "dwarf2-13"
+    run_dump_test "dwarf2-14"
+    run_dump_test "dwarf2-15"
+    run_dump_test "dwarf2-16"
+    run_dump_test "dwarf2-17"
+    run_dump_test "dwarf2-18"
     run_dump_test "bss"
     run_dump_test "bad-bss"
     run_dump_test "bad-section-flag"
diff --git a/gas/testsuite/gas/i386/dw2-compress-1.d b/gas/testsuite/gas/i386/dw2-compress-1.d
index ceebb3f..bfd4837 100644
--- a/gas/testsuite/gas/i386/dw2-compress-1.d
+++ b/gas/testsuite/gas/i386/dw2-compress-1.d
@@ -97,7 +97,7 @@ Raw dump of debug contents of section .z?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to 0x0
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to 0x4
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/gas/testsuite/gas/i386/dw2-compressed-1.d b/gas/testsuite/gas/i386/dw2-compressed-1.d
index f4c110d5..0a2a092 100644
--- a/gas/testsuite/gas/i386/dw2-compressed-1.d
+++ b/gas/testsuite/gas/i386/dw2-compressed-1.d
@@ -98,7 +98,7 @@ Raw dump of debug contents of section .debug_line:
   \[0x.*\]  Extended opcode 2: set Address to 0x0
   \[0x.*\]  Advance Line by 3 to 4
   \[0x.*\]  Copy
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Extended opcode 2: set Address to 0x4
   \[0x.*\]  Extended opcode 1: End of Sequence
 
diff --git a/gas/testsuite/gas/i386/ilp32/lns/lns-duplicate.d b/gas/testsuite/gas/i386/ilp32/lns/lns-duplicate.d
index c4e5c6f..fc0f861 100644
--- a/gas/testsuite/gas/i386/ilp32/lns/lns-duplicate.d
+++ b/gas/testsuite/gas/i386/ilp32/lns/lns-duplicate.d
@@ -7,5 +7,5 @@ Raw dump of debug contents of section \.z?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Copy
   \[0x.*\]  Set basic block
-  \[0x.*\]  .* by 1 to 2
+  \[0x.*\]  .* by 1 to 2 \(view 1\)
 #pass
diff --git a/gas/testsuite/gas/lns/lns-big-delta.d b/gas/testsuite/gas/lns/lns-big-delta.d
index d86f434..65e0ce1 100644
--- a/gas/testsuite/gas/lns/lns-big-delta.d
+++ b/gas/testsuite/gas/lns/lns-big-delta.d
@@ -8,7 +8,7 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Copy
   \[0x.*\]  Advance Line by 1 to 2
   \[0x.*\]  Advance PC by fixed size amount 0 to 0x0
-  \[0x.*\]  Copy
+  \[0x.*\]  Copy \(view 1\)
   \[0x.*\]  Advance Line by 1 to 3
   \[0x.*\]  Extended opcode 2: set Address to 0x.*
   \[0x.*\]  Copy
diff --git a/gas/testsuite/gas/lns/lns-duplicate.d b/gas/testsuite/gas/lns/lns-duplicate.d
index 9fe28ab..4bf44e0 100644
--- a/gas/testsuite/gas/lns/lns-duplicate.d
+++ b/gas/testsuite/gas/lns/lns-duplicate.d
@@ -6,5 +6,5 @@ Raw dump of debug contents of section \.z?debug_line:
   \[0x.*\]  Extended opcode 2: set Address to .*
   \[0x.*\]  Copy
   \[0x.*\]  Set basic block
-  \[0x.*\]  .* by 1 to 2
+  \[0x.*\]  .* by 1 to 2 \(view 1\)
 #pass
diff --git a/gas/testsuite/gas/mips/loc-swap-2.d b/gas/testsuite/gas/mips/loc-swap-2.d
index ed280a8..6176614 100644
--- a/gas/testsuite/gas/mips/loc-swap-2.d
+++ b/gas/testsuite/gas/mips/loc-swap-2.d
@@ -39,11 +39,11 @@ Raw dump of debug contents of section .debug_line:
  Line Number Statements:
   \[0x.*\]  Extended opcode 2: set Address to 0x0
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x0 and Line by 6 to 7
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 9
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 10
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 9 \(view 1\)
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 10 \(view 2\)
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x8 and Line by 3 to 13
   \[0x.*\]  Special opcode 62: advance Address by 4 to 0xc and Line by 1 to 14
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0xc and Line by 1 to 15
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0xc and Line by 1 to 15 \(view 1\)
   \[0x.*\]  Special opcode 119: advance Address by 8 to 0x14 and Line by 2 to 17
   \[0x.*\]  Advance PC by 4 to 0x18
   \[0x.*\]  Extended opcode 1: End of Sequence
diff --git a/gas/testsuite/gas/mips/loc-swap-3.d b/gas/testsuite/gas/mips/loc-swap-3.d
index 2e46e04..0610a44 100644
--- a/gas/testsuite/gas/mips/loc-swap-3.d
+++ b/gas/testsuite/gas/mips/loc-swap-3.d
@@ -12,6 +12,6 @@
 #   Set prologue_end to true
 # here
 #------------------------------------------------------------------------
-.*  Special opcode 6: advance Address by 0 to 0x[01] and Line by 1 to 2
+.*  Special opcode 6: advance Address by 0 to 0x[01] and Line by 1 to 2 \(view 1\)
 .*  Advance PC by .*
 .*  Extended opcode 1: End of Sequence
diff --git a/gas/testsuite/gas/mips/loc-swap.d b/gas/testsuite/gas/mips/loc-swap.d
index 4e11106..94fe7cd 100644
--- a/gas/testsuite/gas/mips/loc-swap.d
+++ b/gas/testsuite/gas/mips/loc-swap.d
@@ -44,9 +44,9 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x0 and Line by 6 to 7
   \[0x.*\]  Special opcode 63: advance Address by 4 to 0x4 and Line by 2 to 9
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0xc and Line by 3 to 12
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0xc and Line by 2 to 14
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0xc and Line by 2 to 14 \(view 1\)
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x14 and Line by 3 to 17
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x14 and Line by 2 to 19
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x14 and Line by 2 to 19 \(view 1\)
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x1c and Line by 3 to 22
   \[0x.*\]  Special opcode 63: advance Address by 4 to 0x20 and Line by 2 to 24
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x28 and Line by 3 to 27
@@ -54,7 +54,7 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x34 and Line by 3 to 32
   \[0x.*\]  Special opcode 63: advance Address by 4 to 0x38 and Line by 2 to 34
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x40 and Line by 3 to 37
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x40 and Line by 2 to 39
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x40 and Line by 2 to 39 \(view 1\)
   \[0x.*\]  Special opcode 120: advance Address by 8 to 0x48 and Line by 3 to 42
   \[0x.*\]  Special opcode 63: advance Address by 4 to 0x4c and Line by 2 to 44
   \[0x.*\]  Advance PC by 36 to 0x70
diff --git a/gas/testsuite/gas/mips/micromips@loc-swap-2.d b/gas/testsuite/gas/mips/micromips@loc-swap-2.d
index e148f25..9504be7 100644
--- a/gas/testsuite/gas/mips/micromips@loc-swap-2.d
+++ b/gas/testsuite/gas/mips/micromips@loc-swap-2.d
@@ -39,11 +39,11 @@ Raw dump of debug contents of section .debug_line:
  Line Number Statements:
   \[0x.*\]  Extended opcode 2: set Address to 0x1
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x1 and Line by 6 to 7
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x1 and Line by 2 to 9
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x1 and Line by 1 to 10
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x1 and Line by 2 to 9 \(view 1\)
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x1 and Line by 1 to 10 \(view 2\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x5 and Line by 3 to 13
   \[0x.*\]  Special opcode 34: advance Address by 2 to 0x7 and Line by 1 to 14
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x7 and Line by 1 to 15
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x7 and Line by 1 to 15 \(view 1\)
   \[0x.*\]  Special opcode 63: advance Address by 4 to 0xb and Line by 2 to 17
   \[0x.*\]  Advance PC by 1 to 0xc
   \[0x.*\]  Extended opcode 1: End of Sequence
diff --git a/gas/testsuite/gas/mips/micromips@loc-swap.d b/gas/testsuite/gas/mips/micromips@loc-swap.d
index 23aedae..1427fee 100644
--- a/gas/testsuite/gas/mips/micromips@loc-swap.d
+++ b/gas/testsuite/gas/mips/micromips@loc-swap.d
@@ -45,9 +45,9 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x1 and Line by 6 to 7
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x3 and Line by 2 to 9
   \[0x.*\]  Special opcode 36: advance Address by 2 to 0x5 and Line by 3 to 12
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x5 and Line by 2 to 14
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x5 and Line by 2 to 14 \(view 1\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x9 and Line by 3 to 17
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x9 and Line by 2 to 19
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x9 and Line by 2 to 19 \(view 1\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0xd and Line by 3 to 22
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0xf and Line by 2 to 24
   \[0x.*\]  Special opcode 36: advance Address by 2 to 0x11 and Line by 3 to 27
diff --git a/gas/testsuite/gas/mips/mips16@loc-swap-2.d b/gas/testsuite/gas/mips/mips16@loc-swap-2.d
index 95b9e9c..a4cc000 100644
--- a/gas/testsuite/gas/mips/mips16@loc-swap-2.d
+++ b/gas/testsuite/gas/mips/mips16@loc-swap-2.d
@@ -39,11 +39,11 @@ Raw dump of debug contents of section .debug_line:
  Line Number Statements:
   \[0x.*\]  Extended opcode 2: set Address to 0x1
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x1 and Line by 6 to 7
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x1 and Line by 2 to 9
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x1 and Line by 1 to 10
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x1 and Line by 2 to 9 \(view 1\)
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x1 and Line by 1 to 10 \(view 2\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x5 and Line by 3 to 13
   \[0x.*\]  Special opcode 34: advance Address by 2 to 0x7 and Line by 1 to 14
-  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x7 and Line by 1 to 15
+  \[0x.*\]  Special opcode 6: advance Address by 0 to 0x7 and Line by 1 to 15 \(view 1\)
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x9 and Line by 2 to 17
   \[0x.*\]  Advance PC by 1 to 0xa
   \[0x.*\]  Extended opcode 1: End of Sequence
diff --git a/gas/testsuite/gas/mips/mips16@loc-swap.d b/gas/testsuite/gas/mips/mips16@loc-swap.d
index 4d0c781..9b02346 100644
--- a/gas/testsuite/gas/mips/mips16@loc-swap.d
+++ b/gas/testsuite/gas/mips/mips16@loc-swap.d
@@ -44,9 +44,9 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x1 and Line by 6 to 7
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x3 and Line by 2 to 9
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x7 and Line by 3 to 12
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x7 and Line by 2 to 14
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x7 and Line by 2 to 14 \(view 1\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0xb and Line by 3 to 17
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0xb and Line by 2 to 19
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0xb and Line by 2 to 19 \(view 1\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0xf and Line by 3 to 22
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x11 and Line by 2 to 24
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x15 and Line by 3 to 27
@@ -54,7 +54,7 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x1b and Line by 3 to 32
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x1d and Line by 2 to 34
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x21 and Line by 3 to 37
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x21 and Line by 2 to 39
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x21 and Line by 2 to 39 \(view 1\)
   \[0x.*\]  Special opcode 92: advance Address by 6 to 0x27 and Line by 3 to 42
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x29 and Line by 2 to 44
   \[0x.*\]  Advance PC by 23 to 0x40
diff --git a/gas/testsuite/gas/mips/mips16e@loc-swap.d b/gas/testsuite/gas/mips/mips16e@loc-swap.d
index 412e45b..7356e3f 100644
--- a/gas/testsuite/gas/mips/mips16e@loc-swap.d
+++ b/gas/testsuite/gas/mips/mips16e@loc-swap.d
@@ -44,9 +44,9 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 11: advance Address by 0 to 0x1 and Line by 6 to 7
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x3 and Line by 2 to 9
   \[0x.*\]  Special opcode 36: advance Address by 2 to 0x5 and Line by 3 to 12
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x5 and Line by 2 to 14
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x5 and Line by 2 to 14 \(view 1\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0x9 and Line by 3 to 17
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x9 and Line by 2 to 19
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x9 and Line by 2 to 19 \(view 1\)
   \[0x.*\]  Special opcode 64: advance Address by 4 to 0xd and Line by 3 to 22
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0xf and Line by 2 to 24
   \[0x.*\]  Special opcode 36: advance Address by 2 to 0x11 and Line by 3 to 27
@@ -54,7 +54,7 @@ Raw dump of debug contents of section \.debug_line:
   \[0x.*\]  Special opcode 36: advance Address by 2 to 0x15 and Line by 3 to 32
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x17 and Line by 2 to 34
   \[0x.*\]  Special opcode 36: advance Address by 2 to 0x19 and Line by 3 to 37
-  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x19 and Line by 2 to 39
+  \[0x.*\]  Special opcode 7: advance Address by 0 to 0x19 and Line by 2 to 39 \(view 1\)
   \[0x.*\]  Special opcode 92: advance Address by 6 to 0x1f and Line by 3 to 42
   \[0x.*\]  Special opcode 35: advance Address by 2 to 0x21 and Line by 2 to 44
   \[0x.*\]  Advance PC by 31 to 0x40
diff --git a/gas/write.c b/gas/write.c
index 1242cbf..8efdbc5 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -465,6 +465,13 @@ cvt_frag_to_fill (segT sec ATTRIBUTE_UNUSED, fragS *fragP)
 	valueT value = S_GET_VALUE (fragP->fr_symbol);
 	int size;
 
+	if (!S_IS_DEFINED (fragP->fr_symbol))
+	  {
+	    as_bad_where (fragP->fr_file, fragP->fr_line,
+			  _("leb128 operand is an undefined symbol: %s"),
+			  S_GET_NAME (fragP->fr_symbol));
+	  }
+
 	size = output_leb128 (fragP->fr_literal + fragP->fr_fix, value,
 			      fragP->fr_subtype);
 
@@ -1904,6 +1911,8 @@ write_object_file (void)
   /* Relaxation has completed.  Freeze all syms.  */
   finalize_syms = 1;
 
+  dwarf2dbg_final_check ();
+
 #ifdef md_post_relax_hook
   md_post_relax_hook;
 #endif


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]