diff options
Diffstat (limited to 'bfd')
48 files changed, 245 insertions, 36 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ec3ab0a..69313e1 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,79 @@ +2021-01-07 H.J. Lu <hongjiu.lu@intel.com> + + PR 27109 + * aix386-core.c (core_aix386_vec): Initialize + keep_unused_section_symbol to TARGET_KEEP_UNUSED_SECTION_SYMBOLS. + * aout-target.h (MY (vec)): Likewise. + * binary.c (binary_vec): Likewise. + * cisco-core.c (core_cisco_be_vec): Likewise. + (core_cisco_le_vec): Likewise. + * coff-alpha.c (alpha_ecoff_le_vec): Likewise. + * coff-i386.c (TARGET_SYM): Likewise. + (TARGET_SYM_BIG): Likewise. + * coff-ia64.c (TARGET_SYM): Likewise. + * coff-mips.c (mips_ecoff_le_vec): Likewise. + (mips_ecoff_be_vec): Likewise. + (mips_ecoff_bele_vec): Likewise. + * coff-rs6000.c (rs6000_xcoff_vec): Likewise. + (powerpc_xcoff_vec): Likewise. + * coff-sh.c (sh_coff_small_vec): Likewise. + (sh_coff_small_le_vec): Likewise. + * coff-tic30.c (tic30_coff_vec): Likewise. + * coff-tic54x.c (tic54x_coff0_vec): Likewise. + (tic54x_coff0_beh_vec): Likewise. + (tic54x_coff1_vec): Likewise. + (tic54x_coff1_beh_vec): Likewise. + (tic54x_coff2_vec): Likewise. + (tic54x_coff2_beh_vec): Likewise. + * coff-x86_64.c (TARGET_SYM): Likewise. + (TARGET_SYM_BIG): Likewise. + * coff64-rs6000.c (rs6000_xcoff64_vec): Likewise. + (rs6000_xcoff64_aix_vec): Likewise. + * coffcode.h (CREATE_BIG_COFF_TARGET_VEC): Likewise. + (CREATE_BIGHDR_COFF_TARGET_VEC): Likewise. + (CREATE_LITTLE_COFF_TARGET_VEC): Likewise. + * elfxx-target.h (TARGET_BIG_SYM): Likewise. + (TARGET_LITTLE_SYM): Likewise. + * hppabsd-core.c (core_hppabsd_vec): Likewise. + * hpux-core.c (core_hpux_vec): Likewise. + * i386msdos.c (i386_msdos_vec): Likewise. + * ihex.c (ihex_vec): Likewise. + * irix-core.c (core_irix_vec): Likewise. + * mach-o-target.c (TARGET_NAME): Likewise. + * mmo.c (mmix_mmo_vec): Likewise. + * netbsd-core.c (core_netbsd_vec): Likewise. + * osf-core.c (core_osf_vec): Likewise. + * pdp11.c (MY (vec)): Likewise. + * pef.c (pef_vec): Likewise. + (pef_xlib_vec): Likewise. + * plugin.c (plugin_vec): Likewise. + * ppcboot.c (powerpc_boot_vec): Likewise. + * ptrace-core.c (core_ptrace_vec): Likewise. + * sco5-core.c (core_sco5_vec): Likewise. + * som.c (hppa_som_vec): Likewise. + * srec.c (srec_vec): Likewise. + (symbolsrec_vec): Likewise. + * tekhex.c (tekhex_vec): Likewise. + * trad-core.c (core_trad_vec): Likewise. + * verilog.c (verilog_vec): Likewise. + * vms-alpha.c (alpha_vms_vec): Likewise. + * vms-lib.c (alpha_vms_lib_txt_vec): Likewise. + * wasm-module.c (wasm_vec): Likewise. + * xsym.c (sym_vec): Likewise. + * elf.c (ignore_section_sym): Return TRUE if BSF_SECTION_SYM_USED + isn't set. + (elf_map_symbols): Don't include ignored section symbols. + * elfcode.h (elf_slurp_symbol_table): Also set + BSF_SECTION_SYM_USED on STT_SECTION symbols. + * elflink.c (bfd_elf_final_link): Generated section symbols only + when emitting relocations or reqired. + * elfxx-x86.h (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New. + * syms.c (BSF_SECTION_SYM_USED): New. + * targets.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New. + (bfd_target): Add keep_unused_section_symbols. + (bfd_keep_unused_section_symbols): New. + * bfd-in2.h: Regenerated. + 2021-01-07 Nick Clifton <nickc@redhat.com> PR 25713 diff --git a/bfd/aix386-core.c b/bfd/aix386-core.c index d641b81..68cd642 100644 --- a/bfd/aix386-core.c +++ b/bfd/aix386-core.c @@ -239,6 +239,7 @@ const bfd_target core_aix386_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, NO_GET, NO_GETS, NO_PUT, NO_GET, NO_GETS, NO_PUT, /* data */ diff --git a/bfd/aout-target.h b/bfd/aout-target.h index 8c27bb1..92fc3ed 100644 --- a/bfd/aout-target.h +++ b/bfd/aout-target.h @@ -660,6 +660,7 @@ const bfd_target MY (vec) = AR_PAD_CHAR, /* AR_pad_char. */ 15, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ #ifdef TARGET_IS_BIG_ENDIAN_P bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 43ead18..7eff85b 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -6416,6 +6416,9 @@ typedef struct bfd_symbol with this name and type in use. BSF_OBJECT must also be set. */ #define BSF_GNU_UNIQUE (1 << 23) + /* This section symbol should be included in the symbol table. */ +#define BSF_SECTION_SYM_USED (1 << 24) + flagword flags; /* A pointer to the section to which this symbol is @@ -7291,6 +7294,11 @@ bfd_boolean generic_core_file_matches_executable_p (bfd_assert (__FILE__,__LINE__), NULL)) #endif +/* Defined to TRUE if unused section symbol should be kept. */ +#ifndef TARGET_KEEP_UNUSED_SECTION_SYMBOLS +#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS TRUE +#endif + enum bfd_flavour { /* N.B. Update bfd_flavour_name if you change this. */ @@ -7364,6 +7372,9 @@ typedef struct bfd_target possible targets when more than one target matches. */ unsigned char match_priority; + /* TRUE if unused section symbols should be kept. */ + bfd_boolean keep_unused_section_symbols; + /* Entries for byte swapping for data. These are different from the other entry points, since they don't take a BFD as the first argument. Certain other handlers could do the same. */ @@ -7794,6 +7805,12 @@ bfd_asymbol_flavour (const asymbol *sy) return sy->the_bfd->xvec->flavour; } +static inline bfd_boolean +bfd_keep_unused_section_symbols (const bfd *abfd) +{ + return abfd->xvec->keep_unused_section_symbols; +} + bfd_boolean bfd_set_default_target (const char *name); const bfd_target *bfd_find_target (const char *target_name, bfd *abfd); diff --git a/bfd/binary.c b/bfd/binary.c index db1bec0..942c66b 100644 --- a/bfd/binary.c +++ b/bfd/binary.c @@ -335,6 +335,7 @@ const bfd_target binary_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 255, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ diff --git a/bfd/cisco-core.c b/bfd/cisco-core.c index 1b77829..c0e68ad 100644 --- a/bfd/cisco-core.c +++ b/bfd/cisco-core.c @@ -329,6 +329,7 @@ const bfd_target core_cisco_be_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ @@ -384,6 +385,7 @@ const bfd_target core_cisco_le_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match_priority */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c index 50b2f97..db26587 100644 --- a/bfd/coff-alpha.c +++ b/bfd/coff-alpha.c @@ -2427,6 +2427,7 @@ const bfd_target alpha_ecoff_le_vec = ' ', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ diff --git a/bfd/coff-i386.c b/bfd/coff-i386.c index 5048df9..e025195 100644 --- a/bfd/coff-i386.c +++ b/bfd/coff-i386.c @@ -651,6 +651,7 @@ const bfd_target '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, @@ -729,6 +730,7 @@ const bfd_target '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, @@ -772,4 +774,4 @@ const bfd_target &bigobj_swap_table }; -#endif
\ No newline at end of file +#endif diff --git a/bfd/coff-ia64.c b/bfd/coff-ia64.c index 24a4a7c..887c7aa 100644 --- a/bfd/coff-ia64.c +++ b/bfd/coff-ia64.c @@ -170,6 +170,7 @@ const bfd_target '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, diff --git a/bfd/coff-mips.c b/bfd/coff-mips.c index 38376b2..d20f4b4 100644 --- a/bfd/coff-mips.c +++ b/bfd/coff-mips.c @@ -1446,6 +1446,7 @@ const bfd_target mips_ecoff_le_vec = ' ', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -1504,6 +1505,7 @@ const bfd_target mips_ecoff_be_vec = ' ', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, @@ -1562,6 +1564,7 @@ const bfd_target mips_ecoff_bele_vec = ' ', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index a71791e..fbc1aed 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -4201,6 +4201,7 @@ const bfd_target rs6000_xcoff_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ /* data */ bfd_getb64, @@ -4382,6 +4383,7 @@ const bfd_target powerpc_xcoff_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ /* data */ bfd_getb64, diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c index 99541a7..04ef99b 100644 --- a/bfd/coff-sh.c +++ b/bfd/coff-sh.c @@ -3134,6 +3134,7 @@ const bfd_target sh_coff_small_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ @@ -3191,6 +3192,7 @@ const bfd_target sh_coff_small_le_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ diff --git a/bfd/coff-tic30.c b/bfd/coff-tic30.c index f3e7df0..f4d3a13 100644 --- a/bfd/coff-tic30.c +++ b/bfd/coff-tic30.c @@ -192,6 +192,7 @@ const bfd_target tic30_coff_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ diff --git a/bfd/coff-tic54x.c b/bfd/coff-tic54x.c index 914bb2a..3c18221 100644 --- a/bfd/coff-tic54x.c +++ b/bfd/coff-tic54x.c @@ -415,6 +415,7 @@ const bfd_target tic54x_coff0_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, tic54x_getl32, tic54x_getl_signed_32, tic54x_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -472,6 +473,11 @@ const bfd_target tic54x_coff0_beh_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ +#ifdef TARGET_KEEP_UNUSED_SECTION_SYMBOLS + TRUE, /* keep unused section symbols. */ +#else + FALSE, /* keep unused section symbols. */ +#endif bfd_getl64, bfd_getl_signed_64, bfd_putl64, tic54x_getl32, tic54x_getl_signed_32, tic54x_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -530,6 +536,11 @@ const bfd_target tic54x_coff1_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ +#ifdef TARGET_KEEP_UNUSED_SECTION_SYMBOLS + TRUE, /* keep unused section symbols. */ +#else + FALSE, /* keep unused section symbols. */ +#endif bfd_getl64, bfd_getl_signed_64, bfd_putl64, tic54x_getl32, tic54x_getl_signed_32, tic54x_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -588,6 +599,11 @@ const bfd_target tic54x_coff1_beh_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ +#ifdef TARGET_KEEP_UNUSED_SECTION_SYMBOLS + TRUE, /* keep unused section symbols. */ +#else + FALSE, /* keep unused section symbols. */ +#endif bfd_getl64, bfd_getl_signed_64, bfd_putl64, tic54x_getl32, tic54x_getl_signed_32, tic54x_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -646,6 +662,11 @@ const bfd_target tic54x_coff2_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ +#ifdef TARGET_KEEP_UNUSED_SECTION_SYMBOLS + TRUE, /* keep unused section symbols. */ +#else + FALSE, /* keep unused section symbols. */ +#endif bfd_getl64, bfd_getl_signed_64, bfd_putl64, tic54x_getl32, tic54x_getl_signed_32, tic54x_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -704,6 +725,11 @@ const bfd_target tic54x_coff2_beh_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ +#ifdef TARGET_KEEP_UNUSED_SECTION_SYMBOLS + TRUE, /* keep unused section symbols. */ +#else + FALSE, /* keep unused section symbols. */ +#endif bfd_getl64, bfd_getl_signed_64, bfd_putl64, tic54x_getl32, tic54x_getl_signed_32, tic54x_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ diff --git a/bfd/coff-x86_64.c b/bfd/coff-x86_64.c index 0279ce2..adab60c 100644 --- a/bfd/coff-x86_64.c +++ b/bfd/coff-x86_64.c @@ -782,6 +782,7 @@ const bfd_target '/', /* Ar_pad_char. */ 15, /* Ar_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, @@ -854,6 +855,7 @@ const bfd_target '/', /* Ar_pad_char. */ 15, /* Ar_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c index a3b1702..9aa0304 100644 --- a/bfd/coff64-rs6000.c +++ b/bfd/coff64-rs6000.c @@ -2665,6 +2665,7 @@ const bfd_target rs6000_xcoff64_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ /* data */ bfd_getb64, @@ -2928,6 +2929,7 @@ const bfd_target rs6000_xcoff64_aix_vec = '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ /* data */ bfd_getb64, diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 21820da..2fd699f 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -5820,6 +5820,7 @@ const bfd_target VAR = \ '/', /* AR_pad_char. */ \ 15, /* AR_max_namelen. */ \ 0, /* match priority. */ \ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ \ \ /* Data conversion functions. */ \ bfd_getb64, bfd_getb_signed_64, bfd_putb64, \ @@ -5881,6 +5882,7 @@ const bfd_target VAR = \ '/', /* AR_pad_char. */ \ 15, /* AR_max_namelen. */ \ 0, /* match priority. */ \ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ \ \ /* Data conversion functions. */ \ bfd_getb64, bfd_getb_signed_64, bfd_putb64, \ @@ -5942,6 +5944,7 @@ const bfd_target VAR = \ '/', /* AR_pad_char. */ \ 15, /* AR_max_namelen. */ \ 0, /* match priority. */ \ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ \ \ /* Data conversion functions. */ \ bfd_getl64, bfd_getl_signed_64, bfd_putl64, \ @@ -4061,6 +4061,10 @@ ignore_section_sym (bfd *abfd, asymbol *sym) if ((sym->flags & BSF_SECTION_SYM) == 0) return FALSE; + /* Ignore the section symbol if it isn't used. */ + if ((sym->flags & BSF_SECTION_SYM_USED) == 0) + return TRUE; + if (sym->section == NULL) return TRUE; @@ -4148,7 +4152,10 @@ elf_map_symbols (bfd *abfd, unsigned int *pnum_locals) at least in that case. */ for (asect = abfd->sections; asect; asect = asect->next) { - if (sect_syms[asect->index] == NULL) + asymbol *sym = asect->symbol; + /* Don't include ignored section symbols. */ + if (!ignore_section_sym (abfd, sym) + && sect_syms[asect->index] == NULL) { if (!sym_is_global (abfd, asect->symbol)) num_locals++; @@ -4170,6 +4177,7 @@ elf_map_symbols (bfd *abfd, unsigned int *pnum_locals) if (sym_is_global (abfd, sym)) i = num_locals + num_globals2++; + /* Don't include ignored section symbols. */ else if (!ignore_section_sym (abfd, sym)) i = num_locals2++; else @@ -4179,9 +4187,10 @@ elf_map_symbols (bfd *abfd, unsigned int *pnum_locals) } for (asect = abfd->sections; asect; asect = asect->next) { - if (sect_syms[asect->index] == NULL) + asymbol *sym = asect->symbol; + if (!ignore_section_sym (abfd, sym) + && sect_syms[asect->index] == NULL) { - asymbol *sym = asect->symbol; unsigned int i; sect_syms[asect->index] = sym; diff --git a/bfd/elfcode.h b/bfd/elfcode.h index b40fb4a..4e99fcc 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1347,7 +1347,13 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) switch (ELF_ST_TYPE (isym->st_info)) { case STT_SECTION: - sym->symbol.flags |= BSF_SECTION_SYM | BSF_DEBUGGING; + /* Mark the input section symbol as used since it may be + used for relocation and section group. + NB: BSF_SECTION_SYM_USED is ignored by linker and may + be cleared by objcopy for non-relocatable inputs. */ + sym->symbol.flags |= (BSF_SECTION_SYM + | BSF_DEBUGGING + | BSF_SECTION_SYM_USED); break; case STT_FILE: sym->symbol.flags |= BSF_FILE | BSF_DEBUGGING; diff --git a/bfd/elflink.c b/bfd/elflink.c index 4c54b1a..a7c952b 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12527,9 +12527,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (info->strip != strip_all || emit_relocs) { - bfd_boolean name_local_sections; - const char *name; - file_ptr off = elf_next_file_pos (abfd); _bfd_elf_assign_file_position_for_section (symtab_hdr, off, TRUE); @@ -12550,36 +12547,38 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) bfd_und_section_ptr, NULL) != 1) goto error_return; - /* Output a symbol for each section. We output these even if we are - discarding local symbols, since they are used for relocs. These - symbols usually have no names. We store the index of each one in - the index field of the section, so that we can find it again when - outputting relocs. */ + /* Output a symbol for each section if asked or they are used for + relocs. These symbols usually have no names. We store the + index of each one in the index field of the section, so that + we can find it again when outputting relocs. */ - name_local_sections - = (bed->elf_backend_name_local_section_symbols - && bed->elf_backend_name_local_section_symbols (abfd)); + if (bfd_keep_unused_section_symbols (abfd) || emit_relocs) + { + bfd_boolean name_local_sections + = (bed->elf_backend_name_local_section_symbols + && bed->elf_backend_name_local_section_symbols (abfd)); + const char *name = NULL; - name = NULL; - elfsym.st_size = 0; - elfsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); - elfsym.st_other = 0; - elfsym.st_value = 0; - elfsym.st_target_internal = 0; - for (i = 1; i < elf_numsections (abfd); i++) - { - o = bfd_section_from_elf_index (abfd, i); - if (o != NULL) - { - o->target_index = bfd_get_symcount (abfd); - elfsym.st_shndx = i; - if (!bfd_link_relocatable (info)) - elfsym.st_value = o->vma; - if (name_local_sections) - name = o->name; - if (elf_link_output_symstrtab (&flinfo, name, &elfsym, o, - NULL) != 1) - goto error_return; + elfsym.st_size = 0; + elfsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); + elfsym.st_other = 0; + elfsym.st_value = 0; + elfsym.st_target_internal = 0; + for (i = 1; i < elf_numsections (abfd); i++) + { + o = bfd_section_from_elf_index (abfd, i); + if (o != NULL) + { + o->target_index = bfd_get_symcount (abfd); + elfsym.st_shndx = i; + if (!bfd_link_relocatable (info)) + elfsym.st_value = o->vma; + if (name_local_sections) + name = o->name; + if (elf_link_output_symstrtab (&flinfo, name, &elfsym, o, + NULL) != 1) + goto error_return; + } } } } diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index cae1fbf..c930b76 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -1007,6 +1007,9 @@ const bfd_target TARGET_BIG_SYM = elf_match_priority, + /* TRUE if unused section symbols should be kept. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, + /* Routines to byte-swap various sized integers from the data sections */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, @@ -1108,6 +1111,9 @@ const bfd_target TARGET_LITTLE_SYM = elf_match_priority, + /* TRUE if unused section symbols should be kept. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, + /* Routines to byte-swap various sized integers from the data sections */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h index cc8149d..e11e06b 100644 --- a/bfd/elfxx-x86.h +++ b/bfd/elfxx-x86.h @@ -18,6 +18,9 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +/* Don't generate unused section symbols. */ +#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS FALSE + #include "sysdep.h" #include "bfd.h" #include "bfdlink.h" diff --git a/bfd/hppabsd-core.c b/bfd/hppabsd-core.c index d2c8a94..c36e467 100644 --- a/bfd/hppabsd-core.c +++ b/bfd/hppabsd-core.c @@ -230,6 +230,7 @@ const bfd_target core_hppabsd_vec = 0, /* symbol prefix */ ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ diff --git a/bfd/hpux-core.c b/bfd/hpux-core.c index 42f8424..03d0de3 100644 --- a/bfd/hpux-core.c +++ b/bfd/hpux-core.c @@ -392,6 +392,7 @@ const bfd_target core_hpux_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ diff --git a/bfd/i386msdos.c b/bfd/i386msdos.c index 526561e..6254b2a 100644 --- a/bfd/i386msdos.c +++ b/bfd/i386msdos.c @@ -279,6 +279,7 @@ const bfd_target i386_msdos_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -981,6 +981,7 @@ const bfd_target ihex_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ diff --git a/bfd/irix-core.c b/bfd/irix-core.c index d00f491..e4fb622 100644 --- a/bfd/irix-core.c +++ b/bfd/irix-core.c @@ -293,6 +293,7 @@ const bfd_target core_irix_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match_priority */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ diff --git a/bfd/mach-o-target.c b/bfd/mach-o-target.c index 993c974..3b45433 100644 --- a/bfd/mach-o-target.c +++ b/bfd/mach-o-target.c @@ -136,6 +136,7 @@ const bfd_target TARGET_NAME = ' ', /* ar_pad_char. */ 16, /* ar_max_namelen. */ TARGET_PRIORITY, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ #if TARGET_BIG_ENDIAN bfd_getb64, bfd_getb_signed_64, bfd_putb64, @@ -3344,6 +3344,7 @@ const bfd_target mmix_mmo_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ diff --git a/bfd/netbsd-core.c b/bfd/netbsd-core.c index a1f8820..60fa69d 100644 --- a/bfd/netbsd-core.c +++ b/bfd/netbsd-core.c @@ -276,6 +276,7 @@ const bfd_target core_netbsd_vec = ' ', /* ar_pad_char. */ 16, /* ar_max_namelen. */ 0, /* Match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data. */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data. */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data. */ diff --git a/bfd/osf-core.c b/bfd/osf-core.c index f91b2aa..17cc532 100644 --- a/bfd/osf-core.c +++ b/bfd/osf-core.c @@ -187,6 +187,7 @@ const bfd_target core_osf_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ diff --git a/bfd/pdp11.c b/bfd/pdp11.c index 914dcaa..8992f4e 100644 --- a/bfd/pdp11.c +++ b/bfd/pdp11.c @@ -4689,6 +4689,7 @@ const bfd_target MY (vec) = AR_PAD_CHAR, /* AR_pad_char. */ 15, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getp32, bfd_getp_signed_32, bfd_putp32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */ @@ -1015,6 +1015,7 @@ const bfd_target pef_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ @@ -1159,6 +1160,7 @@ const bfd_target pef_xlib_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ diff --git a/bfd/plugin.c b/bfd/plugin.c index d733f6a..d1767b0 100644 --- a/bfd/plugin.c +++ b/bfd/plugin.c @@ -719,6 +719,7 @@ const bfd_target plugin_vec = '/', /* ar_pad_char. */ 15, /* ar_max_namelen. */ 255, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, diff --git a/bfd/ppcboot.c b/bfd/ppcboot.c index e3ade1c..5cdd7ad 100644 --- a/bfd/ppcboot.c +++ b/bfd/ppcboot.c @@ -495,6 +495,7 @@ const bfd_target powerpc_boot_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ diff --git a/bfd/ptrace-core.c b/bfd/ptrace-core.c index 7cf47af..d21a61c 100644 --- a/bfd/ptrace-core.c +++ b/bfd/ptrace-core.c @@ -177,6 +177,7 @@ const bfd_target core_ptrace_vec = 0, /* symbol prefix */ ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ diff --git a/bfd/sco5-core.c b/bfd/sco5-core.c index c543c38..167dba9 100644 --- a/bfd/sco5-core.c +++ b/bfd/sco5-core.c @@ -358,6 +358,7 @@ const bfd_target core_sco5_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ @@ -6859,6 +6859,7 @@ const bfd_target hppa_som_vec = '/', /* AR_pad_char. */ 14, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ @@ -1295,6 +1295,7 @@ const bfd_target srec_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ @@ -1351,6 +1352,7 @@ const bfd_target symbolsrec_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ @@ -307,6 +307,9 @@ CODE_FRAGMENT . with this name and type in use. BSF_OBJECT must also be set. *} .#define BSF_GNU_UNIQUE (1 << 23) . +. {* This section symbol should be included in the symbol table. *} +.#define BSF_SECTION_SYM_USED (1 << 24) +. . flagword flags; . . {* A pointer to the section to which this symbol is diff --git a/bfd/targets.c b/bfd/targets.c index 8086f03..076441b 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -133,6 +133,11 @@ DESCRIPTION . (bfd_assert (__FILE__,__LINE__), NULL)) .#endif . +.{* Defined to TRUE if unused section symbol should be kept. *} +.#ifndef TARGET_KEEP_UNUSED_SECTION_SYMBOLS +.#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS TRUE +.#endif +. This is the structure which defines the type of BFD this is. The <<xvec>> member of the struct <<bfd>> itself points here. Each module that implements access to a different target under BFD, @@ -215,6 +220,9 @@ DESCRIPTION . possible targets when more than one target matches. *} . unsigned char match_priority; . +. {* TRUE if unused section symbols should be kept. *} +. bfd_boolean keep_unused_section_symbols; +. . {* Entries for byte swapping for data. These are different from the . other entry points, since they don't take a BFD as the first argument. . Certain other handlers could do the same. *} @@ -655,6 +663,12 @@ to find an alternative output format that is suitable. . return sy->the_bfd->xvec->flavour; .} . +.static inline bfd_boolean +.bfd_keep_unused_section_symbols (const bfd *abfd) +.{ +. return abfd->xvec->keep_unused_section_symbols; +.} +. */ /* All known xvecs (even those that don't compile on all systems). diff --git a/bfd/tekhex.c b/bfd/tekhex.c index 99d54db..6599a4f 100644 --- a/bfd/tekhex.c +++ b/bfd/tekhex.c @@ -1008,6 +1008,7 @@ const bfd_target tekhex_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ diff --git a/bfd/trad-core.c b/bfd/trad-core.c index 1a4dbe6..14627cb 100644 --- a/bfd/trad-core.c +++ b/bfd/trad-core.c @@ -279,6 +279,7 @@ const bfd_target core_trad_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ diff --git a/bfd/verilog.c b/bfd/verilog.c index a54f6b0..94a9cc8 100644 --- a/bfd/verilog.c +++ b/bfd/verilog.c @@ -405,6 +405,7 @@ const bfd_target verilog_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c index 72d89e5..94001cc 100644 --- a/bfd/vms-alpha.c +++ b/bfd/vms-alpha.c @@ -9792,6 +9792,7 @@ const bfd_target alpha_vms_vec = ' ', /* ar_pad_char. */ 15, /* ar_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c index 3752b91..eaac8af 100644 --- a/bfd/vms-lib.c +++ b/bfd/vms-lib.c @@ -2403,6 +2403,7 @@ const bfd_target alpha_vms_lib_txt_vec = ' ', /* ar_pad_char. */ 15, /* ar_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, diff --git a/bfd/wasm-module.c b/bfd/wasm-module.c index 1fde4a5..dc13564 100644 --- a/bfd/wasm-module.c +++ b/bfd/wasm-module.c @@ -794,6 +794,7 @@ const bfd_target wasm_vec = ' ', /* AR_pad_char. */ 255, /* AR_max_namelen. */ 0, /* Match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ /* Routines to byte-swap various sized integers from the data sections. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, @@ -2298,6 +2298,7 @@ const bfd_target sym_vec = ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ |