X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felf.c;h=d22e57b6f8477d48324891394dca5fc8b9d4e646;hb=125c4a69c4572195571873dccbc31434bba53ddd;hp=3f500d67543fb7e2cae72790357cbad031dcb8c2;hpb=ee44def1eaa29493c81e711daafaf5e54f2d7eb4;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf.c b/bfd/elf.c index 3f500d6754..d22e57b6f8 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -31,6 +31,10 @@ SECTION haven't bothered yet. */ +#ifdef __sparcv9 +#define _SYSCALL32 /* For Sparc64-cross-32 */ +#endif + #include "bfd.h" #include "sysdep.h" #include "bfdlink.h" @@ -950,7 +954,8 @@ _bfd_elf_link_hash_copy_indirect (dir, ind) } void -_bfd_elf_link_hash_hide_symbol(h) +_bfd_elf_link_hash_hide_symbol(info, h) + struct bfd_link_info *info ATTRIBUTE_UNUSED; struct elf_link_hash_entry *h; { h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; @@ -977,6 +982,7 @@ _bfd_elf_link_hash_table_init (table, abfd, newfunc) table->needed = NULL; table->hgot = NULL; table->stab_info = NULL; + table->dynlocal = NULL; return _bfd_link_hash_table_init (&table->root, abfd, newfunc); } @@ -1327,8 +1333,10 @@ bfd_section_from_shdr (abfd, shindex) /* If this reloc section does not use the main symbol table we don't treat it as a reloc section. BFD can't adequately represent such a section, so at least for now, we don't - try. We just present it as a normal section. */ - if (hdr->sh_link != elf_onesymtab (abfd)) + try. We just present it as a normal section. We also + can't use it as a reloc section if it points to the null + section. */ + if (hdr->sh_link != elf_onesymtab (abfd) || hdr->sh_info == SHN_UNDEF) return _bfd_elf_make_section_from_shdr (abfd, hdr, name); if (! bfd_section_from_shdr (abfd, hdr->sh_info)) @@ -1354,8 +1362,9 @@ bfd_section_from_shdr (abfd, shindex) target_sect->rel_filepos = hdr->sh_offset; /* In the section to which the relocations apply, mark whether its relocations are of the REL or RELA variety. */ - elf_section_data (target_sect)->use_rela_p - = (hdr->sh_type == SHT_RELA); + if (hdr->sh_size != 0) + elf_section_data (target_sect)->use_rela_p + = (hdr->sh_type == SHT_RELA); abfd->flags |= HAS_RELOC; return true; } @@ -1764,7 +1773,6 @@ assign_section_numbers (abfd) asection *sec; unsigned int section_number; Elf_Internal_Shdr **i_shdrp; - struct elf_backend_data *bed = get_elf_backend_data (abfd); section_number = 1; @@ -1899,7 +1907,7 @@ assign_section_numbers (abfd) /* This is a .stab section. */ elf_section_data (s)->this_hdr.sh_entsize = - 4 + 2 * (bed->s->arch_size / 8); + 4 + 2 * bfd_get_arch_size (abfd) / 8; } } break; @@ -2901,18 +2909,21 @@ assign_file_positions_for_segments (abfd) if (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core) { - if (i == 0) /* the actual "note" segment */ - { /* this one actually contains everything. */ + /* The actual "note" segment has i == 0. + This is the one that actually contains everything. */ + if (i == 0) + { sec->filepos = off; p->p_filesz = sec->_raw_size; off += sec->_raw_size; voff = off; } - else /* fake sections -- don't need to be written */ + else { + /* Fake sections -- don't need to be written. */ sec->filepos = 0; sec->_raw_size = 0; - flags = sec->flags = 0; /* no contents */ + flags = sec->flags = 0; } p->p_memsz = 0; p->p_align = 1; @@ -3226,7 +3237,7 @@ prep_headers (abfd) i_ehdrp->e_machine = EM_NONE; break; case bfd_arch_sparc: - if (bed->s->arch_size == 64) + if (bfd_get_arch_size (abfd) == 64) i_ehdrp->e_machine = EM_SPARCV9; else i_ehdrp->e_machine = EM_SPARC; @@ -3240,6 +3251,12 @@ prep_headers (abfd) case bfd_arch_ia64: i_ehdrp->e_machine = EM_IA_64; break; + case bfd_arch_m68hc11: + i_ehdrp->e_machine = EM_68HC11; + break; + case bfd_arch_m68hc12: + i_ehdrp->e_machine = EM_68HC12; + break; case bfd_arch_m68k: i_ehdrp->e_machine = EM_68K; break; @@ -3729,7 +3746,7 @@ copy_private_bfd_data (ibfd, obfd) more to do. */ isec = 0; - matching_lma = false; + matching_lma = 0; suggested_lma = 0; for (j = 0, s = ibfd->sections; s != NULL; s = s->next) @@ -3795,21 +3812,32 @@ copy_private_bfd_data (ibfd, obfd) free (sections); continue; } - else if (matching_lma != 0) - { - /* At least one section fits inside the current segment. - Keep it, but modify its physical address to match the - LMA of the first section that fitted. */ - - m->p_paddr = matching_lma; - } else { - /* None of the sections fitted inside the current segment. - Change the current segment's physical address to match - the LMA of the first section. */ + if (matching_lma != 0) + { + /* At least one section fits inside the current segment. + Keep it, but modify its physical address to match the + LMA of the first section that fitted. */ - m->p_paddr = suggested_lma; + m->p_paddr = matching_lma; + } + else + { + /* None of the sections fitted inside the current segment. + Change the current segment's physical address to match + the LMA of the first section. */ + + m->p_paddr = suggested_lma; + } + + /* Offset the segment physical address from the lma to allow + for space taken up by elf headers. */ + if (m->includes_filehdr) + m->p_paddr -= iehdr->e_ehsize; + + if (m->includes_phdrs) + m->p_paddr -= iehdr->e_phnum * iehdr->e_phentsize; } /* Step Three: Loop over the sections again, this time assigning @@ -3842,7 +3870,12 @@ copy_private_bfd_data (ibfd, obfd) { /* If the first section in a segment does not start at the beginning of the segment, then something is wrong. */ - if (os->lma != m->p_paddr) + if (os->lma != (m->p_paddr + + (m->includes_filehdr + ? iehdr->e_ehsize : 0) + + (m->includes_phdrs + ? iehdr->e_phnum * iehdr->e_phentsize + : 0))) abort (); } else @@ -4473,18 +4506,13 @@ _bfd_elf_slurp_version_tables (abfd) Elf_Internal_Shdr *hdr; Elf_External_Verdef *everdef; Elf_Internal_Verdef *iverdef; + Elf_Internal_Verdef *iverdefarr; + Elf_Internal_Verdef iverdefmem; unsigned int i; + unsigned int maxidx; hdr = &elf_tdata (abfd)->dynverdef_hdr; - elf_tdata (abfd)->verdef = - ((Elf_Internal_Verdef *) - bfd_zalloc (abfd, hdr->sh_info * sizeof (Elf_Internal_Verdef))); - if (elf_tdata (abfd)->verdef == NULL) - goto error_return; - - elf_tdata (abfd)->cverdefs = hdr->sh_info; - contents = (bfd_byte *) bfd_malloc (hdr->sh_size); if (contents == NULL) goto error_return; @@ -4492,15 +4520,42 @@ _bfd_elf_slurp_version_tables (abfd) || bfd_read ((PTR) contents, 1, hdr->sh_size, abfd) != hdr->sh_size) goto error_return; + /* We know the number of entries in the section but not the maximum + index. Therefore we have to run through all entries and find + the maximum. */ + everdef = (Elf_External_Verdef *) contents; + maxidx = 0; + for (i = 0; i < hdr->sh_info; ++i) + { + _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem); + + if ((iverdefmem.vd_ndx & VERSYM_VERSION) > maxidx) + maxidx = iverdefmem.vd_ndx & VERSYM_VERSION; + + everdef = ((Elf_External_Verdef *) + ((bfd_byte *) everdef + iverdefmem.vd_next)); + } + + elf_tdata (abfd)->verdef = + ((Elf_Internal_Verdef *) + bfd_zalloc (abfd, maxidx * sizeof (Elf_Internal_Verdef))); + if (elf_tdata (abfd)->verdef == NULL) + goto error_return; + + elf_tdata (abfd)->cverdefs = maxidx; + everdef = (Elf_External_Verdef *) contents; - iverdef = elf_tdata (abfd)->verdef; - for (i = 0; i < hdr->sh_info; i++, iverdef++) + iverdefarr = elf_tdata (abfd)->verdef; + for (i = 0; i < hdr->sh_info; i++) { Elf_External_Verdaux *everdaux; Elf_Internal_Verdaux *iverdaux; unsigned int j; - _bfd_elf_swap_verdef_in (abfd, everdef, iverdef); + _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem); + + iverdef = &iverdefarr[(iverdefmem.vd_ndx & VERSYM_VERSION) - 1]; + memcpy (iverdef, &iverdefmem, sizeof (Elf_Internal_Verdef)); iverdef->vd_bfd = abfd; @@ -5051,7 +5106,7 @@ elfcore_maybe_make_sect (abfd, name, sect) /* prstatus_t exists on: - solaris 2.[567] + solaris 2.5+ linux 2.[01] + glibc unixware 4.2 */ @@ -5062,28 +5117,60 @@ elfcore_grok_prstatus (abfd, note) bfd* abfd; Elf_Internal_Note* note; { - prstatus_t prstat; char buf[100]; char* name; asection* sect; + int raw_size; - if (note->descsz != sizeof (prstat)) - return true; + if (note->descsz == sizeof (prstatus_t)) + { + prstatus_t prstat; - memcpy (&prstat, note->descdata, sizeof (prstat)); + raw_size = sizeof (prstat.pr_reg); + memcpy (&prstat, note->descdata, sizeof (prstat)); - elf_tdata (abfd)->core_signal = prstat.pr_cursig; - elf_tdata (abfd)->core_pid = prstat.pr_pid; + elf_tdata (abfd)->core_signal = prstat.pr_cursig; + elf_tdata (abfd)->core_pid = prstat.pr_pid; - /* pr_who exists on: - solaris 2.[567] - unixware 4.2 - pr_who doesn't exist on: - linux 2.[01] - */ + /* pr_who exists on: + solaris 2.5+ + unixware 4.2 + pr_who doesn't exist on: + linux 2.[01] + */ #if defined (HAVE_PRSTATUS_T_PR_WHO) - elf_tdata (abfd)->core_lwpid = prstat.pr_who; + elf_tdata (abfd)->core_lwpid = prstat.pr_who; #endif + } +#if defined (__sparcv9) + else if (note->descsz == sizeof (prstatus32_t)) + { + /* 64-bit host, 32-bit corefile */ + prstatus32_t prstat; + + raw_size = sizeof (prstat.pr_reg); + memcpy (&prstat, note->descdata, sizeof (prstat)); + + elf_tdata (abfd)->core_signal = prstat.pr_cursig; + elf_tdata (abfd)->core_pid = prstat.pr_pid; + + /* pr_who exists on: + solaris 2.5+ + unixware 4.2 + pr_who doesn't exist on: + linux 2.[01] + */ +#if defined (HAVE_PRSTATUS_T_PR_WHO) + elf_tdata (abfd)->core_lwpid = prstat.pr_who; +#endif + } +#endif /* __sparcv9 */ + else + { + /* Fail - we don't know how to handle any other + note size (ie. data object type). */ + return true; + } /* Make a ".reg/999" section. */ @@ -5096,8 +5183,20 @@ elfcore_grok_prstatus (abfd, note) sect = bfd_make_section (abfd, name); if (sect == NULL) return false; - sect->_raw_size = sizeof (prstat.pr_reg); - sect->filepos = note->descpos + offsetof (prstatus_t, pr_reg); + + if (note->descsz == sizeof (prstatus_t)) + { + sect->_raw_size = raw_size; + sect->filepos = note->descpos + offsetof (prstatus_t, pr_reg); + } +#if defined (__sparcv9) + else if (note->descsz == sizeof (prstatus32_t)) + { + sect->_raw_size = raw_size; + sect->filepos = note->descpos + offsetof (prstatus32_t, pr_reg); + } +#endif + sect->flags = SEC_HAS_CONTENTS; sect->alignment_power = 2; @@ -5175,11 +5274,17 @@ elfcore_grok_prxfpreg (abfd, note) #if defined (HAVE_PRPSINFO_T) -# define elfcore_psinfo_t prpsinfo_t +typedef prpsinfo_t elfcore_psinfo_t; +#if defined (__sparcv9) /* Sparc64 cross Sparc32 */ +typedef prpsinfo32_t elfcore_psinfo32_t; +#endif #endif #if defined (HAVE_PSINFO_T) -# define elfcore_psinfo_t psinfo_t +typedef psinfo_t elfcore_psinfo_t; +#if defined (__sparcv9) /* Sparc64 cross Sparc32 */ +typedef psinfo32_t elfcore_psinfo32_t; +#endif #endif @@ -5219,18 +5324,40 @@ elfcore_grok_psinfo (abfd, note) bfd* abfd; Elf_Internal_Note* note; { - elfcore_psinfo_t psinfo; + if (note->descsz == sizeof (elfcore_psinfo_t)) + { + elfcore_psinfo_t psinfo; - if (note->descsz != sizeof (elfcore_psinfo_t)) - return true; + memcpy (&psinfo, note->descdata, note->descsz); + + elf_tdata (abfd)->core_program + = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); + + elf_tdata (abfd)->core_command + = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); + } +#if defined (__sparcv9) + else if (note->descsz == sizeof (elfcore_psinfo32_t)) + { + /* 64-bit host, 32-bit corefile */ + elfcore_psinfo32_t psinfo; + + memcpy (&psinfo, note->descdata, note->descsz); - memcpy (&psinfo, note->descdata, note->descsz); + elf_tdata (abfd)->core_program + = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); - elf_tdata (abfd)->core_program - = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); + elf_tdata (abfd)->core_command + = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); + } +#endif - elf_tdata (abfd)->core_command - = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); + else + { + /* Fail - we don't know how to handle any other + note size (ie. data object type). */ + return true; + } /* Note that for some reason, a spurious space is tacked onto the end of the args in some (at least one anyway) @@ -5255,15 +5382,25 @@ elfcore_grok_pstatus (abfd, note) bfd* abfd; Elf_Internal_Note* note; { - pstatus_t pstat; + if (note->descsz == sizeof (pstatus_t)) + { + pstatus_t pstat; - if (note->descsz != sizeof (pstat)) - return true; + memcpy (&pstat, note->descdata, sizeof (pstat)); - memcpy (&pstat, note->descdata, sizeof (pstat)); + elf_tdata (abfd)->core_pid = pstat.pr_pid; + } +#if defined (__sparcv9) + else if (note->descsz == sizeof (pstatus32_t)) + { + /* 64-bit host, 32-bit corefile */ + pstatus32_t pstat; - elf_tdata (abfd)->core_pid = pstat.pr_pid; + memcpy (&pstat, note->descdata, sizeof (pstat)); + elf_tdata (abfd)->core_pid = pstat.pr_pid; + } +#endif /* Could grab some more details from the "representative" lwpstatus_t in pstat.pr_lwp, but we'll catch it all in an NT_LWPSTATUS note, presumably. */