]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: new functions for getting strings out of a strtab
authorNick Alcock <nick.alcock@oracle.com>
Sat, 13 Jul 2019 20:47:30 +0000 (21:47 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Mon, 23 Sep 2019 13:12:54 +0000 (14:12 +0100)
The CTF linking process wants to deduplicate the CTF strtab against the
ELF strtab, for which it needs to know the number of strings in the
strtab and it needs to be able to extract them one by one.

The BFD strtab functions only support returning the
size-or-section-length of the strtab (with _bfd_elf_strtab_size)
and returning the offset (but not string!) and decrementing the refcount
at the same time.

So add new functions _bfd_elf_strtab_len (that just returns the length
in strings of the strtab, never the section size) and bfd_elf_strtab_str
(which returns the string at a given strtab index, and its offset,
without touching the refcount).

It is probably a mistake to use _bfd_elf_strtab_str in particular before
_bfd_elf_strtab_finalize is called, and will not produce useful output
if you do so.

bfd/
* elf-strtab.c (_bfd_elf_strtab_len): New.
(_bfd_elf_strtab_str): Likewise.
* bfd-elf.h: Declare them.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf-strtab.c

index ea8f3b7b41cbcbc8ac23f59c8fb848de72129b39..05182ca38701157f284ba5bf2d02e3b2f36a7dc8 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
+
+       * elf-strtab.c (_bfd_elf_strtab_len): New.
+       (_bfd_elf_strtab_str): Likewise.
+       * bfd-elf.h: Declare them.
+
 2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
 
        * elf-bfd.h (bfd_elf_get_str_section): Add.
index a9e2d3eeaf14301b526b6a84a5ec516be46531f6..4240d97a429a9cec0ab08fd39410e75116835682 100644 (file)
@@ -2252,8 +2252,12 @@ extern void _bfd_elf_strtab_restore
   (struct elf_strtab_hash *, void *);
 extern bfd_size_type _bfd_elf_strtab_size
   (struct elf_strtab_hash *);
+extern bfd_size_type _bfd_elf_strtab_len
+  (struct elf_strtab_hash *);
 extern bfd_size_type _bfd_elf_strtab_offset
   (struct elf_strtab_hash *, size_t);
+extern const char * _bfd_elf_strtab_str
+  (struct elf_strtab_hash *, size_t idx, size_t *offset);
 extern bfd_boolean _bfd_elf_strtab_emit
   (bfd *, struct elf_strtab_hash *);
 extern void _bfd_elf_strtab_finalize
index ec9002fae7b26cec18eb92ab364a36bd9f22bca6..5d3eac7b40f2195f0fa76f35f8d08f1a611dbca6 100644 (file)
@@ -270,6 +270,12 @@ _bfd_elf_strtab_size (struct elf_strtab_hash *tab)
   return tab->sec_size ? tab->sec_size : tab->size;
 }
 
+bfd_size_type
+_bfd_elf_strtab_len (struct elf_strtab_hash *tab)
+{
+  return tab->size;
+}
+
 bfd_size_type
 _bfd_elf_strtab_offset (struct elf_strtab_hash *tab, size_t idx)
 {
@@ -285,6 +291,19 @@ _bfd_elf_strtab_offset (struct elf_strtab_hash *tab, size_t idx)
   return tab->array[idx]->u.index;
 }
 
+const char *
+_bfd_elf_strtab_str (struct elf_strtab_hash *tab, size_t idx,
+                     bfd_size_type *offset)
+{
+  if (idx == 0)
+    return 0;
+  BFD_ASSERT (idx < tab->size);
+  BFD_ASSERT (tab->sec_size);
+  if (offset)
+    *offset = tab->array[idx]->u.index;
+  return tab->array[idx]->root.string;
+}
+
 bfd_boolean
 _bfd_elf_strtab_emit (register bfd *abfd, struct elf_strtab_hash *tab)
 {