if (bfd_elf_get_str_section (abfd, shindex) == NULL)
return NULL;
}
+ else
+ {
+ /* PR 24273: The string section's contents may have already
+ been loaded elsewhere, eg because a corrupt file has the
+ string section index in the ELF header pointing at a group
+ section. So be paranoid, and test that the last byte of
+ the section is zero. */
+ if (hdr->sh_size == 0 || hdr->contents[hdr->sh_size - 1] != 0)
+ return NULL;
+ }
if (strindex >= hdr->sh_size)
{
BFD_ASSERT (sizeof (*dest) >= 4);
amt = shdr->sh_size * sizeof (*dest) / 4;
shdr->contents = (unsigned char *)
- bfd_alloc2 (abfd, shdr->sh_size, sizeof (*dest) / 4);
+ bfd_alloc2 (abfd, shdr->sh_size, sizeof (*dest) / 4);
/* PR binutils/4110: Handle corrupt group headers. */
if (shdr->contents == NULL)
{
sections_being_created = NULL;
if (sections_being_created == NULL)
{
- /* FIXME: It would be more efficient to attach this array to the bfd somehow. */
sections_being_created = (bfd_boolean *)
- bfd_zalloc (abfd, elf_numsections (abfd) * sizeof (bfd_boolean));
+ bfd_zalloc2 (abfd, elf_numsections (abfd), sizeof (bfd_boolean));
sections_being_created_abfd = abfd;
}
if (sections_being_created [shindex])
if (entry->ndx == shindex)
goto success;
- entry = bfd_alloc (abfd, sizeof * entry);
+ entry = bfd_alloc (abfd, sizeof (*entry));
if (entry == NULL)
goto fail;
entry->ndx = shindex;
/* Ignore linker created group section. See elfNN_ia64_object_p in
elfxx-ia64.c. */
- if (((sec->flags & (SEC_GROUP | SEC_LINKER_CREATED)) != SEC_GROUP)
+ if ((sec->flags & (SEC_GROUP | SEC_LINKER_CREATED)) != SEC_GROUP
+ || sec->size == 0
|| *failedptr)
return;
_bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name);
if (section_number > ((SHN_LORESERVE - 2) & 0xFFFF))
{
- elf_section_list * entry;
+ elf_section_list *entry;
BFD_ASSERT (elf_symtab_shndx_list (abfd) == NULL);
- entry = bfd_zalloc (abfd, sizeof * entry);
+ entry = bfd_zalloc (abfd, sizeof (*entry));
entry->ndx = section_number++;
elf_symtab_shndx_list (abfd) = entry;
entry->hdr.sh_name
symstrtab_hdr->sh_type = SHT_STRTAB;
/* Allocate buffer to swap out the .strtab section. */
- symstrtab = (struct elf_sym_strtab *) bfd_malloc ((symcount + 1)
- * sizeof (*symstrtab));
+ symstrtab = (struct elf_sym_strtab *) bfd_malloc2 (symcount + 1,
+ sizeof (*symstrtab));
if (symstrtab == NULL)
{
_bfd_elf_strtab_free (stt);
_bfd_elf_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
sec_ptr asect)
{
+#if SIZEOF_LONG == SIZEOF_INT
+ if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
+ {
+ bfd_set_error (bfd_error_file_too_big);
+ return -1;
+ }
+#endif
return (asect->reloc_count + 1) * sizeof (arelent *);
}
{
elf_symbol_type *newsym;
- newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof * newsym);
+ newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof (*newsym));
if (!newsym)
return NULL;
newsym->symbol.the_bfd = abfd;
return elfcore_maybe_make_sect (abfd, name, sect);
}
+static bfd_boolean
+elfcore_make_auxv_note_section (bfd *abfd, Elf_Internal_Note *note,
+ size_t offs)
+{
+ asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv",
+ SEC_HAS_CONTENTS);
+
+ if (sect == NULL)
+ return FALSE;
+
+ sect->size = note->descsz - offs;
+ sect->filepos = note->descpos + offs;
+ sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
+
+ return TRUE;
+}
+
/* prstatus_t exists on:
solaris 2.5+
linux 2.[01] + glibc
return elfcore_make_note_pseudosection (abfd, ".reg-aarch-sve", note);
}
+static bfd_boolean
+elfcore_grok_aarch_pauth (bfd *abfd, Elf_Internal_Note *note)
+{
+ return elfcore_make_note_pseudosection (abfd, ".reg-aarch-pauth", note);
+}
+
#if defined (HAVE_PRPSINFO_T)
typedef prpsinfo_t elfcore_psinfo_t;
#if defined (HAVE_PRPSINFO32_T) /* Sparc64 cross Sparc32 */
case NT_PPC_TAR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tar (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tar (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_PPR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_ppr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_ppr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_DSCR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_dscr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_dscr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_EBB:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_ebb (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_ebb (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_PMU:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_pmu (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_pmu (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CGPR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_cgpr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_cgpr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CFPR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_cfpr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_cfpr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CVMX:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_cvmx (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_cvmx (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CVSX:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_cvsx (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_cvsx (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_SPR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_spr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_spr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CTAR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_ctar (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_ctar (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CPPR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_cppr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_cppr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_PPC_TM_CDSCR:
if (note->namesz == 6
- && strcmp (note->namedata, "LINUX") == 0)
- return elfcore_grok_ppc_tm_cdscr (abfd, note);
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_ppc_tm_cdscr (abfd, note);
else
- return TRUE;
+ return TRUE;
case NT_S390_HIGH_GPRS:
if (note->namesz == 6
else
return TRUE;
+ case NT_ARM_PAC_MASK:
+ if (note->namesz == 6
+ && strcmp (note->namedata, "LINUX") == 0)
+ return elfcore_grok_aarch_pauth (abfd, note);
+ else
+ return TRUE;
+
case NT_PRPSINFO:
case NT_PSINFO:
if (bed->elf_backend_grok_psinfo)
#endif
case NT_AUXV:
- {
- asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv",
- SEC_HAS_CONTENTS);
-
- if (sect == NULL)
- return FALSE;
- sect->size = note->descsz;
- sect->filepos = note->descpos;
- sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
-
- return TRUE;
- }
+ return elfcore_make_auxv_note_section (abfd, note, 0);
case NT_FILE:
return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.file",
elfobj_grok_stapsdt_note_1 (bfd *abfd, Elf_Internal_Note *note)
{
struct sdt_note *cur =
- (struct sdt_note *) bfd_alloc (abfd, sizeof (struct sdt_note)
- + note->descsz);
+ (struct sdt_note *) bfd_alloc (abfd,
+ sizeof (struct sdt_note) + note->descsz);
cur->next = (struct sdt_note *) (elf_tdata (abfd))->sdt_note_head;
cur->size = (bfd_size_type) note->descsz;
note);
case NT_FREEBSD_PROCSTAT_AUXV:
- {
- asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv",
- SEC_HAS_CONTENTS);
-
- if (sect == NULL)
- return FALSE;
- sect->size = note->descsz - 4;
- sect->filepos = note->descpos + 4;
- sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
-
- return TRUE;
- }
+ return elfcore_make_auxv_note_section (abfd, note, 4);
case NT_X86_XSTATE:
if (note->namesz == 8)
if (elfcore_netbsd_get_lwpid (note, &lwp))
elf_tdata (abfd)->core->lwpid = lwp;
- if (note->type == NT_NETBSDCORE_PROCINFO)
+ switch (note->type)
{
+ case NT_NETBSDCORE_PROCINFO:
/* NetBSD-specific core "procinfo". Note that we expect to
find this note before any of the others, which is fine,
since the kernel writes this note out first when it
creates a core file. */
-
return elfcore_grok_netbsd_procinfo (abfd, note);
+#ifdef NT_NETBSDCORE_AUXV
+ case NT_NETBSDCORE_AUXV:
+ /* NetBSD-specific Elf Auxiliary Vector data. */
+ return elfcore_make_auxv_note_section (abfd, note, 4);
+#endif
+ default:
+ break;
}
- /* As of Jan 2002 there are no other machine-independent notes
+ /* As of March 2017 there are no other machine-independent notes
defined for NetBSD core files. If the note type is less
than the start of the machine-dependent note types, we don't
understand it. */
return TRUE;
}
+ /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
+ There's also old PT___GETREGS40 == mach + 1 for old reg
+ structure which lacks GBR. */
+
+ case bfd_arch_sh:
+ switch (note->type)
+ {
+ case NT_NETBSDCORE_FIRSTMACH+3:
+ return elfcore_make_note_pseudosection (abfd, ".reg", note);
+
+ case NT_NETBSDCORE_FIRSTMACH+5:
+ return elfcore_make_note_pseudosection (abfd, ".reg2", note);
+
+ default:
+ return TRUE;
+ }
+
/* On all other arch's, PT_GETREGS == mach+1 and
PT_GETFPREGS == mach+3. */
return elfcore_make_note_pseudosection (abfd, ".reg-xfp", note);
if (note->type == NT_OPENBSD_AUXV)
- {
- asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv",
- SEC_HAS_CONTENTS);
-
- if (sect == NULL)
- return FALSE;
- sect->size = note->descsz;
- sect->filepos = note->descpos;
- sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
-
- return TRUE;
- }
+ return elfcore_make_auxv_note_section (abfd, note, 0);
if (note->type == NT_OPENBSD_WCOOKIE)
{
char *
elfcore_write_ppc_tar (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tar,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tar,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TAR, ppc_tar, size);
+ note_name, NT_PPC_TAR, ppc_tar, size);
}
char *
elfcore_write_ppc_ppr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_ppr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_ppr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_PPR, ppc_ppr, size);
+ note_name, NT_PPC_PPR, ppc_ppr, size);
}
char *
elfcore_write_ppc_dscr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_dscr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_dscr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_DSCR, ppc_dscr, size);
+ note_name, NT_PPC_DSCR, ppc_dscr, size);
}
char *
elfcore_write_ppc_ebb (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_ebb,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_ebb,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_EBB, ppc_ebb, size);
+ note_name, NT_PPC_EBB, ppc_ebb, size);
}
char *
elfcore_write_ppc_pmu (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_pmu,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_pmu,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_PMU, ppc_pmu, size);
+ note_name, NT_PPC_PMU, ppc_pmu, size);
}
char *
elfcore_write_ppc_tm_cgpr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_cgpr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_cgpr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CGPR, ppc_tm_cgpr, size);
+ note_name, NT_PPC_TM_CGPR, ppc_tm_cgpr, size);
}
char *
elfcore_write_ppc_tm_cfpr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_cfpr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_cfpr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CFPR, ppc_tm_cfpr, size);
+ note_name, NT_PPC_TM_CFPR, ppc_tm_cfpr, size);
}
char *
elfcore_write_ppc_tm_cvmx (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_cvmx,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_cvmx,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CVMX, ppc_tm_cvmx, size);
+ note_name, NT_PPC_TM_CVMX, ppc_tm_cvmx, size);
}
char *
elfcore_write_ppc_tm_cvsx (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_cvsx,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_cvsx,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CVSX, ppc_tm_cvsx, size);
+ note_name, NT_PPC_TM_CVSX, ppc_tm_cvsx, size);
}
char *
elfcore_write_ppc_tm_spr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_spr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_spr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_SPR, ppc_tm_spr, size);
+ note_name, NT_PPC_TM_SPR, ppc_tm_spr, size);
}
char *
elfcore_write_ppc_tm_ctar (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_ctar,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_ctar,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CTAR, ppc_tm_ctar, size);
+ note_name, NT_PPC_TM_CTAR, ppc_tm_ctar, size);
}
char *
elfcore_write_ppc_tm_cppr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_cppr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_cppr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CPPR, ppc_tm_cppr, size);
+ note_name, NT_PPC_TM_CPPR, ppc_tm_cppr, size);
}
char *
elfcore_write_ppc_tm_cdscr (bfd *abfd,
- char *buf,
- int *bufsiz,
- const void *ppc_tm_cdscr,
- int size)
+ char *buf,
+ int *bufsiz,
+ const void *ppc_tm_cdscr,
+ int size)
{
char *note_name = "LINUX";
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, NT_PPC_TM_CDSCR, ppc_tm_cdscr, size);
+ note_name, NT_PPC_TM_CDSCR, ppc_tm_cdscr, size);
}
static char *
note_name, NT_ARM_SVE, aarch_sve, size);
}
+char *
+elfcore_write_aarch_pauth (bfd *abfd,
+ char *buf,
+ int *bufsiz,
+ const void *aarch_pauth,
+ int size)
+{
+ char *note_name = "LINUX";
+ return elfcore_write_note (abfd, buf, bufsiz,
+ note_name, NT_ARM_PAC_MASK, aarch_pauth, size);
+}
+
char *
elfcore_write_register_note (bfd *abfd,
char *buf,
return elfcore_write_aarch_hw_watch (abfd, buf, bufsiz, data, size);
if (strcmp (section, ".reg-aarch-sve") == 0)
return elfcore_write_aarch_sve (abfd, buf, bufsiz, data, size);
+ if (strcmp (section, ".reg-aarch-pauth") == 0)
+ return elfcore_write_aarch_pauth (abfd, buf, bufsiz, data, size);
return NULL;
}