Fix and test "checkpoint" in non-stop mode
[binutils-gdb.git] / bfd / elf-strtab.c
index 45743f608a2d8f9d2db1d63eb2ecae8583942f14..4d38e04e9caeac0060375819ba496f08832aa8ec 100644 (file)
@@ -1,6 +1,5 @@
 /* ELF strtab with GC and suffix merging support.
-   Copyright 2001, 2002, 2003, 2005, 2006, 2007, 2008
-   Free Software Foundation, Inc.
+   Copyright (C) 2001-2015 Free Software Foundation, Inc.
    Written by Jakub Jelinek <jakub@redhat.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -208,10 +207,32 @@ _bfd_elf_strtab_refcount (struct elf_strtab_hash *tab, bfd_size_type idx)
 }
 
 void
-_bfd_elf_strtab_clear_refs (struct elf_strtab_hash *tab, bfd_size_type idx)
+_bfd_elf_strtab_clear_all_refs (struct elf_strtab_hash *tab)
 {
-  while (idx < tab->size)
-    tab->array[idx++]->refcount = 0;
+  bfd_size_type idx;
+
+  for (idx = 1; idx < tab->size; idx++)
+    tab->array[idx]->refcount = 0;
+}
+
+/* Downsizes strtab.  Entries from IDX up to the current size are
+   removed from the array.  */
+void
+_bfd_elf_strtab_restore_size (struct elf_strtab_hash *tab, bfd_size_type idx)
+{
+  bfd_size_type curr_size = tab->size;
+
+  BFD_ASSERT (tab->sec_size == 0);
+  BFD_ASSERT (idx <= curr_size);
+  tab->size = idx;
+  for (; idx < curr_size; ++idx)
+    {
+      /* We don't remove entries from the hash table, just set their
+        REFCOUNT to zero.  Setting LEN zero will result in the size
+        growing if the entry is added again.  See _bfd_elf_strtab_add.  */
+      tab->array[idx]->refcount = 0;
+      tab->array[idx]->len = 0;
+    }
 }
 
 bfd_size_type