aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2020-07-02 11:30:52 +0100
committerNick Clifton <nickc@redhat.com>2020-07-02 11:30:52 +0100
commit0942c7ab94e554657c3e11ab85ae7f15373ee80d (patch)
treeb9a60c0257ad7aa26fe5985f5ae279db2e4528cd
parent1cdf9e33eadd3bf091fe64ed30daa0263f736ea2 (diff)
downloadfsf-binutils-gdb-0942c7ab94e554657c3e11ab85ae7f15373ee80d.zip
fsf-binutils-gdb-0942c7ab94e554657c3e11ab85ae7f15373ee80d.tar.gz
fsf-binutils-gdb-0942c7ab94e554657c3e11ab85ae7f15373ee80d.tar.bz2
Change readelf's display of symbol names (when not in --wide mode) so that if they are going to be truncated then "[...]" is displayed at the end. Add a comment line option to disable this enhancement and restore the old behaviour.
PR 26028 binutils* readelf.c (print_symbol): Handle truncation of symbol names. (options): Add -T/--silent-truncation option. (parse_args): Handle the option. (print_dynamic_symbol): Correct calculation of width available to display symbol name. * doc/binutils.texi: Document the -T option to readelf. * NEWS: Mention the new feature. gas * testsuite/gas/ia64/group-2.d: Add -T option to readelf command line. * testsuite/gas/ia64/unwind.d: Likewise. * testsuite/gas/mmix/bspec-1.d: Likewise. * testsuite/gas/mmix/bspec-2.d: Likewise. * testsuite/gas/mmix/comment-1.d: Likewise. * testsuite/gas/tic6x/scomm-directive-4.d: Likewise. ld * testsuite/ld-powerpc/powerpc.exp: Add -T option to readelf command line when running some tests. * testsuite/ld-arm/arm-elf.exp: Likewise. * testsuite/ld-mips-elf/mips-elf.exp: Likewise. * testsuite/ld-mmix/local1.d: Likewise. * testsuite/ld-mmix/local3.d: Likewise. * testsuite/ld-mmix/local5.d: Likewise. * testsuite/ld-mmix/local7.d: Likewise. * testsuite/ld-powerpc/powerpc.exp: Likewise.
-rw-r--r--binutils/ChangeLog11
-rw-r--r--binutils/NEWS6
-rw-r--r--binutils/doc/binutils.texi10
-rw-r--r--binutils/readelf.c54
-rw-r--r--gas/ChangeLog11
-rw-r--r--gas/testsuite/gas/ia64/group-2.d2
-rw-r--r--gas/testsuite/gas/ia64/unwind.d2
-rw-r--r--gas/testsuite/gas/mmix/bspec-1.d2
-rw-r--r--gas/testsuite/gas/mmix/bspec-2.d2
-rw-r--r--gas/testsuite/gas/mmix/comment-1.d2
-rw-r--r--gas/testsuite/gas/tic6x/scomm-directive-4.d2
-rw-r--r--ld/ChangeLog13
-rw-r--r--ld/testsuite/ld-arm/arm-elf.exp6
-rw-r--r--ld/testsuite/ld-mips-elf/mips-elf.exp4
-rw-r--r--ld/testsuite/ld-mmix/local1.d2
-rw-r--r--ld/testsuite/ld-mmix/local3.d2
-rw-r--r--ld/testsuite/ld-mmix/local5.d2
-rw-r--r--ld/testsuite/ld-mmix/local7.d2
-rw-r--r--ld/testsuite/ld-powerpc/powerpc.exp6
19 files changed, 116 insertions, 25 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index c37e6f7..fee8c1d 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,14 @@
+2020-07-02 Nick Clifton <nickc@redhat.com>
+
+ PR 26028
+ * readelf.c (print_symbol): Handle truncation of symbol names.
+ (options): Add -T/--silent-truncation option.
+ (parse_args): Handle the option.
+ (print_dynamic_symbol): Correct calculation of width available to
+ display symbol name.
+ * doc/binutils.texi: Document the -T option to readelf.
+ * NEWS: Mention the new feature.
+
2020-06-30 H.J. Lu <hongjiu.lu@intel.com>
* NEWS: Mention x86 NaCl target support removal.
diff --git a/binutils/NEWS b/binutils/NEWS
index b0cc156..1da8a86 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,11 @@
-*- text -*-
+* Changed readelf's display of symbol names when wide mode is not enabled.
+ If the name is too long it will be truncated and the last five characters
+ replaced with "[...]". The old behaviour of displaying 5 more characters but
+ not indicating that truncation has happened can be restored by the use of the
+ -T or --silent-truncation options.
+
* X86 NaCl target support is removed.
* The readelf tool now has a -L or --lint or --enable-checks option which turns
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index b93cde0..f198626 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -4726,6 +4726,7 @@ readelf [@option{-a}|@option{--all}]
[@option{-I}|@option{--histogram}]
[@option{-v}|@option{--version}]
[@option{-W}|@option{--wide}]
+ [@option{-T}|@option{--silent-truncation}]
[@option{-H}|@option{--help}]
@var{elffile}@dots{}
@c man end
@@ -4939,6 +4940,15 @@ Don't break output lines to fit into 80 columns. By default
@command{readelf} to print each section header resp. each segment one a
single line, which is far more readable on terminals wider than 80 columns.
+@item -T
+@itemx --silent-truncation
+Normally when readelf is displaying a symbol name, and it has to
+truncate the name to fit into an 80 column display, it will add a
+suffix of @code{[...]} to the name. This command line option
+disables this behaviour, allowing 5 more characters of the name to be
+displayed and restoring the old behaviour of readelf (prior to release
+2.35).
+
@item -H
@itemx --help
Display the command-line options understood by @command{readelf}.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 1d7cfbc..6057515 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -234,6 +234,7 @@ static bfd_boolean do_archive_index = FALSE;
static bfd_boolean check_all = FALSE;
static bfd_boolean is_32bit_elf = FALSE;
static bfd_boolean decompress_dumps = FALSE;
+static bfd_boolean do_not_show_symbol_truncation = FALSE;
static char *dump_ctf_parent_name;
static char *dump_ctf_symtab_name;
@@ -533,15 +534,19 @@ print_vma (bfd_vma vma, print_mode mode)
Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
+ If truncation will happen and do_not_show_symbol_truncation is FALSE then display
+ abs(WIDTH) - 5 characters followed by "[...]".
+
If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
padding as necessary.
Returns the number of emitted characters. */
static unsigned int
-print_symbol (signed int width, const char *symbol)
+print_symbol (signed int width, const char * symbol)
{
bfd_boolean extra_padding = FALSE;
+ bfd_boolean do_dots = FALSE;
signed int num_printed = 0;
#ifdef HAVE_MBSTATE_T
mbstate_t state;
@@ -562,7 +567,17 @@ print_symbol (signed int width, const char *symbol)
This simplifies the code below. */
width_remaining = INT_MAX;
else
- width_remaining = width;
+ {
+ width_remaining = width;
+ if (! do_not_show_symbol_truncation
+ && (int) strlen (symbol) > width)
+ {
+ width_remaining -= 5;
+ if ((int) width_remaining < 0)
+ width_remaining = 0;
+ do_dots = TRUE;
+ }
+ }
#ifdef HAVE_MBSTATE_T
/* Initialise the multibyte conversion state. */
@@ -618,6 +633,9 @@ print_symbol (signed int width, const char *symbol)
}
}
+ if (do_dots)
+ num_printed += printf ("[...]");
+
if (extra_padding && num_printed < width)
{
/* Fill in the remaining spaces. */
@@ -4512,6 +4530,7 @@ static struct option options[] =
{"version", no_argument, 0, 'v'},
{"wide", no_argument, 0, 'W'},
+ {"silent-truncation",no_argument, 0, 'T'},
{"help", no_argument, 0, 'H'},
{0, no_argument, 0, 0}
};
@@ -4579,6 +4598,7 @@ usage (FILE * stream)
fprintf (stream, _("\
-I --histogram Display histogram of bucket list lengths\n\
-W --wide Allow output width to exceed 80 characters\n\
+ -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\
@<file> Read options from <file>\n\
-H --help Display this information\n\
-v --version Display the version number of readelf\n"));
@@ -4673,7 +4693,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
usage (stderr);
while ((c = getopt_long
- (argc, argv, "ADHILNR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
+ (argc, argv, "ADHILNR:STVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
{
switch (c)
{
@@ -4832,6 +4852,9 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
case 'W':
do_wide = TRUE;
break;
+ case 'T':
+ do_not_show_symbol_truncation = TRUE;
+ break;
default:
/* xgettext:c-format */
error (_("Invalid option '-%c'\n"), c);
@@ -12032,7 +12055,7 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si,
enum versioned_symbol_info sym_info;
unsigned short vna_other;
Elf_Internal_Sym *psym = symtab + si;
-
+
printf ("%6ld: ", si);
print_vma (psym->st_value, LONG_HEX);
putchar (' ');
@@ -12053,9 +12076,10 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si,
printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
}
printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
- print_symbol (25, VALID_SYMBOL_NAME (strtab, strtab_size,
- psym->st_name)
- ? strtab + psym->st_name : _("<corrupt>"));
+
+ bfd_boolean is_valid = VALID_SYMBOL_NAME (strtab, strtab_size,
+ psym->st_name);
+ const char * sstr = is_valid ? strtab + psym->st_name : _("<corrupt>");
version_string
= get_symbol_version_string (filedata,
@@ -12063,6 +12087,22 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si,
|| section->sh_type == SHT_DYNSYM),
strtab, strtab_size, si,
psym, &sym_info, &vna_other);
+
+ int len_avail = 21;
+ if (! do_wide && version_string != NULL)
+ {
+ char buffer[256];
+
+ len_avail -= sprintf (buffer, "@%s", version_string);
+
+ if (sym_info == symbol_undefined)
+ len_avail -= sprintf (buffer," (%d)", vna_other);
+ else if (sym_info != symbol_hidden)
+ len_avail -= 1;
+ }
+
+ print_symbol (len_avail, sstr);
+
if (version_string)
{
if (sym_info == symbol_undefined)
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 88c5451..864c6cd 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,14 @@
+2020-07-02 Nick Clifton <nickc@redhat.com>
+
+ PR 26028
+ * testsuite/gas/ia64/group-2.d: Add -T option to readelf
+ command line.
+ * testsuite/gas/ia64/unwind.d: Likewise.
+ * testsuite/gas/mmix/bspec-1.d: Likewise.
+ * testsuite/gas/mmix/bspec-2.d: Likewise.
+ * testsuite/gas/mmix/comment-1.d: Likewise.
+ * testsuite/gas/tic6x/scomm-directive-4.d: Likewise.
+
2020-07-01 Alan Modra <amodra@gmail.com>
* config/tc-xc16x.c (md_apply_fix): Add FIXME.
diff --git a/gas/testsuite/gas/ia64/group-2.d b/gas/testsuite/gas/ia64/group-2.d
index fca5415c..52a313a 100644
--- a/gas/testsuite/gas/ia64/group-2.d
+++ b/gas/testsuite/gas/ia64/group-2.d
@@ -1,4 +1,4 @@
-#readelf: -Sg
+#readelf: -Sg -T
#as: -x
#name: ia64 unwind group
diff --git a/gas/testsuite/gas/ia64/unwind.d b/gas/testsuite/gas/ia64/unwind.d
index bdb7af8..3f0d2d3 100644
--- a/gas/testsuite/gas/ia64/unwind.d
+++ b/gas/testsuite/gas/ia64/unwind.d
@@ -1,4 +1,4 @@
-#readelf: -S
+#readelf: -S -T
#name: ia64 unwind section
There are 9 section headers, starting at offset .*:
diff --git a/gas/testsuite/gas/mmix/bspec-1.d b/gas/testsuite/gas/mmix/bspec-1.d
index ab2e155..2a9a59b 100644
--- a/gas/testsuite/gas/mmix/bspec-1.d
+++ b/gas/testsuite/gas/mmix/bspec-1.d
@@ -1,4 +1,4 @@
-#readelf: -Ssr -x1 -x4
+#readelf: -Ssr -T -x1 -x4
There are 9 section headers, starting at offset .*:
#...
+\[ 4\] \.MMIX\.spec_data\.2 +PROGBITS +0+ +0+44
diff --git a/gas/testsuite/gas/mmix/bspec-2.d b/gas/testsuite/gas/mmix/bspec-2.d
index 4841229..2ade9b6 100644
--- a/gas/testsuite/gas/mmix/bspec-2.d
+++ b/gas/testsuite/gas/mmix/bspec-2.d
@@ -1,4 +1,4 @@
-#readelf: -Sr -x1 -x4
+#readelf: -Sr -T -x1 -x4
There are 11 section headers, starting at offset .*:
#...
\[ 4\] \.MMIX\.spec_data\.2 PROGBITS 0+ 0+48
diff --git a/gas/testsuite/gas/mmix/comment-1.d b/gas/testsuite/gas/mmix/comment-1.d
index 82559fe..569af60 100644
--- a/gas/testsuite/gas/mmix/comment-1.d
+++ b/gas/testsuite/gas/mmix/comment-1.d
@@ -1,5 +1,5 @@
#as: -no-expand
-#readelf: -Ssrx1 -x6
+#readelf: -Ssrx1 -T -x6
There are 10 section headers, starting at offset 0x...:
#...
+\[ 5\] \.MMIX\.spec_data\.4 +PROGBITS +0+ +0+c4
diff --git a/gas/testsuite/gas/tic6x/scomm-directive-4.d b/gas/testsuite/gas/tic6x/scomm-directive-4.d
index 219673d..26255ab 100644
--- a/gas/testsuite/gas/tic6x/scomm-directive-4.d
+++ b/gas/testsuite/gas/tic6x/scomm-directive-4.d
@@ -1,7 +1,7 @@
#name: C6X .scomm directive 4
#as:
#source: scomm-directive-4.s
-#readelf: -Ss
+#readelf: -Ss -T
There are 8 section headers, starting at offset .*:
diff --git a/ld/ChangeLog b/ld/ChangeLog
index f7c6fb0..156bcba 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,16 @@
+2020-07-02 Nick Clifton <nickc@redhat.com>
+
+ PR 26028
+ * testsuite/ld-powerpc/powerpc.exp: Add -T option to readelf
+ command line when running some tests.
+ * testsuite/ld-arm/arm-elf.exp: Likewise.
+ * testsuite/ld-mips-elf/mips-elf.exp: Likewise.
+ * testsuite/ld-mmix/local1.d: Likewise.
+ * testsuite/ld-mmix/local3.d: Likewise.
+ * testsuite/ld-mmix/local5.d: Likewise.
+ * testsuite/ld-mmix/local7.d: Likewise.
+ * testsuite/ld-powerpc/powerpc.exp: Likewise.
+
2020-06-30 H.J. Lu <hongjiu.lu@intel.com>
* Makefile.am (ALL_EMULATION_SOURCES): Remove eelf_i386_nacl.c,
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index 0bd4cca..1289317 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -794,7 +794,7 @@ set armeabitests_nonacl {
"--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-implib.lib --cmse-implib" ""
"-march=armv8-m.base -mthumb --defsym VER=1"
{cmse-implib.s}
- {{readelf {-s tmpdir/cmse-implib.lib} cmse-implib.rd}
+ {{readelf {-s --wide tmpdir/cmse-implib.lib} cmse-implib.rd}
{readelf {-h tmpdir/cmse-implib.lib} cmse-implib.type}}
"cmse-implib"}
{"Input secure gateway import library"
@@ -802,7 +802,7 @@ set armeabitests_nonacl {
"-march=armv8-m.base -mthumb --defsym VER=2"
{cmse-implib.s}
{{ld cmse-new-implib.out}
- {readelf {-s tmpdir/cmse-new-implib.lib} cmse-new-implib.rd}}
+ {readelf {-s --wide tmpdir/cmse-new-implib.lib} cmse-new-implib.rd}}
"cmse-new-implib"}
{"Input secure gateway import library: no output import library"
"--section-start .gnu.sgstubs=0x20000 --in-implib=tmpdir/cmse-implib.lib --cmse-implib" ""
@@ -832,7 +832,7 @@ set armeabitests_nonacl {
"--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-new-comeback-implib.lib --in-implib=tmpdir/cmse-implib.lib --cmse-implib" ""
"-march=armv8-m.base -mthumb --defsym VER=3"
{cmse-implib.s}
- {{readelf {-s tmpdir/cmse-new-comeback-implib.lib} cmse-new-comeback-implib.rd}}
+ {{readelf {-s --wide tmpdir/cmse-new-comeback-implib.lib} cmse-new-comeback-implib.rd}}
"cmse-new-comeback-implib"}
{"Input secure gateway import library: entry function change"
"--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-new-wrong-implib.lib --in-implib=tmpdir/cmse-implib.lib --cmse-implib" ""
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index 3d62051..e98429c 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -29,7 +29,7 @@ if {[istarget "mips*-*-vxworks"]} {
{"VxWorks executable test 1 (dynamic)" \
"tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic" ""
"-mips2" {vxworks1.s}
- {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
+ {{readelf {--relocs -T} vxworks1.rd} {objdump -dr vxworks1.dd}}
"vxworks1"}
{"VxWorks executable test 2 (dynamic)" \
"-Tvxworks1.ld -q --force-dynamic" ""
@@ -1575,7 +1575,7 @@ proc run_mips_undefweak_test { name abi args } {
[list \
[list objdump -d pr21375${objsuf}.dd] \
[list readelf -A pr21375${rdesuf}.gd] \
- [list readelf --dyn-syms pr21375${rdesuf}${irixsuf}.sd] \
+ [list readelf {--dyn-syms --wide} pr21375${rdesuf}${irixsuf}.sd] \
[list readelf -h pr21375${abisuf}.hd]] \
"pr21375${binsuf}${dsosuf}"]]
}
diff --git a/ld/testsuite/ld-mmix/local1.d b/ld/testsuite/ld-mmix/local1.d
index 41a67c2..7519ea1 100644
--- a/ld/testsuite/ld-mmix/local1.d
+++ b/ld/testsuite/ld-mmix/local1.d
@@ -4,7 +4,7 @@
#source: regext1.s
#source: start.s
#ld: -m elf64mmix
-#readelf: -Ssx1 -x2
+#readelf: -Ssx1 -T -x2
# We check that the externally visible symbol ext1 is a local register
# (different meaning of "local" than for symbol), which can be seen as
diff --git a/ld/testsuite/ld-mmix/local3.d b/ld/testsuite/ld-mmix/local3.d
index 74840d3..e5d5893 100644
--- a/ld/testsuite/ld-mmix/local3.d
+++ b/ld/testsuite/ld-mmix/local3.d
@@ -4,7 +4,7 @@
#source: ext1.s
#source: start.s
#ld: -m elf64mmix
-#readelf: -Ssx1 -x2
+#readelf: -Ssx1 -T -x2
# Like local1, but ext1 is here a constant, not a global register.
diff --git a/ld/testsuite/ld-mmix/local5.d b/ld/testsuite/ld-mmix/local5.d
index ae81364..2dccb2e 100644
--- a/ld/testsuite/ld-mmix/local5.d
+++ b/ld/testsuite/ld-mmix/local5.d
@@ -5,7 +5,7 @@
#source: regext1.s
#source: start.s
#ld: -m elf64mmix
-#readelf: -Ssx1 -x2
+#readelf: -Ssx1 -T -x2
# Like local1, but with two checks for a local register.
diff --git a/ld/testsuite/ld-mmix/local7.d b/ld/testsuite/ld-mmix/local7.d
index 6d80cc9..5754c34 100644
--- a/ld/testsuite/ld-mmix/local7.d
+++ b/ld/testsuite/ld-mmix/local7.d
@@ -5,7 +5,7 @@
#source: ext1.s
#source: start.s
#ld: -m elf64mmix
-#readelf: -Ssx1 -x2
+#readelf: -Ssx1 -T -x2
# Like local1, but ext1 is here a constant, not a global register and two
# local-register checks.
diff --git a/ld/testsuite/ld-powerpc/powerpc.exp b/ld/testsuite/ld-powerpc/powerpc.exp
index 1297871..3e458e4 100644
--- a/ld/testsuite/ld-powerpc/powerpc.exp
+++ b/ld/testsuite/ld-powerpc/powerpc.exp
@@ -32,13 +32,13 @@ if {[istarget "*-*-vxworks"]} {
{"VxWorks shared library test 1"
"-shared --hash-style=sysv -Tvxworks1.ld" ""
"-mregnames" {vxworks1-lib.s}
- {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
+ {{readelf {--relocs -T} vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
{readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
"libvxworks1.so"}
{"VxWorks executable test 1 (dynamic)" \
"tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic --hash-style=sysv" ""
"-mregnames" {vxworks1.s}
- {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
+ {{readelf {--relocs -T} vxworks1.rd} {objdump -dr vxworks1.dd}}
"vxworks1"}
{"VxWorks executable test 2 (dynamic)" \
"-Tvxworks1.ld -q --force-dynamic --hash-style=sysv" ""
@@ -58,7 +58,7 @@ if {[istarget "*-*-vxworks"]} {
{"VxWorks relocatable relax test"
"-Tvxworks1.ld -r --relax -q --hash-style=sysv" ""
"-mregnames" {vxworks-relax-2.s}
- {{readelf --relocs vxworks-relax-2.rd}}
+ {{readelf {--relocs -T} vxworks-relax-2.rd}}
"vxworks-relax-2"}
}
run_ld_link_tests $ppcvxtests