GNU Binutils with patches for OS216
修訂 | 0942c7ab94e554657c3e11ab85ae7f15373ee80d (tree) |
---|---|
時間 | 2020-07-02 19:30:52 |
作者 | Nick Clifton <nickc@redh...> |
Commiter | Nick Clifton |
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.
@@ -1,3 +1,14 @@ | ||
1 | +2020-07-02 Nick Clifton <nickc@redhat.com> | |
2 | + | |
3 | + PR 26028 | |
4 | + * readelf.c (print_symbol): Handle truncation of symbol names. | |
5 | + (options): Add -T/--silent-truncation option. | |
6 | + (parse_args): Handle the option. | |
7 | + (print_dynamic_symbol): Correct calculation of width available to | |
8 | + display symbol name. | |
9 | + * doc/binutils.texi: Document the -T option to readelf. | |
10 | + * NEWS: Mention the new feature. | |
11 | + | |
1 | 12 | 2020-06-30 H.J. Lu <hongjiu.lu@intel.com> |
2 | 13 | |
3 | 14 | * NEWS: Mention x86 NaCl target support removal. |
@@ -1,5 +1,11 @@ | ||
1 | 1 | -*- text -*- |
2 | 2 | |
3 | +* Changed readelf's display of symbol names when wide mode is not enabled. | |
4 | + If the name is too long it will be truncated and the last five characters | |
5 | + replaced with "[...]". The old behaviour of displaying 5 more characters but | |
6 | + not indicating that truncation has happened can be restored by the use of the | |
7 | + -T or --silent-truncation options. | |
8 | + | |
3 | 9 | * X86 NaCl target support is removed. |
4 | 10 | |
5 | 11 | * The readelf tool now has a -L or --lint or --enable-checks option which turns |
@@ -4726,6 +4726,7 @@ readelf [@option{-a}|@option{--all}] | ||
4726 | 4726 | [@option{-I}|@option{--histogram}] |
4727 | 4727 | [@option{-v}|@option{--version}] |
4728 | 4728 | [@option{-W}|@option{--wide}] |
4729 | + [@option{-T}|@option{--silent-truncation}] | |
4729 | 4730 | [@option{-H}|@option{--help}] |
4730 | 4731 | @var{elffile}@dots{} |
4731 | 4732 | @c man end |
@@ -4939,6 +4940,15 @@ Don't break output lines to fit into 80 columns. By default | ||
4939 | 4940 | @command{readelf} to print each section header resp. each segment one a |
4940 | 4941 | single line, which is far more readable on terminals wider than 80 columns. |
4941 | 4942 | |
4943 | +@item -T | |
4944 | +@itemx --silent-truncation | |
4945 | +Normally when readelf is displaying a symbol name, and it has to | |
4946 | +truncate the name to fit into an 80 column display, it will add a | |
4947 | +suffix of @code{[...]} to the name. This command line option | |
4948 | +disables this behaviour, allowing 5 more characters of the name to be | |
4949 | +displayed and restoring the old behaviour of readelf (prior to release | |
4950 | +2.35). | |
4951 | + | |
4942 | 4952 | @item -H |
4943 | 4953 | @itemx --help |
4944 | 4954 | Display the command-line options understood by @command{readelf}. |
@@ -234,6 +234,7 @@ static bfd_boolean do_archive_index = FALSE; | ||
234 | 234 | static bfd_boolean check_all = FALSE; |
235 | 235 | static bfd_boolean is_32bit_elf = FALSE; |
236 | 236 | static bfd_boolean decompress_dumps = FALSE; |
237 | +static bfd_boolean do_not_show_symbol_truncation = FALSE; | |
237 | 238 | |
238 | 239 | static char *dump_ctf_parent_name; |
239 | 240 | static char *dump_ctf_symtab_name; |
@@ -533,15 +534,19 @@ print_vma (bfd_vma vma, print_mode mode) | ||
533 | 534 | |
534 | 535 | Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true. |
535 | 536 | |
537 | + If truncation will happen and do_not_show_symbol_truncation is FALSE then display | |
538 | + abs(WIDTH) - 5 characters followed by "[...]". | |
539 | + | |
536 | 540 | If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, |
537 | 541 | padding as necessary. |
538 | 542 | |
539 | 543 | Returns the number of emitted characters. */ |
540 | 544 | |
541 | 545 | static unsigned int |
542 | -print_symbol (signed int width, const char *symbol) | |
546 | +print_symbol (signed int width, const char * symbol) | |
543 | 547 | { |
544 | 548 | bfd_boolean extra_padding = FALSE; |
549 | + bfd_boolean do_dots = FALSE; | |
545 | 550 | signed int num_printed = 0; |
546 | 551 | #ifdef HAVE_MBSTATE_T |
547 | 552 | mbstate_t state; |
@@ -562,7 +567,17 @@ print_symbol (signed int width, const char *symbol) | ||
562 | 567 | This simplifies the code below. */ |
563 | 568 | width_remaining = INT_MAX; |
564 | 569 | else |
565 | - width_remaining = width; | |
570 | + { | |
571 | + width_remaining = width; | |
572 | + if (! do_not_show_symbol_truncation | |
573 | + && (int) strlen (symbol) > width) | |
574 | + { | |
575 | + width_remaining -= 5; | |
576 | + if ((int) width_remaining < 0) | |
577 | + width_remaining = 0; | |
578 | + do_dots = TRUE; | |
579 | + } | |
580 | + } | |
566 | 581 | |
567 | 582 | #ifdef HAVE_MBSTATE_T |
568 | 583 | /* Initialise the multibyte conversion state. */ |
@@ -618,6 +633,9 @@ print_symbol (signed int width, const char *symbol) | ||
618 | 633 | } |
619 | 634 | } |
620 | 635 | |
636 | + if (do_dots) | |
637 | + num_printed += printf ("[...]"); | |
638 | + | |
621 | 639 | if (extra_padding && num_printed < width) |
622 | 640 | { |
623 | 641 | /* Fill in the remaining spaces. */ |
@@ -4512,6 +4530,7 @@ static struct option options[] = | ||
4512 | 4530 | |
4513 | 4531 | {"version", no_argument, 0, 'v'}, |
4514 | 4532 | {"wide", no_argument, 0, 'W'}, |
4533 | + {"silent-truncation",no_argument, 0, 'T'}, | |
4515 | 4534 | {"help", no_argument, 0, 'H'}, |
4516 | 4535 | {0, no_argument, 0, 0} |
4517 | 4536 | }; |
@@ -4579,6 +4598,7 @@ usage (FILE * stream) | ||
4579 | 4598 | fprintf (stream, _("\ |
4580 | 4599 | -I --histogram Display histogram of bucket list lengths\n\ |
4581 | 4600 | -W --wide Allow output width to exceed 80 characters\n\ |
4601 | + -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\ | |
4582 | 4602 | @<file> Read options from <file>\n\ |
4583 | 4603 | -H --help Display this information\n\ |
4584 | 4604 | -v --version Display the version number of readelf\n")); |
@@ -4673,7 +4693,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv) | ||
4673 | 4693 | usage (stderr); |
4674 | 4694 | |
4675 | 4695 | while ((c = getopt_long |
4676 | - (argc, argv, "ADHILNR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF) | |
4696 | + (argc, argv, "ADHILNR:STVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF) | |
4677 | 4697 | { |
4678 | 4698 | switch (c) |
4679 | 4699 | { |
@@ -4832,6 +4852,9 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv) | ||
4832 | 4852 | case 'W': |
4833 | 4853 | do_wide = TRUE; |
4834 | 4854 | break; |
4855 | + case 'T': | |
4856 | + do_not_show_symbol_truncation = TRUE; | |
4857 | + break; | |
4835 | 4858 | default: |
4836 | 4859 | /* xgettext:c-format */ |
4837 | 4860 | error (_("Invalid option '-%c'\n"), c); |
@@ -12032,7 +12055,7 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si, | ||
12032 | 12055 | enum versioned_symbol_info sym_info; |
12033 | 12056 | unsigned short vna_other; |
12034 | 12057 | Elf_Internal_Sym *psym = symtab + si; |
12035 | - | |
12058 | + | |
12036 | 12059 | printf ("%6ld: ", si); |
12037 | 12060 | print_vma (psym->st_value, LONG_HEX); |
12038 | 12061 | putchar (' '); |
@@ -12053,9 +12076,10 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si, | ||
12053 | 12076 | printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); |
12054 | 12077 | } |
12055 | 12078 | printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx)); |
12056 | - print_symbol (25, VALID_SYMBOL_NAME (strtab, strtab_size, | |
12057 | - psym->st_name) | |
12058 | - ? strtab + psym->st_name : _("<corrupt>")); | |
12079 | + | |
12080 | + bfd_boolean is_valid = VALID_SYMBOL_NAME (strtab, strtab_size, | |
12081 | + psym->st_name); | |
12082 | + const char * sstr = is_valid ? strtab + psym->st_name : _("<corrupt>"); | |
12059 | 12083 | |
12060 | 12084 | version_string |
12061 | 12085 | = get_symbol_version_string (filedata, |
@@ -12063,6 +12087,22 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si, | ||
12063 | 12087 | || section->sh_type == SHT_DYNSYM), |
12064 | 12088 | strtab, strtab_size, si, |
12065 | 12089 | psym, &sym_info, &vna_other); |
12090 | + | |
12091 | + int len_avail = 21; | |
12092 | + if (! do_wide && version_string != NULL) | |
12093 | + { | |
12094 | + char buffer[256]; | |
12095 | + | |
12096 | + len_avail -= sprintf (buffer, "@%s", version_string); | |
12097 | + | |
12098 | + if (sym_info == symbol_undefined) | |
12099 | + len_avail -= sprintf (buffer," (%d)", vna_other); | |
12100 | + else if (sym_info != symbol_hidden) | |
12101 | + len_avail -= 1; | |
12102 | + } | |
12103 | + | |
12104 | + print_symbol (len_avail, sstr); | |
12105 | + | |
12066 | 12106 | if (version_string) |
12067 | 12107 | { |
12068 | 12108 | if (sym_info == symbol_undefined) |
@@ -1,3 +1,14 @@ | ||
1 | +2020-07-02 Nick Clifton <nickc@redhat.com> | |
2 | + | |
3 | + PR 26028 | |
4 | + * testsuite/gas/ia64/group-2.d: Add -T option to readelf | |
5 | + command line. | |
6 | + * testsuite/gas/ia64/unwind.d: Likewise. | |
7 | + * testsuite/gas/mmix/bspec-1.d: Likewise. | |
8 | + * testsuite/gas/mmix/bspec-2.d: Likewise. | |
9 | + * testsuite/gas/mmix/comment-1.d: Likewise. | |
10 | + * testsuite/gas/tic6x/scomm-directive-4.d: Likewise. | |
11 | + | |
1 | 12 | 2020-07-01 Alan Modra <amodra@gmail.com> |
2 | 13 | |
3 | 14 | * config/tc-xc16x.c (md_apply_fix): Add FIXME. |
@@ -1,4 +1,4 @@ | ||
1 | -#readelf: -Sg | |
1 | +#readelf: -Sg -T | |
2 | 2 | #as: -x |
3 | 3 | #name: ia64 unwind group |
4 | 4 |
@@ -1,4 +1,4 @@ | ||
1 | -#readelf: -S | |
1 | +#readelf: -S -T | |
2 | 2 | #name: ia64 unwind section |
3 | 3 | |
4 | 4 | There are 9 section headers, starting at offset .*: |
@@ -1,4 +1,4 @@ | ||
1 | -#readelf: -Ssr -x1 -x4 | |
1 | +#readelf: -Ssr -T -x1 -x4 | |
2 | 2 | There are 9 section headers, starting at offset .*: |
3 | 3 | #... |
4 | 4 | +\[ 4\] \.MMIX\.spec_data\.2 +PROGBITS +0+ +0+44 |
@@ -1,4 +1,4 @@ | ||
1 | -#readelf: -Sr -x1 -x4 | |
1 | +#readelf: -Sr -T -x1 -x4 | |
2 | 2 | There are 11 section headers, starting at offset .*: |
3 | 3 | #... |
4 | 4 | \[ 4\] \.MMIX\.spec_data\.2 PROGBITS 0+ 0+48 |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #as: -no-expand |
2 | -#readelf: -Ssrx1 -x6 | |
2 | +#readelf: -Ssrx1 -T -x6 | |
3 | 3 | There are 10 section headers, starting at offset 0x...: |
4 | 4 | #... |
5 | 5 | +\[ 5\] \.MMIX\.spec_data\.4 +PROGBITS +0+ +0+c4 |
@@ -1,7 +1,7 @@ | ||
1 | 1 | #name: C6X .scomm directive 4 |
2 | 2 | #as: |
3 | 3 | #source: scomm-directive-4.s |
4 | -#readelf: -Ss | |
4 | +#readelf: -Ss -T | |
5 | 5 | |
6 | 6 | There are 8 section headers, starting at offset .*: |
7 | 7 |
@@ -1,3 +1,16 @@ | ||
1 | +2020-07-02 Nick Clifton <nickc@redhat.com> | |
2 | + | |
3 | + PR 26028 | |
4 | + * testsuite/ld-powerpc/powerpc.exp: Add -T option to readelf | |
5 | + command line when running some tests. | |
6 | + * testsuite/ld-arm/arm-elf.exp: Likewise. | |
7 | + * testsuite/ld-mips-elf/mips-elf.exp: Likewise. | |
8 | + * testsuite/ld-mmix/local1.d: Likewise. | |
9 | + * testsuite/ld-mmix/local3.d: Likewise. | |
10 | + * testsuite/ld-mmix/local5.d: Likewise. | |
11 | + * testsuite/ld-mmix/local7.d: Likewise. | |
12 | + * testsuite/ld-powerpc/powerpc.exp: Likewise. | |
13 | + | |
1 | 14 | 2020-06-30 H.J. Lu <hongjiu.lu@intel.com> |
2 | 15 | |
3 | 16 | * Makefile.am (ALL_EMULATION_SOURCES): Remove eelf_i386_nacl.c, |
@@ -794,7 +794,7 @@ set armeabitests_nonacl { | ||
794 | 794 | "--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-implib.lib --cmse-implib" "" |
795 | 795 | "-march=armv8-m.base -mthumb --defsym VER=1" |
796 | 796 | {cmse-implib.s} |
797 | - {{readelf {-s tmpdir/cmse-implib.lib} cmse-implib.rd} | |
797 | + {{readelf {-s --wide tmpdir/cmse-implib.lib} cmse-implib.rd} | |
798 | 798 | {readelf {-h tmpdir/cmse-implib.lib} cmse-implib.type}} |
799 | 799 | "cmse-implib"} |
800 | 800 | {"Input secure gateway import library" |
@@ -802,7 +802,7 @@ set armeabitests_nonacl { | ||
802 | 802 | "-march=armv8-m.base -mthumb --defsym VER=2" |
803 | 803 | {cmse-implib.s} |
804 | 804 | {{ld cmse-new-implib.out} |
805 | - {readelf {-s tmpdir/cmse-new-implib.lib} cmse-new-implib.rd}} | |
805 | + {readelf {-s --wide tmpdir/cmse-new-implib.lib} cmse-new-implib.rd}} | |
806 | 806 | "cmse-new-implib"} |
807 | 807 | {"Input secure gateway import library: no output import library" |
808 | 808 | "--section-start .gnu.sgstubs=0x20000 --in-implib=tmpdir/cmse-implib.lib --cmse-implib" "" |
@@ -832,7 +832,7 @@ set armeabitests_nonacl { | ||
832 | 832 | "--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-new-comeback-implib.lib --in-implib=tmpdir/cmse-implib.lib --cmse-implib" "" |
833 | 833 | "-march=armv8-m.base -mthumb --defsym VER=3" |
834 | 834 | {cmse-implib.s} |
835 | - {{readelf {-s tmpdir/cmse-new-comeback-implib.lib} cmse-new-comeback-implib.rd}} | |
835 | + {{readelf {-s --wide tmpdir/cmse-new-comeback-implib.lib} cmse-new-comeback-implib.rd}} | |
836 | 836 | "cmse-new-comeback-implib"} |
837 | 837 | {"Input secure gateway import library: entry function change" |
838 | 838 | "--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-new-wrong-implib.lib --in-implib=tmpdir/cmse-implib.lib --cmse-implib" "" |
@@ -29,7 +29,7 @@ if {[istarget "mips*-*-vxworks"]} { | ||
29 | 29 | {"VxWorks executable test 1 (dynamic)" \ |
30 | 30 | "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic" "" |
31 | 31 | "-mips2" {vxworks1.s} |
32 | - {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}} | |
32 | + {{readelf {--relocs -T} vxworks1.rd} {objdump -dr vxworks1.dd}} | |
33 | 33 | "vxworks1"} |
34 | 34 | {"VxWorks executable test 2 (dynamic)" \ |
35 | 35 | "-Tvxworks1.ld -q --force-dynamic" "" |
@@ -1575,7 +1575,7 @@ proc run_mips_undefweak_test { name abi args } { | ||
1575 | 1575 | [list \ |
1576 | 1576 | [list objdump -d pr21375${objsuf}.dd] \ |
1577 | 1577 | [list readelf -A pr21375${rdesuf}.gd] \ |
1578 | - [list readelf --dyn-syms pr21375${rdesuf}${irixsuf}.sd] \ | |
1578 | + [list readelf {--dyn-syms --wide} pr21375${rdesuf}${irixsuf}.sd] \ | |
1579 | 1579 | [list readelf -h pr21375${abisuf}.hd]] \ |
1580 | 1580 | "pr21375${binsuf}${dsosuf}"]] |
1581 | 1581 | } |
@@ -4,7 +4,7 @@ | ||
4 | 4 | #source: regext1.s |
5 | 5 | #source: start.s |
6 | 6 | #ld: -m elf64mmix |
7 | -#readelf: -Ssx1 -x2 | |
7 | +#readelf: -Ssx1 -T -x2 | |
8 | 8 | |
9 | 9 | # We check that the externally visible symbol ext1 is a local register |
10 | 10 | # (different meaning of "local" than for symbol), which can be seen as |
@@ -4,7 +4,7 @@ | ||
4 | 4 | #source: ext1.s |
5 | 5 | #source: start.s |
6 | 6 | #ld: -m elf64mmix |
7 | -#readelf: -Ssx1 -x2 | |
7 | +#readelf: -Ssx1 -T -x2 | |
8 | 8 | |
9 | 9 | # Like local1, but ext1 is here a constant, not a global register. |
10 | 10 |
@@ -5,7 +5,7 @@ | ||
5 | 5 | #source: regext1.s |
6 | 6 | #source: start.s |
7 | 7 | #ld: -m elf64mmix |
8 | -#readelf: -Ssx1 -x2 | |
8 | +#readelf: -Ssx1 -T -x2 | |
9 | 9 | |
10 | 10 | # Like local1, but with two checks for a local register. |
11 | 11 |
@@ -5,7 +5,7 @@ | ||
5 | 5 | #source: ext1.s |
6 | 6 | #source: start.s |
7 | 7 | #ld: -m elf64mmix |
8 | -#readelf: -Ssx1 -x2 | |
8 | +#readelf: -Ssx1 -T -x2 | |
9 | 9 | |
10 | 10 | # Like local1, but ext1 is here a constant, not a global register and two |
11 | 11 | # local-register checks. |
@@ -32,13 +32,13 @@ if {[istarget "*-*-vxworks"]} { | ||
32 | 32 | {"VxWorks shared library test 1" |
33 | 33 | "-shared --hash-style=sysv -Tvxworks1.ld" "" |
34 | 34 | "-mregnames" {vxworks1-lib.s} |
35 | - {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd} | |
35 | + {{readelf {--relocs -T} vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd} | |
36 | 36 | {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}} |
37 | 37 | "libvxworks1.so"} |
38 | 38 | {"VxWorks executable test 1 (dynamic)" \ |
39 | 39 | "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic --hash-style=sysv" "" |
40 | 40 | "-mregnames" {vxworks1.s} |
41 | - {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}} | |
41 | + {{readelf {--relocs -T} vxworks1.rd} {objdump -dr vxworks1.dd}} | |
42 | 42 | "vxworks1"} |
43 | 43 | {"VxWorks executable test 2 (dynamic)" \ |
44 | 44 | "-Tvxworks1.ld -q --force-dynamic --hash-style=sysv" "" |
@@ -58,7 +58,7 @@ if {[istarget "*-*-vxworks"]} { | ||
58 | 58 | {"VxWorks relocatable relax test" |
59 | 59 | "-Tvxworks1.ld -r --relax -q --hash-style=sysv" "" |
60 | 60 | "-mregnames" {vxworks-relax-2.s} |
61 | - {{readelf --relocs vxworks-relax-2.rd}} | |
61 | + {{readelf {--relocs -T} vxworks-relax-2.rd}} | |
62 | 62 | "vxworks-relax-2"} |
63 | 63 | } |
64 | 64 | run_ld_link_tests $ppcvxtests |