From 174fd7f9556183397625dbfa99ef68ecd325c74b Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Mon, 9 Feb 2004 08:04:00 +0000 Subject: [PATCH] * bfd-elf.h (elf_backend_name_local_section_symbols): New hook. * elf.c (swap_out_syms): Use it to decide whether local section symbols should be named. * elfxx-target.h (elf_backend_name_local_section_symbols): New macro. * elfxx-mips.h (_bfd_mips_elf_name_local_section_symbols): Declare. (elf_backend_name_local_section_symbols): Define. * elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): New. --- bfd/ChangeLog | 10 ++++++++++ bfd/elf-bfd.h | 5 +++++ bfd/elf.c | 8 +++++++- bfd/elfxx-mips.c | 20 ++++++++++++++++++++ bfd/elfxx-mips.h | 4 ++++ bfd/elfxx-target.h | 4 ++++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 72a2e2ffa49..19b521c742a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2004-02-09 Richard Sandiford + + * bfd-elf.h (elf_backend_name_local_section_symbols): New hook. + * elf.c (swap_out_syms): Use it to decide whether local section + symbols should be named. + * elfxx-target.h (elf_backend_name_local_section_symbols): New macro. + * elfxx-mips.h (_bfd_mips_elf_name_local_section_symbols): Declare. + (elf_backend_name_local_section_symbols): Define. + * elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): New. + 2004-01-30 H.J. Lu * elfxx-ia64.c (elfNN_ia64_relax_brl): New function. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index c457a399f34..6bbacade36f 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -576,6 +576,11 @@ struct elf_backend_data int (*elf_backend_get_symbol_type) (Elf_Internal_Sym *, int); + /* Return true if local section symbols should have a non-null st_name. + NULL implies false. */ + bfd_boolean (*elf_backend_name_local_section_symbols) + (bfd *); + /* A function to do additional processing on the ELF section header just before writing it out. This is used to set the flags and type fields for some sections, or to actually write out data for diff --git a/bfd/elf.c b/bfd/elf.c index cd107bda035..82f778b308b 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5261,6 +5261,7 @@ swap_out_syms (bfd *abfd, char *outbound_shndx; int idx; bfd_size_type amt; + bfd_boolean name_local_sections; if (!elf_map_symbols (abfd)) return FALSE; @@ -5326,6 +5327,10 @@ swap_out_syms (bfd *abfd, outbound_shndx += sizeof (Elf_External_Sym_Shndx); } + name_local_sections + = (bed->elf_backend_name_local_section_symbols + && bed->elf_backend_name_local_section_symbols (abfd)); + syms = bfd_get_outsymbols (abfd); for (idx = 0; idx < symcount; idx++) { @@ -5335,7 +5340,8 @@ swap_out_syms (bfd *abfd, flagword flags = syms[idx]->flags; int type; - if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM) + if (!name_local_sections + && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM) { /* Local section symbols have no name. */ sym.st_name = 0; diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 7bcdb1115b3..a296458bf67 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -4271,6 +4271,26 @@ _bfd_mips_elf_symbol_processing (bfd *abfd, asymbol *asym) } } +/* There appears to be a bug in the MIPSpro linker that causes GOT_DISP + relocations against two unnamed section symbols to resolve to the + same address. For example, if we have code like: + + lw $4,%got_disp(.data)($gp) + lw $25,%got_disp(.text)($gp) + jalr $25 + + then the linker will resolve both relocations to .data and the program + will jump there rather than to .text. + + We can work around this problem by giving names to local section symbols. + This is also what the MIPSpro tools do. */ + +bfd_boolean +_bfd_mips_elf_name_local_section_symbols (bfd *abfd) +{ + return SGI_COMPAT (abfd); +} + /* Work over a section just before writing it out. This routine is used by both the 32-bit and the 64-bit ABI. FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by name; there has to be diff --git a/bfd/elfxx-mips.h b/bfd/elfxx-mips.h index d3787e9ef96..9e5d7afe427 100644 --- a/bfd/elfxx-mips.h +++ b/bfd/elfxx-mips.h @@ -24,6 +24,8 @@ extern bfd_boolean _bfd_mips_elf_new_section_hook (bfd *, asection *); extern void _bfd_mips_elf_symbol_processing (bfd *, asymbol *); +extern bfd_boolean _bfd_mips_elf_name_local_section_symbols + (bfd *); extern bfd_boolean _bfd_mips_elf_section_processing (bfd *, Elf_Internal_Shdr *); extern bfd_boolean _bfd_mips_elf_section_from_shdr @@ -119,4 +121,6 @@ extern bfd_vma _bfd_mips_elf_sign_extend (bfd_vma, int); extern struct bfd_elf_special_section const _bfd_mips_elf_special_sections[]; +#define elf_backend_name_local_section_symbols \ + _bfd_mips_elf_name_local_section_symbols #define elf_backend_special_sections _bfd_mips_elf_special_sections diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 40fe8e76ece..ca0e47b32e7 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -274,6 +274,9 @@ #ifndef elf_backend_get_symbol_type #define elf_backend_get_symbol_type 0 #endif +#ifndef elf_backend_name_local_section_symbols +#define elf_backend_name_local_section_symbols 0 +#endif #ifndef elf_backend_section_processing #define elf_backend_section_processing 0 #endif @@ -456,6 +459,7 @@ static const struct elf_backend_data elfNN_bed = elf_backend_symbol_processing, elf_backend_symbol_table_processing, elf_backend_get_symbol_type, + elf_backend_name_local_section_symbols, elf_backend_section_processing, elf_backend_section_from_shdr, elf_backend_section_flags, -- 2.30.2