xtensa: fix gas segfault with --text-section-literals
authorMax Filippov <jcmvbkbc@gmail.com>
Sun, 17 May 2015 03:46:15 +0000 (06:46 +0300)
committerMax Filippov <jcmvbkbc@gmail.com>
Tue, 26 May 2015 07:14:17 +0000 (10:14 +0300)
When --text-section-literals is used and code in the .init or .fini
emits literal in the absence of .literal_position, xtensa_move_literals
segfaults.

Check that search_frag is non-NULL in the xtensa_move_literals and
report error otherwise.

2015-05-26  Max Filippov  <jcmvbkbc@gmail.com>
gas/
* config/tc-xtensa.c (xtensa_move_literals): Check that
search_frag is non-NULL. Report error if literal frag is not
found.

gas/ChangeLog
gas/config/tc-xtensa.c

index f3a30d2624b64803a2e4b421bb769ec50f2386d2..a0ab897f947777aae4bb3ff4ac218fb536636d19 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-26  Max Filippov  <jcmvbkbc@gmail.com>
+
+       * config/tc-xtensa.c (xtensa_move_literals): Check that
+       search_frag is non-NULL. Report error if literal frag is not
+       found.
+
 2015-05-22  Nick Clifton  <nickc@redhat.com>
 
        PR gas/18446
index 31c0b6be7eea1d0d80289e843244418a4cf475f8..18307c1b52a578984d7738cc39e6097a32eabfd3 100644 (file)
@@ -10808,13 +10808,21 @@ xtensa_move_literals (void)
       frchain_to = NULL;
       frag_splice = &(frchain_from->frch_root);
 
-      while (!search_frag->tc_frag_data.literal_frag)
+      while (search_frag && !search_frag->tc_frag_data.literal_frag)
        {
          gas_assert (search_frag->fr_fix == 0
                  || search_frag->fr_type == rs_align);
          search_frag = search_frag->fr_next;
        }
 
+      if (!search_frag)
+       {
+         search_frag = frchain_from->frch_root;
+         as_bad_where (search_frag->fr_file, search_frag->fr_line,
+                       _("literal pool location required for text-section-literals; specify with .literal_position"));
+         continue;
+       }
+
       gas_assert (search_frag->tc_frag_data.literal_frag->fr_subtype
              == RELAX_LITERAL_POOL_BEGIN);
       xtensa_switch_section_emit_state (&state, segment->seg, 0);