2005-06-27 H.J. Lu * elf-bfd.h (elf_backend_data): Add special_section, common_definition, common_section_index, common_section, and merge_symbol. (_bfd_elf_common_definition): New. (_bfd_elf_common_section_index): New. (_bfd_elf_common_section): New. * elf.c (elf_fake_sections): Don't clear sh_flags. * elflink.c (_bfd_elf_merge_symbol): Call backend merge_symbol if it is available. (is_global_data_symbol_definition): Call backend common_definition instead of checking SHN_COMMON. (elf_link_add_object_symbols): Likewise. (elf_link_output_extsym): Call backend common_section_index for common section index. (elf_link_input_bfd): Call backend special_section for unknown special section indices. (_bfd_elf_common_definition): New. (_bfd_elf_common_section_index): New. (_bfd_elf_common_section): New. * elfxx-target.h (elf_backend_common_definition): New. (elf_backend_common_section_index): New. (elf_backend_common_section): New. (elf_backend_special_section): New. (elf_backend_merge_symbol): New. (elfNN_bed): Initialize special_section, common_definition, common_section_index, common_section, and merge_symbol. * section.c (BFD_FAKE_SECTION): New. (STD_SECTION): Use it. * bfd-in2.h: Regenerated. --- bfd/elf-bfd.h.common 2005-06-27 10:05:29.908272947 -0700 +++ bfd/elf-bfd.h 2005-06-27 10:06:05.683368968 -0700 @@ -973,6 +973,33 @@ struct elf_backend_data see elf.c. */ bfd_vma (*plt_sym_val) (bfd_vma, const asection *, const arelent *); + /* Return the special section where symbol is defined. */ + asection *(*special_section) (Elf_Internal_Sym *); + + /* Is symbol defined in common section? */ + bfd_boolean (*common_definition) (Elf_Internal_Sym *); + + /* Return a common section index for section. */ + unsigned int (*common_section_index) (asection *); + + /* Return a common section for section. */ + asection *(*common_section) (asection *); + + /* Return TRUE if we can merge 2 definitions. */ + bfd_boolean (*merge_symbol) (struct bfd_link_info *, + struct elf_link_hash_entry **, + struct elf_link_hash_entry *, + Elf_Internal_Sym *, asection **, + bfd_vma *, unsigned int *, + bfd_boolean *, bfd_boolean *, + bfd_boolean *, bfd_boolean *, + bfd_boolean *, bfd_boolean *, + bfd_boolean *, bfd_boolean *, + bfd *, asection **, + bfd_boolean *, bfd_boolean *, + bfd_boolean *, bfd_boolean *, + bfd *, asection **); + /* Used to handle bad SHF_LINK_ORDER input. */ bfd_error_handler_type link_order_error_handler; @@ -1747,6 +1774,15 @@ extern int bfd_elf_link_record_local_dyn extern bfd_boolean _bfd_elf_close_and_cleanup (bfd *); +extern bfd_boolean _bfd_elf_common_definition + (Elf_Internal_Sym *); + +extern unsigned int _bfd_elf_common_section_index + (asection *); + +extern asection *_bfd_elf_common_section + (asection *); + extern void _bfd_dwarf2_cleanup_debug_info (bfd *); --- bfd/elf.c.common 2005-06-27 10:05:29.913272122 -0700 +++ bfd/elf.c 2005-06-27 10:05:29.935268492 -0700 @@ -2626,7 +2626,7 @@ elf_fake_sections (bfd *abfd, asection * return; } - this_hdr->sh_flags = 0; + /* Don't clear sh_flags. Assembler may set additional bits. */ if ((asect->flags & SEC_ALLOC) != 0 || asect->user_set_vma) --- bfd/elflink.c.common 2005-06-27 10:05:29.885276742 -0700 +++ bfd/elflink.c 2005-06-27 10:06:05.689367978 -0700 @@ -783,6 +783,7 @@ _bfd_elf_merge_symbol (bfd *abfd, bfd *oldbfd; bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon; bfd_boolean newweak, oldweak; + const struct elf_backend_data *bed; *skip = FALSE; *override = FALSE; @@ -960,6 +961,17 @@ _bfd_elf_merge_symbol (bfd *abfd, return FALSE; } + bed = get_elf_backend_data (abfd); + if (bed->merge_symbol + && !bed->merge_symbol (info, sym_hash, h, sym, psec, pvalue, + pold_alignment, skip, override, + type_change_ok, size_change_ok, + &newdyn, &newdef, &newdyncommon, &newweak, + abfd, &sec, + &olddyn, &olddef, &olddyncommon, &oldweak, + oldbfd, &oldsec)) + return FALSE; + /* We need to remember if a symbol has a definition in a dynamic object or is weak in all dynamic objects. Internal and hidden visibility will make it unavailable to dynamic objects. */ @@ -1200,7 +1212,7 @@ _bfd_elf_merge_symbol (bfd *abfd, newdef = FALSE; newdyncommon = FALSE; *pvalue = sym->st_size; - *psec = sec = bfd_com_section_ptr; + *psec = sec = bed->common_section (oldsec); *size_change_ok = TRUE; } @@ -2664,6 +2676,8 @@ static bfd_boolean is_global_data_symbol_definition (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Sym *sym) { + const struct elf_backend_data *bed; + /* Local symbols do not count, but target specific ones might. */ if (ELF_ST_BIND (sym->st_info) != STB_GLOBAL && ELF_ST_BIND (sym->st_info) < STB_LOOS) @@ -2679,7 +2693,8 @@ is_global_data_symbol_definition (bfd *a /* If the symbol is defined in the common section, then it is a common definition and so does not count. */ - if (sym->st_shndx == SHN_COMMON) + bed = get_elf_backend_data (abfd); + if (bed->common_definition (sym)) return FALSE; /* If the symbol is in a target specific section then we @@ -3571,6 +3586,7 @@ elf_link_add_object_symbols (bfd *abfd, bfd_boolean type_change_ok; bfd_boolean new_weakdef; bfd_boolean override; + bfd_boolean common; unsigned int old_alignment; bfd *old_bfd; @@ -3580,6 +3596,7 @@ elf_link_add_object_symbols (bfd *abfd, sec = NULL; value = isym->st_value; *sym_hash = NULL; + common = bed->common_definition (isym); bind = ELF_ST_BIND (isym->st_info); if (bind == STB_LOCAL) @@ -3592,8 +3609,7 @@ elf_link_add_object_symbols (bfd *abfd, } else if (bind == STB_GLOBAL) { - if (isym->st_shndx != SHN_UNDEF - && isym->st_shndx != SHN_COMMON) + if (isym->st_shndx != SHN_UNDEF && !common) flags = BSF_GLOBAL; } else if (bind == STB_WEAK) @@ -3883,13 +3899,12 @@ elf_link_add_object_symbols (bfd *abfd, } /* Set the alignment of a common symbol. */ - if ((isym->st_shndx == SHN_COMMON - || bfd_is_com_section (sec)) + if ((common || bfd_is_com_section (sec)) && h->root.type == bfd_link_hash_common) { unsigned int align; - if (isym->st_shndx == SHN_COMMON) + if (common) align = bfd_log2 (isym->st_value); else { @@ -3915,7 +3930,7 @@ elf_link_add_object_symbols (bfd *abfd, definition or a common symbol is ignored due to the old normal definition. We need to make sure the maximum alignment is maintained. */ - if ((old_alignment || isym->st_shndx == SHN_COMMON) + if ((old_alignment || common) && h->root.type != bfd_link_hash_common) { unsigned int common_align; @@ -6528,7 +6543,7 @@ elf_link_output_extsym (struct elf_link_ case bfd_link_hash_common: input_sec = h->root.u.c.p->section; - sym.st_shndx = SHN_COMMON; + sym.st_shndx = bed->common_section_index (input_sec); sym.st_value = 1 << h->root.u.c.p->alignment_power; break; @@ -6882,6 +6897,8 @@ elf_link_input_bfd (struct elf_final_lin isec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) isec = bfd_com_section_ptr; + else if (bed->special_section) + isec = bed->special_section (isym); else { /* Who knows? */ @@ -9906,3 +9923,21 @@ _bfd_elf_provide_section_bound_symbols ( if (do_end) bfd_elf_set_symbol (he, end_val); } + +bfd_boolean +_bfd_elf_common_definition (Elf_Internal_Sym *sym) +{ + return sym->st_shndx == SHN_COMMON; +} + +unsigned int +_bfd_elf_common_section_index (asection *sec ATTRIBUTE_UNUSED) +{ + return SHN_COMMON; +} + +asection * +_bfd_elf_common_section (asection *sec ATTRIBUTE_UNUSED) +{ + return bfd_com_section_ptr; +} --- bfd/elfxx-target.h.common 2005-06-27 10:05:29.920270967 -0700 +++ bfd/elfxx-target.h 2005-06-27 10:05:29.943267172 -0700 @@ -522,6 +522,26 @@ #define elf_backend_link_order_error_handler _bfd_default_error_handler #endif +#ifndef elf_backend_common_definition +#define elf_backend_common_definition _bfd_elf_common_definition +#endif + +#ifndef elf_backend_common_section_index +#define elf_backend_common_section_index _bfd_elf_common_section_index +#endif + +#ifndef elf_backend_common_section +#define elf_backend_common_section _bfd_elf_common_section +#endif + +#ifndef elf_backend_special_section +#define elf_backend_special_section NULL +#endif + +#ifndef elf_backend_merge_symbol +#define elf_backend_merge_symbol NULL +#endif + extern const struct elf_size_info _bfd_elfNN_size_info; #ifndef INCLUDED_TARGET_FILE @@ -591,6 +611,11 @@ static const struct elf_backend_data elf elf_backend_ecoff_debug_swap, elf_backend_bfd_from_remote_memory, elf_backend_plt_sym_val, + elf_backend_special_section, + elf_backend_common_definition, + elf_backend_common_section_index, + elf_backend_common_section, + elf_backend_merge_symbol, elf_backend_link_order_error_handler, elf_backend_relplt_name, ELF_MACHINE_ALT1, --- bfd/section.c.common 2005-05-18 10:37:28.000000000 -0700 +++ bfd/section.c 2005-06-27 10:05:29.945266842 -0700 @@ -634,6 +634,47 @@ CODE_FRAGMENT .#define bfd_section_removed_from_list(ABFD, S) \ . ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S)) . +.#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, SYM_PTR, NAME, IDX) \ +. {* name, id, index, next, prev, flags, user_set_vma, *} \ +. { NAME, IDX, 0, NULL, NULL, FLAGS, 0, \ +. \ +. {* linker_mark, linker_has_input, gc_mark, segment_mark, *} \ +. 0, 0, 1, 0, \ +. \ +. {* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc, *} \ +. 0, 0, 0, 0, \ +. \ +. {* need_finalize_relax, reloc_done, *} \ +. 0, 0, \ +. \ +. {* vma, lma, size, rawsize *} \ +. 0, 0, 0, 0, \ +. \ +. {* output_offset, output_section, alignment_power, *} \ +. 0, (struct bfd_section *) &SEC, 0, \ +. \ +. {* relocation, orelocation, reloc_count, filepos, rel_filepos, *} \ +. NULL, NULL, 0, 0, 0, \ +. \ +. {* line_filepos, userdata, contents, lineno, lineno_count, *} \ +. 0, NULL, NULL, NULL, 0, \ +. \ +. {* entsize, kept_section, moving_line_filepos, *} \ +. 0, NULL, 0, \ +. \ +. {* target_index, used_by_bfd, constructor_chain, owner, *} \ +. 0, NULL, NULL, NULL, \ +. \ +. {* symbol, *} \ +. (struct bfd_symbol *) SYM, \ +. \ +. {* symbol_ptr_ptr, *} \ +. (struct bfd_symbol **) SYM_PTR, \ +. \ +. {* map_head, map_tail *} \ +. { NULL }, { NULL } \ +. } +. */ /* We use a macro to initialize the static asymbol structures because @@ -661,46 +702,8 @@ static const asymbol global_syms[] = #define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX) \ const asymbol * const SYM = (asymbol *) &global_syms[IDX]; \ - asection SEC = \ - /* name, id, index, next, prev, flags, user_set_vma, */ \ - { NAME, IDX, 0, NULL, NULL, FLAGS, 0, \ - \ - /* linker_mark, linker_has_input, gc_mark, segment_mark, */ \ - 0, 0, 1, 0, \ - \ - /* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc, */ \ - 0, 0, 0, 0, \ - \ - /* need_finalize_relax, reloc_done, */ \ - 0, 0, \ - \ - /* vma, lma, size, rawsize */ \ - 0, 0, 0, 0, \ - \ - /* output_offset, output_section, alignment_power, */ \ - 0, (struct bfd_section *) &SEC, 0, \ - \ - /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \ - NULL, NULL, 0, 0, 0, \ - \ - /* line_filepos, userdata, contents, lineno, lineno_count, */ \ - 0, NULL, NULL, NULL, 0, \ - \ - /* entsize, kept_section, moving_line_filepos, */ \ - 0, NULL, 0, \ - \ - /* target_index, used_by_bfd, constructor_chain, owner, */ \ - 0, NULL, NULL, NULL, \ - \ - /* symbol, */ \ - (struct bfd_symbol *) &global_syms[IDX], \ - \ - /* symbol_ptr_ptr, */ \ - (struct bfd_symbol **) &SYM, \ - \ - /* map_head, map_tail */ \ - { NULL }, { NULL } \ - } + asection SEC = BFD_FAKE_SECTION(SEC, FLAGS, &global_syms[IDX], &SYM, \ + NAME, IDX) STD_SECTION (bfd_com_section, SEC_IS_COMMON, bfd_com_symbol, BFD_COM_SECTION_NAME, 0);