From 7e2294f9378d28e2645b2db1d23053755a603c5c Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 21 Jul 2004 06:46:20 +0000 Subject: [PATCH] * elf-bfd.h (ELF_COMMON_DEF_P): New. * elflink.c (_bfd_elf_symbol_refs_local_p): Use it to handle common definitions. * elf-m10300.c: Use SYMBOL_REFERENCES_LOCAL instead of _bfd_elf_symbol_refs_local_p. * elf32-frv.c (FRVFDPIC_SYM_LOCAL): Remove hack for common symbols. --- bfd/ChangeLog | 10 ++++++++++ bfd/elf-bfd.h | 7 +++++++ bfd/elf-m10300.c | 10 +++++----- bfd/elf32-frv.c | 12 +----------- bfd/elflink.c | 6 +++++- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index aa3f6f80524..2f4b51952ca 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2004-07-21 Alexandre Oliva + + * elf-bfd.h (ELF_COMMON_DEF_P): New. + * elflink.c (_bfd_elf_symbol_refs_local_p): Use it to handle + common definitions. + * elf-m10300.c: Use SYMBOL_REFERENCES_LOCAL instead of + _bfd_elf_symbol_refs_local_p. + * elf32-frv.c (FRVFDPIC_SYM_LOCAL): Remove hack for common + symbols. + 2004-07-19 H.J. Lu * bfd-in.h (dynamic_lib_link_class): Add DYN_NO_ADD_NEEDED and diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 94a847d8d26..ee6089427eb 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -218,6 +218,13 @@ struct elf_link_hash_entry #define SYMBOL_CALLS_LOCAL(INFO, H) \ _bfd_elf_symbol_refs_local_p (H, INFO, 1) +/* Common symbols that are turned into definitions don't have the + DEF_REGULAR flag set, so they might appear to be undefined. */ +#define ELF_COMMON_DEF_P(H) \ + (((H)->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 \ + && ((H)->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 \ + && (H)->root.type == bfd_link_hash_defined) + /* Records local symbols to be emitted in the dynamic symbol table. */ struct elf_link_local_dynamic_entry diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index f41c118d24a..a83015d7647 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -1020,7 +1020,7 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, if (info->shared && (input_section->flags & SEC_ALLOC) != 0 && h != NULL - && ! _bfd_elf_symbol_refs_local_p (h, info, 1)) + && ! SYMBOL_REFERENCES_LOCAL (info, h)) return bfd_reloc_dangerous; } @@ -1079,7 +1079,7 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, /* h->dynindx may be -1 if this symbol was marked to become local. */ if (h == NULL - || _bfd_elf_symbol_refs_local_p (h, info, 1)) + || SYMBOL_REFERENCES_LOCAL (info, h)) { relocate = TRUE; outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE); @@ -1302,7 +1302,7 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, BFD_ASSERT (off != (bfd_vma) -1); if (! elf_hash_table (info)->dynamic_sections_created - || _bfd_elf_symbol_refs_local_p (h, info, 1)) + || SYMBOL_REFERENCES_LOCAL (info, h)) /* This is actually a static link, or it is a -Bsymbolic link and the symbol is defined locally, or the symbol was forced to be local @@ -1461,9 +1461,9 @@ mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section, || r_type == R_MN10300_GOT24 || r_type == R_MN10300_GOT16) && elf_hash_table (info)->dynamic_sections_created - && !_bfd_elf_symbol_refs_local_p (h, info, 1)) + && !SYMBOL_REFERENCES_LOCAL (info, hh)) || (r_type == R_MN10300_32 - && !_bfd_elf_symbol_refs_local_p (h, info, 1) + && !SYMBOL_REFERENCES_LOCAL (info, hh) && ((input_section->flags & SEC_ALLOC) != 0 /* DWARF will emit R_MN10300_32 relocations in its sections against symbols defined diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c index 3b64a0e8cf2..69d20bfe569 100644 --- a/bfd/elf32-frv.c +++ b/bfd/elf32-frv.c @@ -661,17 +661,7 @@ frvfdpic_elf_link_hash_table_create (bfd *abfd) its function descriptor must be assigned by the dynamic linker. */ #define FRVFDPIC_SYM_LOCAL(INFO, H) \ (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ - || ! elf_hash_table (INFO)->dynamic_sections_created \ - || (/* The condition below is an ugly hack to get .scommon data to - be regarded as local. For some reason the - ELF_LINK_HASH_DEF_REGULAR bit is not set on such common - symbols, and the SEC_IS_COMMON bit is not set any longer - when we need to perform this test. Hopefully this - approximation is good enough. */ \ - ((H)->root.type == bfd_link_hash_defined \ - || (H)->root.type == bfd_link_hash_defweak) \ - && (H)->root.u.def.section->output_section \ - && ((H)->root.u.def.section->flags & SEC_LINKER_CREATED))) + || ! elf_hash_table (INFO)->dynamic_sections_created) #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \ ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) diff --git a/bfd/elflink.c b/bfd/elflink.c index 4920d9da8f0..4fc24a358d3 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2456,9 +2456,13 @@ _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h, if (h == NULL) return TRUE; + /* Common symbols that become definitions don't get the DEF_REGULAR + flag set, so test it first, and don't bail out. */ + if (ELF_COMMON_DEF_P (h)) + /* Do nothing. */; /* If we don't have a definition in a regular file, then we can't resolve locally. The sym is either undefined or dynamic. */ - if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) + else if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) return FALSE; /* Forced local symbols resolve locally. */ -- 2.30.2