Stop Gas from generating line info or address ranges for sections that do not contain...
authorNick Clifton <nickc@redhat.com>
Thu, 12 Nov 2020 11:43:20 +0000 (11:43 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 12 Nov 2020 11:43:20 +0000 (11:43 +0000)
PR 26850
* dwarf2dbg.c (dwarf2_gen_line_info_1): Do not record lines in
sections that are not executable or not loadable.
(out_debug_line): Move warning message into dwarf2_gen_line_info_1.
* testsuite/gas/elf/dwarf2-20.s: New test.
* testsuite/gas/elf/dwarf2-20.d: New test driver.
* testsuite/gas/elf/elf.exp: Run the new test.
* testsuite/gas/elf/warn-2.s: Use the .nop directive.

gas/ChangeLog
gas/dwarf2dbg.c
gas/testsuite/gas/elf/dwarf2-20.d [new file with mode: 0644]
gas/testsuite/gas/elf/dwarf2-20.s [new file with mode: 0644]
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/warn-2.s

index 854e58362c334968ff7bef58964672e3ea42de9a..36258e83ddd3a962202012d8fe2c6625f15c6e46 100644 (file)
@@ -1,3 +1,12 @@
+2020-11-12  Nick Clifton  <nickc@redhat.com>
+
+       PR 26850
+       * dwarf2dbg.c
+       * testsuite/gas/elf/dwarf2-20.s: New test.
+       * testsuite/gas/elf/dwarf2-20.d: New test driver.
+       * testsuite/gas/elf/elf.exp: Run the new test.
+       * testsuite/gas/elf/warn-2.s
+
 2020-11-11  Przemyslaw Wirkus  <przemyslaw.wirkus@arm.com>
 
        * testsuite/gas/aarch64/ls64.s: Update test.
index 4e03c637d765978ddf1dbea8238b5d949321bcce..25ebc94a8d2b4c51279290770f188bf0ae60be19 100644 (file)
@@ -504,6 +504,18 @@ dwarf2_gen_line_info_1 (symbolS *label, struct dwarf2_line_info *loc)
 {
   struct line_subseg *lss;
   struct line_entry *e;
+  flagword need_flags = SEC_ALLOC | SEC_LOAD | SEC_CODE;
+
+  /* PR 26850: Do not record LOCs in non-executable, non-allocated,
+     or non-loaded sections.  */
+  if ((now_seg->flags & need_flags) != need_flags)
+    {
+      if (! SEG_NORMAL (now_seg))
+       /* FIXME: Add code to suppress multiple warnings ?  */
+       as_warn ("dwarf line number information for %s ignored",
+                segment_name (now_seg));
+      return;
+    }
 
   e = XNEW (struct line_entry);
   e->next = NULL;
@@ -2341,11 +2353,10 @@ out_debug_line (segT line_seg)
 
   /* For each section, emit a statement program.  */
   for (s = all_segs; s; s = s->next)
+    /* Paranoia - this check should have already have
+       been handled in dwarf2_gen_line_info_1().  */
     if (SEG_NORMAL (s->seg))
       process_entries (s->seg, s->head->head);
-    else
-      as_warn ("dwarf line number information for %s ignored",
-              segment_name (s->seg));
 
   if (flag_dwarf_sections)
     /* We have to switch to the special .debug_line_end section
@@ -2740,7 +2751,6 @@ dwarf2_init (void)
     flag_dwarf_cie_version = 1;
 }
 
-
 /* Finish the dwarf2 debug sections.  We emit .debug.line if there
    were any .file/.loc directives, or --gdwarf2 was given, and if the
    file has a non-empty .debug_info section and an empty .debug_line
diff --git a/gas/testsuite/gas/elf/dwarf2-20.d b/gas/testsuite/gas/elf/dwarf2-20.d
new file mode 100644 (file)
index 0000000..363510a
--- /dev/null
@@ -0,0 +1,18 @@
+#as: -gdwarf-3
+#readelf: -wr
+#name: DWARF2_20: debug ranges ignore non-code sections
+# The mn10200 target has a pointer size of 3, but it does not use segment selectors.  This confuses DWARF and readelf will complain.
+#xfail: mn102*-*
+
+Contents of the .debug_aranges section:
+
+[      ]+Length:[      ]+(16|28|44)
+[      ]+Version:.*
+[      ]+Offset into .debug_info:[     ]+0x0
+[      ]+Pointer Size:[        ]+(2|4|8)
+[      ]+Segment Size:[        ]+0
+
+[      ]+Address[      ]+Length
+[      ]+0+000 0+00. 
+[      ]+0+000 0+000 
+#pass
diff --git a/gas/testsuite/gas/elf/dwarf2-20.s b/gas/testsuite/gas/elf/dwarf2-20.s
new file mode 100644 (file)
index 0000000..0ad0cc3
--- /dev/null
@@ -0,0 +1,10 @@
+       .section .alloc0,"a"
+       .nop
+       .section .alloc1,"a"
+       .nop
+       .section .nonalloc,""
+       .nop
+       .section .allocexec,"ax"
+       .nop
+       .section .nonallocexec,"x"
+       .nop
index 9d751544830b0f9f473cb37f786902fe4a315599..edacf27d9d8d6796fc27278eef49b125d61f8ec0 100644 (file)
@@ -282,6 +282,7 @@ if { [is_elf_format] } then {
     run_dump_test "dwarf2-17" $dump_opts
     run_dump_test "dwarf2-18" $dump_opts
     run_dump_test "dwarf2-19" $dump_opts
+    run_dump_test "dwarf2-20" $dump_opts
     run_dump_test "dwarf-5-file0" $dump_opts
     run_dump_test "dwarf-4-cu" $dump_opts
     run_dump_test "dwarf-5-cu" $dump_opts
index 79d6205c8071fe5a15db309ccd9ee9988208b3bf..8a128a197e5a5ac078a24367ffc2b1bc2147dc3e 100644 (file)
@@ -1,18 +1,7 @@
 ;# { dg-do assemble }
-;# { dg-options "--gdwarf2 --defsym nop_type=0" }
-;# { dg-options "--gdwarf2 --defsym nop_type=1" { target ia64-*-* } }
-;# { dg-options "--gdwarf2 --defsym nop_type=2" { target or1k*-*-* } }
+;# { dg-options "--gdwarf2" }
 
        .offset 40
-       
- .ifeq nop_type - 1
-       nop 0
- .else
- .ifeq nop_type - 2
-       l.nop 0
- .else
-       nop
- .endif
- .endif
+       .nop
 
 ;# { dg-warning "Warning: dwarf line number information for .* ignored" "" { xfail v850*-*-* } 0 }