]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
binutils: readelf: when dumping CTF, load strtab and symtab automatically
authorNick Alcock <nick.alcock@oracle.com>
Sat, 13 Jul 2019 18:47:11 +0000 (19:47 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Mon, 23 Sep 2019 13:12:54 +0000 (14:12 +0100)
We were only loading them when explicitly requested, which leads to
strings that point off into empty space (into the non-loaded "external"
ELF string table).  Avoid this unfortunate consequence by loading the
strtab and symtab by default, unless a blank name is given.

binutils/
* readelf.c (dump_ctf_symtab_name): Give default value.
(dump_ctf_strtab_name): Likewise.
(dump_section_as_ctf): Allow for the null string.

binutils/ChangeLog
binutils/doc/binutils.texi
binutils/readelf.c

index f5d08fb7ff3c27b51d2e49df36d485ba83c6cdda..c15d7830a970998a9d9488c571623ec015801185 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
+
+       * readelf.c (dump_ctf_symtab_name): Give default value.
+       (dump_ctf_strtab_name): Likewise.
+       (dump_section_as_ctf): Allow for the null string.
+
 2019-07-08  Nick Alcock  <nick.alcock@oracle.com>
 
        * objdump.c (dump_ctf_archive_member): Dump the CTF header.
index bb37cb0988460001ea4858d88f3d95bbe098c1e6..a548180fd684923f3adc720f1c8e3cfb27cc8a47 100644 (file)
@@ -4850,7 +4850,8 @@ command to @command{ar}, but without using the BFD library.  @xref{ar}.
 @item --ctf-symbols=@var{section}
 @item --ctf-strings=@var{section}
 Specify the name of another section from which the CTF file can inherit
-strings and symbols.
+strings and symbols.  By default, the @code{.symtab} and its linked
+string table are used.
 
 If either of @option{--ctf-symbols} or @option{--ctf-strings} is specified, the
 other must be specified as well.
index 40957b01a8e3dca0e7665f9c448a07f51a132e1d..459706805c51e77da01ef4f4310066075e6780e6 100644 (file)
@@ -13944,7 +13944,13 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   data = get_section_contents (section, filedata);
   ctfsect.cts_data = data;
 
-  if (dump_ctf_symtab_name)
+  if (!dump_ctf_symtab_name)
+    dump_ctf_symtab_name = strdup (".symtab");
+
+  if (!dump_ctf_strtab_name)
+    dump_ctf_strtab_name = strdup (".strtab");
+
+  if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0)
     {
       if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL)
        {
@@ -13959,7 +13965,7 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
       symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
       symsect.cts_data = symdata;
     }
-  if (dump_ctf_strtab_name)
+  if (dump_ctf_strtab_name && dump_ctf_symtab_name[0] != 0)
     {
       if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
        {