diff options
author | Jan Beulich <jbeulich@suse.com> | 2025-04-07 12:45:11 +0200 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2025-04-07 12:45:11 +0200 |
commit | 6fe5e01b131716e3000edb5c6b4a1d1a26dd144c (patch) | |
tree | 6c5c9391aa3a1e4d9f3c919e9b3945dcce71f86c | |
parent | 50491ef1d395badbffabe192433d2c6010bc2f15 (diff) | |
download | binutils-6fe5e01b131716e3000edb5c6b4a1d1a26dd144c.zip binutils-6fe5e01b131716e3000edb5c6b4a1d1a26dd144c.tar.gz binutils-6fe5e01b131716e3000edb5c6b4a1d1a26dd144c.tar.bz2 |
nm: also retrieve size for COFF function symbols
Like ELF for all symbols, COFF can record size for at least function
ones. Use that - if available - in preference to the distance-to-next-
symbol heuristic.
To be able to use the new test there, make TI C54x follow TI C4x in
providing .sdef to cover for .def already having different meaning.
-rw-r--r-- | binutils/nm.c | 22 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/nm-coff-1.s | 26 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/nm-coff-sdef-1.s | 26 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/nm.exp | 6 | ||||
-rw-r--r-- | gas/config/obj-coff.c | 4 |
5 files changed, 78 insertions, 6 deletions
diff --git a/binutils/nm.c b/binutils/nm.c index 4e86057..1a8615e 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -79,7 +79,14 @@ struct extended_symbol_info #define SYM_STAB_DESC(sym) (sym->sinfo->stab_desc) #define SYM_STAB_OTHER(sym) (sym->sinfo->stab_other) #define SYM_SIZE(sym) \ - (sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize) + (sym->elfinfo \ + ? sym->elfinfo->internal_elf_sym.st_size \ + : sym->coffinfo \ + && ISFCN (sym->coffinfo->native->u.syment.n_type) \ + && sym->coffinfo->native->u.syment.n_numaux \ + && sym->coffinfo->native[1].u.auxent.x_sym.x_misc.x_fsize \ + ? sym->coffinfo->native[1].u.auxent.x_sym.x_misc.x_fsize \ + : sym->ssize) /* The output formatting functions. */ static void print_object_filename_bsd (const char *); @@ -1036,9 +1043,9 @@ size_forward2 (const void *P_x, const void *P_y) return sorters[0][reverse_sort] (x->minisym, y->minisym); } -/* Sort the symbols by size. ELF provides a size but for other formats - we have to make a guess by assuming that the difference between the - address of a symbol and the address of the next higher symbol is the +/* Sort the symbols by size. ELF and COFF may provide a size but for other + formats we have to make a guess by assuming that the difference between + the address of a symbol and the address of the next higher symbol is the size. */ static long @@ -1081,6 +1088,7 @@ sort_symbols_by_size (bfd *abfd, bool is_dynamic, void *minisyms, asection *sec; bfd_vma sz; asymbol *temp; + const coff_symbol_type *coffsym; if (from + size < fromend) { @@ -1103,6 +1111,12 @@ sort_symbols_by_size (bfd *abfd, bool is_dynamic, void *minisyms, && bfd_get_flavour (abfd) == bfd_target_elf_flavour) sz = ((elf_symbol_type *) sym)->internal_elf_sym.st_size; else if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 + && (coffsym = coff_symbol_from (sym)) != NULL + && ISFCN (coffsym->native->u.syment.n_type) + && coffsym->native->u.syment.n_numaux != 0 + && coffsym->native[1].u.auxent.x_sym.x_misc.x_fsize != 0) + sz = coffsym->native[1].u.auxent.x_sym.x_misc.x_fsize; + else if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 && bfd_is_com_section (sec)) sz = sym->value; else diff --git a/binutils/testsuite/binutils-all/nm-coff-1.s b/binutils/testsuite/binutils-all/nm-coff-1.s new file mode 100644 index 0000000..3efc10e --- /dev/null +++ b/binutils/testsuite/binutils-all/nm-coff-1.s @@ -0,0 +1,26 @@ + .globl text_symbol1 + .globl text_symbol2 + .globl text_symbol3 + .macro ENDFN name:req + .def \name + .type 0x20 /* DT_FUNC */ + .scl 2 /* C_EXT */ + .endef + .def \name + .scl 0xff /* C_EFCN */ + .val . + .endef + .endm + .text +text_symbol1: + .long 0 + .long 0 + .long 0 + ENDFN text_symbol1 +text_symbol2: + .long 0 + .long 0 + ENDFN text_symbol2 +text_symbol3: + .long 0 + ENDFN text_symbol3 diff --git a/binutils/testsuite/binutils-all/nm-coff-sdef-1.s b/binutils/testsuite/binutils-all/nm-coff-sdef-1.s new file mode 100644 index 0000000..f1a10bb --- /dev/null +++ b/binutils/testsuite/binutils-all/nm-coff-sdef-1.s @@ -0,0 +1,26 @@ + .globl text_symbol1 + .globl text_symbol2 + .globl text_symbol3 + .macro ENDFN name:req + .sdef \name + .type 0x20 /* DT_FUNC */ + .scl 2 /* C_EXT */ + .endef + .sdef \name + .scl 0xff /* C_EFCN */ + .val . + .endef + .endm + .text +text_symbol1: + .byte 0,0,0,0 + .byte 0,0,0,0 + .byte 0,0,0,0 + ENDFN text_symbol1 +text_symbol2: + .byte 0,0,0,0 + .byte 0,0,0,0 + ENDFN text_symbol2 +text_symbol3: + .byte 0,0,0,0 + ENDFN text_symbol3 diff --git a/binutils/testsuite/binutils-all/nm.exp b/binutils/testsuite/binutils-all/nm.exp index e1b2d16..b81126b 100644 --- a/binutils/testsuite/binutils-all/nm.exp +++ b/binutils/testsuite/binutils-all/nm.exp @@ -163,6 +163,12 @@ if { [is_elf_format] || [istarget wasm32-*-*] || [istarget bpf-*-*]} { set nm_1_src "nm-elf-1.s" +} elseif {[is_coff_format] && ![istarget arm*-*-*]} { + if {[istarget *c4x-*-*] || [istarget *c54x-*-*]} { + set nm_1_src "nm-coff-sdef-1.s" + } else { + set nm_1_src "nm-coff-1.s" + } } else { set nm_1_src "nm-1.s" } diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c index 19759cd..eb5784e 100644 --- a/gas/config/obj-coff.c +++ b/gas/config/obj-coff.c @@ -1887,8 +1887,8 @@ static const pseudo_typeS coff_pseudo_table[] = {"loc", obj_coff_loc, 0}, {"optim", s_ignore, 0}, /* For sun386i cc (?) */ {"weak", obj_coff_weak, 0}, -#if defined TC_TIC4X - /* The tic4x uses sdef instead of def. */ +#if defined (TC_TIC4X) || defined (TC_TIC54X) + /* The tic4x and tic54x use sdef instead of def. */ {"sdef", obj_coff_def, 0}, #endif #if defined(SEH_CMDS) |