This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 06/19 REVIEW] binutils: readelf: when dumping CTF, load strtab and symtab automatically
- From: Nick Alcock <nick dot alcock at oracle dot com>
- To: binutils at sourceware dot org
- Cc: elena dot zannoni at oracle dot com, jose dot marchesi at oracle dot com, indu dot bhagat at oracle dot com, egeyar dot bagcioglu at oracle dot com
- Date: Tue, 16 Jul 2019 19:04:07 +0100
- Subject: [PATCH 06/19 REVIEW] binutils: readelf: when dumping CTF, load strtab and symtab automatically
- References: <20190716180420.236506-1-nick.alcock@oracle.com>
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/doc/binutils.texi | 3 ++-
binutils/readelf.c | 10 ++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
Technically needs review because it's not in libctf.
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index f3c4eaea4f..8e531b2306 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -4830,7 +4830,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.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index ea35aeef5c..044fd80186 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -13884,7 +13884,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)
{
@@ -13899,7 +13905,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)
{
--
2.22.0.238.g049a27acdc