diff options
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 1291 |
1 files changed, 559 insertions, 732 deletions
@@ -49,6 +49,72 @@ SECTION #include CORE_HEADER #endif +/* Utility macro to make testing for string equality easier to read. */ +#ifndef streq +#define streq(A,B) (strcmp ((A), (B)) == 0) +#endif + +/* Core note names. */ +#define NOTE_NAME_CORE "CORE" +#define NOTE_NAME_FREEBSD "FreeBSD" +#define NOTE_NAME_GDB "GDB" +#define NOTE_NAME_LINUX "LINUX" + +/* Names of a pseudo-section which represent core notes. */ +#define NOTE_PSEUDO_SECTION_AARCH_GCS ".reg-aarch-gcs" +#define NOTE_PSEUDO_SECTION_AARCH_HW_BREAK ".reg-aarch-hw-break" +#define NOTE_PSEUDO_SECTION_AARCH_HW_WATCH ".reg-aarch-hw-watch" +#define NOTE_PSEUDO_SECTION_AARCH_MTE ".reg-aarch-mte" +#define NOTE_PSEUDO_SECTION_AARCH_PAUTH ".reg-aarch-pauth" +#define NOTE_PSEUDO_SECTION_AARCH_SSVE ".reg-aarch-ssve" +#define NOTE_PSEUDO_SECTION_AARCH_SVE ".reg-aarch-sve" +#define NOTE_PSEUDO_SECTION_AARCH_TLS ".reg-aarch-tls" +#define NOTE_PSEUDO_SECTION_AARCH_ZA ".reg-aarch-za" +#define NOTE_PSEUDO_SECTION_AARCH_ZT ".reg-aarch-zt" +#define NOTE_PSEUDO_SECTION_ARC_V2 ".reg-arc-v2" +#define NOTE_PSEUDO_SECTION_ARM_VFP ".reg-arm-vfp" +#define NOTE_PSEUDO_SECTION_I386_TLS ".reg-i386-tls" +#define NOTE_PSEUDO_SECTION_LOONGARCH_CPUCFG ".reg-loongarch-cpucfg" +#define NOTE_PSEUDO_SECTION_LOONGARCH_LASX ".reg-loongarch-lasx" +#define NOTE_PSEUDO_SECTION_LOONGARCH_LBT ".reg-loongarch-lbt" +#define NOTE_PSEUDO_SECTION_LOONGARCH_LSX ".reg-loongarch-lsx" +#define NOTE_PSEUDO_SECTION_PPC_DSCR ".reg-ppc-dscr" +#define NOTE_PSEUDO_SECTION_PPC_EBB ".reg-ppc-ebb" +#define NOTE_PSEUDO_SECTION_PPC_PMU ".reg-ppc-pmu" +#define NOTE_PSEUDO_SECTION_PPC_PPR ".reg-ppc-ppr" +#define NOTE_PSEUDO_SECTION_PPC_TAR ".reg-ppc-tar" +#define NOTE_PSEUDO_SECTION_PPC_TM_CDSCR ".reg-ppc-tm-cdscr" +#define NOTE_PSEUDO_SECTION_PPC_TM_CFPR ".reg-ppc-tm-cfpr" +#define NOTE_PSEUDO_SECTION_PPC_TM_CGPR ".reg-ppc-tm-cgpr" +#define NOTE_PSEUDO_SECTION_PPC_TM_CPPR ".reg-ppc-tm-cppr" +#define NOTE_PSEUDO_SECTION_PPC_TM_CTAR ".reg-ppc-tm-ctar" +#define NOTE_PSEUDO_SECTION_PPC_TM_CVMX ".reg-ppc-tm-cvmx" +#define NOTE_PSEUDO_SECTION_PPC_TM_CVSX ".reg_ppc_tm_cvsx" +#define NOTE_PSEUDO_SECTION_PPC_TM_SPR ".reg_ppc_tm_spr" +#define NOTE_PSEUDO_SECTION_PPC_VSX ".reg_ppc_vsx" +#define NOTE_PSEUDO_SECTION_PPC_VMX ".reg_ppc_vmx" +#define NOTE_PSEUDO_SECTION_REG ".reg" +#define NOTE_PSEUDO_SECTION_REG2 ".reg2" +#define NOTE_PSEUDO_SECTION_RISCV_CSR ".reg_riscv_csr" +#define NOTE_PSEUDO_SECTION_S390_CTRS ".reg_s390_ctrs" +#define NOTE_PSEUDO_SECTION_S390_GS_BC ".reg-s390-gs-bc" +#define NOTE_PSEUDO_SECTION_S390_GS_CB ".reg-s390-gs-cb" +#define NOTE_PSEUDO_SECTION_S390_HIGH_GPRS ".reg-s390-high-gprs" +#define NOTE_PSEUDO_SECTION_S390_LAST_BREAK ".reg-s390-last-break" +#define NOTE_PSEUDO_SECTION_S390_PREFIX ".reg-s390-prefix" +#define NOTE_PSEUDO_SECTION_S390_SYSTEM_CALL ".reg-s390-system-call" +#define NOTE_PSEUDO_SECTION_S390_TDB ".reg-s390-tdb" +#define NOTE_PSEUDO_SECTION_S390_TIMER ".reg-s390-timer" +#define NOTE_PSEUDO_SECTION_S390_TODCMP ".reg-s390-todcmp" +#define NOTE_PSEUDO_SECTION_S390_TODPREG ".reg-s390-todpreg" +#define NOTE_PSEUDO_SECTION_S390_VXRS_HIGH ".reg-s390-vxrs-high" +#define NOTE_PSEUDO_SECTION_S390_VXRS_LOW ".reg-s390-vxrs-low" +#define NOTE_PSEUDO_SECTION_SSP ".reg-ssp" +#define NOTE_PSEUDO_SECTION_TDESC ".gdb-tdesc" +#define NOTE_PSEUDO_SECTION_X86_SEGBASES ".reg-x86-segbases" +#define NOTE_PSEUDO_SECTION_XFP ".reg-xfp" +#define NOTE_PSEUDO_SECTION_XSTATE ".reg-xstate" + static int elf_sort_sections (const void *, const void *); static bool assign_file_positions_except_relocs (bfd *, struct bfd_link_info *); static bool swap_out_syms (bfd *, struct elf_strtab_hash **, int, @@ -504,17 +570,44 @@ bfd_elf_get_elf_syms (bfd *ibfd, shndx = extshndx_buf; isym < isymend; esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL) - if (!(*bed->s->swap_symbol_in) (ibfd, esym, shndx, isym)) - { - symoffset += (esym - (bfd_byte *) extsym_buf) / extsym_size; - /* xgettext:c-format */ - _bfd_error_handler (_("%pB symbol number %lu references" - " nonexistent SHT_SYMTAB_SHNDX section"), - ibfd, (unsigned long) symoffset); - free (alloc_intsym); - intsym_buf = NULL; - goto out1; - } + { + if (!(*bed->s->swap_symbol_in) (ibfd, esym, shndx, isym)) + { + symoffset += (esym - (bfd_byte *) extsym_buf) / extsym_size; + /* xgettext:c-format */ + _bfd_error_handler (_("%pB symbol number %lu references" + " nonexistent SHT_SYMTAB_SHNDX section"), + ibfd, (unsigned long) symoffset); + free (alloc_intsym); + intsym_buf = NULL; + goto out1; + } + + /* PR 33019: Do not accept unsupported binding values - they will + likely cause problems later on. */ + int bind = ELF_ST_BIND (isym->st_info); + if (bind > STB_WEAK && bind < STB_LOOS) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"), + ibfd, (unsigned long) (isym - intsym_buf), bind); + free (alloc_intsym); + intsym_buf = NULL; + goto out1; + } + + /* Paranoia: Also refuse to accept the only undefined symbol type: 7. */ + int t = ELF_ST_TYPE (isym->st_info); + if (t == 7) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"), + ibfd, (unsigned long) (isym - intsym_buf), t); + free (alloc_intsym); + intsym_buf = NULL; + goto out1; + } + } out1: _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size); @@ -838,20 +931,16 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, else if ((flags & SEC_LOAD) != 0) flags |= SEC_DATA; if ((hdr->sh_flags & SHF_MERGE) != 0) - { - flags |= SEC_MERGE; - newsect->entsize = hdr->sh_entsize; - } + flags |= SEC_MERGE; if ((hdr->sh_flags & SHF_STRINGS) != 0) - { - flags |= SEC_STRINGS; - newsect->entsize = hdr->sh_entsize; - } + flags |= SEC_STRINGS; if ((hdr->sh_flags & SHF_TLS) != 0) flags |= SEC_THREAD_LOCAL; if ((hdr->sh_flags & SHF_EXCLUDE) != 0) flags |= SEC_EXCLUDE; + newsect->entsize = hdr->sh_entsize; + switch (elf_elfheader (abfd)->e_ident[EI_OSABI]) { /* FIXME: We should not recognize SHF_GNU_MBIND for ELFOSABI_NONE, @@ -868,7 +957,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, break; } - if ((flags & SEC_ALLOC) == 0) + if ((flags & (SEC_ALLOC | SEC_GROUP)) == 0) { /* The debugging sections appear to be recognized only by name, not any sort of flag. Their SEC_ALLOC bits are cleared. */ @@ -887,7 +976,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, } else if (startswith (name, ".line") || startswith (name, ".stab") - || strcmp (name, ".gdb_index") == 0) + || streq (name, ".gdb_index")) flags |= SEC_DEBUGGING; } } @@ -1531,7 +1620,7 @@ _bfd_elf_print_private_bfd_data (bfd *abfd, void *farg) if (bed->elf_backend_get_target_dtag) name = (*bed->elf_backend_get_target_dtag) (dyn.d_tag); - if (!strcmp (name, "")) + if (streq (name, "")) { sprintf (ab, "%#" PRIx64, (uint64_t) dyn.d_tag); name = ab; @@ -2276,7 +2365,7 @@ _bfd_elf_get_symbol_version_string (bfd *abfd, asymbol *symbol, if (base_p || nodename == NULL || symbol->name == NULL - || strcmp (symbol->name, nodename) != 0) + || ! streq (symbol->name, nodename)) version_string = nodename; } else @@ -2449,6 +2538,7 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex) case SHT_PREINIT_ARRAY: /* .preinit_array section. */ case SHT_GNU_LIBLIST: /* .gnu.liblist section. */ case SHT_GNU_HASH: /* .gnu.hash section. */ + case SHT_GNU_SFRAME: /* .sframe section. */ ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); goto success; @@ -2854,8 +2944,10 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex) default: /* Possibly an attributes section. */ - if (hdr->sh_type == SHT_GNU_ATTRIBUTES - || hdr->sh_type == bed->obj_attrs_section_type) + if (get_elf_backend_data (abfd)->target_os != is_solaris + /* PR 33153: Solaris defines SHT_SUNW_cap which collides with SHT_GNU_ATTRIBUTES. */ + && (hdr->sh_type == SHT_GNU_ATTRIBUTES + || hdr->sh_type == bed->obj_attrs_section_type)) { if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) goto fail; @@ -3469,7 +3561,7 @@ _bfd_elf_init_reloc_shdr (bfd *abfd, struct bfd_elf_section_reloc_data *reldata, const char *sec_name, bool use_rela_p, - bool delay_st_name_p) + bool delay_sh_name_p) { Elf_Internal_Shdr *rel_hdr; const struct elf_backend_data *bed = get_elf_backend_data (abfd); @@ -3480,7 +3572,7 @@ _bfd_elf_init_reloc_shdr (bfd *abfd, return false; reldata->hdr = rel_hdr; - if (delay_st_name_p) + if (delay_sh_name_p) rel_hdr->sh_name = (unsigned int) -1; else if (!_bfd_elf_set_reloc_sh_name (abfd, rel_hdr, sec_name, use_rela_p)) @@ -3526,7 +3618,7 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) Elf_Internal_Shdr *this_hdr; unsigned int sh_type; const char *name = asect->name; - bool delay_st_name_p = false; + bool delay_sh_name_p = false; bfd_vma mask; if (arg->failed) @@ -3543,16 +3635,17 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) && (abfd->flags & BFD_COMPRESS) != 0 && (asect->flags & SEC_DEBUGGING) != 0 && (asect->flags & SEC_ALLOC) == 0 + && (asect->flags & SEC_HAS_CONTENTS) != 0 && name[1] == 'd' && name[6] == '_') { /* If this section will be compressed, delay adding section name to section name section after it is compressed in _bfd_elf_assign_file_positions_for_non_load. */ - delay_st_name_p = true; + delay_sh_name_p = true; } - if (delay_st_name_p) + if (delay_sh_name_p) this_hdr->sh_name = (unsigned int) -1; else { @@ -3735,6 +3828,9 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE) this_hdr->sh_flags |= SHF_EXCLUDE; + if (this_hdr->sh_entsize == 0) + this_hdr->sh_entsize = asect->entsize; + /* If the section has relocs, set up a section header for the SHT_REL[A] section. If two relocation sections are required for this section, it is up to the processor-specific back-end to @@ -3751,14 +3847,14 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) { if (esd->rel.count && esd->rel.hdr == NULL && !_bfd_elf_init_reloc_shdr (abfd, &esd->rel, name, - false, delay_st_name_p)) + false, delay_sh_name_p)) { arg->failed = true; return; } if (esd->rela.count && esd->rela.hdr == NULL && !_bfd_elf_init_reloc_shdr (abfd, &esd->rela, name, - true, delay_st_name_p)) + true, delay_sh_name_p)) { arg->failed = true; return; @@ -3769,7 +3865,7 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) ? &esd->rela : &esd->rel), name, asect->use_rela_p, - delay_st_name_p)) + delay_sh_name_p)) { arg->failed = true; return; @@ -3943,20 +4039,17 @@ bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg) break; } - /* We should always get here with loc == sec->contents + 4, but it is - possible to craft bogus SHT_GROUP sections that will cause segfaults - in objcopy without checking loc here and in the loop above. */ - if (loc == sec->contents) - BFD_ASSERT (0); - else + /* We should always get here with loc == sec->contents + 4. Return + an error for bogus SHT_GROUP sections. */ + loc -= 4; + if (loc != sec->contents) { - loc -= 4; - if (loc != sec->contents) - { - BFD_ASSERT (0); - memset (sec->contents + 4, 0, loc - sec->contents); - loc = sec->contents; - } + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: corrupted group section: `%pA'"), + abfd, sec); + bfd_set_error (bfd_error_bad_value); + *failedptr = true; + return; } H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc); @@ -3972,7 +4065,7 @@ _bfd_elf_plt_get_reloc_section (bfd *abfd, const char *name) /* If a target needs .got.plt section, relocations in rela.plt/rel.plt section likely apply to .got.plt or .got section. */ if (get_elf_backend_data (abfd)->want_got_plt - && strcmp (name, ".plt") == 0) + && streq (name, ".plt")) { asection *sec; @@ -4278,7 +4371,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) but without the trailing ``str'', and set its sh_link field to point to this section. */ if (startswith (sec->name, ".stab") - && strcmp (sec->name + strlen (sec->name) - 3, "str") == 0) + && streq (sec->name + strlen (sec->name) - 3, "str")) { size_t len; char *alc; @@ -4474,7 +4567,11 @@ elf_map_symbols (bfd *abfd, unsigned int *pnum_locals) asection *sec = sym->section; if (sec->owner != abfd) - sec = sec->output_section; + { + sec = sec->output_section; + if (sec == NULL) + return false; + } sect_syms[sec->index] = syms[idx]; } @@ -6067,7 +6164,7 @@ assign_file_positions_for_load_sections (bfd *abfd, PT_DYNAMIC segment. */ else if (p->p_type == PT_DYNAMIC && m->count > 1 - && strcmp (m->sections[0]->name, ".dynamic") != 0) + && ! streq (m->sections[0]->name, ".dynamic")) { _bfd_error_handler (_("%pB: The first section in the PT_DYNAMIC segment" @@ -6292,27 +6389,28 @@ assign_file_positions_for_load_sections (bfd *abfd, } else { - if (p->p_type == PT_LOAD) + if (this_hdr->sh_type == SHT_NOBITS + && (this_hdr->sh_flags & SHF_TLS) != 0 + && this_hdr->sh_offset == 0) { - this_hdr->sh_offset = sec->filepos = off; - if (this_hdr->sh_type != SHT_NOBITS) - off += this_hdr->sh_size; - } - else if (this_hdr->sh_type == SHT_NOBITS - && (this_hdr->sh_flags & SHF_TLS) != 0 - && this_hdr->sh_offset == 0) - { - /* This is a .tbss section that didn't get a PT_LOAD. - (See _bfd_elf_map_sections_to_segments "Create a - final PT_LOAD".) Set sh_offset to the value it - would have if we had created a zero p_filesz and - p_memsz PT_LOAD header for the section. This - also makes the PT_TLS header have the same - p_offset value. */ + /* Set sh_offset for .tbss sections to their nominal + offset after aligning. They are not loaded from + disk so the value doesn't really matter, except + when the .tbss section is the first one in a + PT_TLS segment. In that case it sets the + p_offset for the PT_TLS segment, which according + to the ELF gABI ought to satisfy + p_offset % p_align == p_vaddr % p_align. */ bfd_vma adjust = vma_page_aligned_bias (this_hdr->sh_addr, off, align); this_hdr->sh_offset = sec->filepos = off + adjust; } + else if (p->p_type == PT_LOAD) + { + this_hdr->sh_offset = sec->filepos = off; + if (this_hdr->sh_type != SHT_NOBITS) + off += this_hdr->sh_size; + } if (this_hdr->sh_type != SHT_NOBITS) { @@ -7431,7 +7529,7 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd_vma maxpagesize) || (segment->p_paddr \ ? segment->p_paddr != section->lma * (opb) \ : segment->p_vaddr != section->vma * (opb)) \ - || (strcmp (bfd_section_name (section), ".dynamic") == 0)) \ + || (streq (bfd_section_name (section), ".dynamic"))) \ && (segment->p_type != PT_LOAD || !section->segment_mark)) /* If the output section of a section in the input segment is NULL, @@ -8345,25 +8443,34 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd) return rewrite_elf_program_header (ibfd, obfd, maxpagesize); } -/* Initialize private output section information from input section. */ +/* Copy private section information from input to output. This function + is called both by objcopy where LINK_INFO is NULL, and ld where + LINK_INFO is non-NULL in the usual case but NULL for a special case + when dealing with LTO IR or cloning output sections. */ bool -_bfd_elf_init_private_section_data (bfd *ibfd, +_bfd_elf_copy_private_section_data (bfd *ibfd, asection *isec, bfd *obfd, asection *osec, struct bfd_link_info *link_info) - { - Elf_Internal_Shdr *ihdr, *ohdr; - bool final_link = (link_info != NULL - && !bfd_link_relocatable (link_info)); - if (ibfd->xvec->flavour != bfd_target_elf_flavour || obfd->xvec->flavour != bfd_target_elf_flavour) return true; - BFD_ASSERT (elf_section_data (osec) != NULL); + Elf_Internal_Shdr *ihdr = &elf_section_data (isec)->this_hdr; + Elf_Internal_Shdr *ohdr = &elf_section_data (osec)->this_hdr; + if (link_info == NULL) + { + ohdr->sh_entsize = ihdr->sh_entsize; + + if (ihdr->sh_type == SHT_SYMTAB + || ihdr->sh_type == SHT_DYNSYM + || ihdr->sh_type == SHT_GNU_verneed + || ihdr->sh_type == SHT_GNU_verdef) + ohdr->sh_info = ihdr->sh_info; + } /* If this is a known ABI section, ELF section type and flags may have been set up when OSEC was created. For normal sections we @@ -8373,11 +8480,14 @@ _bfd_elf_init_private_section_data (bfd *ibfd, || elf_section_type (osec) == SHT_NOTE || elf_section_type (osec) == SHT_NOBITS) elf_section_type (osec) = SHT_NULL; + /* For objcopy and relocatable link, copy the ELF section type from the input file if the BFD section flags are the same. (If they are different the user may be doing something like "objcopy --set-section-flags .text=alloc,data".) For a final link allow some flags that the linker clears to differ. */ + bool final_link = (link_info != NULL + && !bfd_link_relocatable (link_info)); if (elf_section_type (osec) == SHT_NULL && (osec->flags == isec->flags || (final_link @@ -8385,9 +8495,28 @@ _bfd_elf_init_private_section_data (bfd *ibfd, & ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC)) == 0))) elf_section_type (osec) = elf_section_type (isec); - /* FIXME: Is this correct for all OS/PROC specific flags? */ - elf_section_flags (osec) = (elf_section_flags (isec) - & (SHF_MASKOS | SHF_MASKPROC)); + elf_section_flags (osec) = elf_section_flags (isec); + /* Like for type, retain flags for objcopy (yet unlike for type, don't do so + for relocatable link). Same heuristic as there: If the BFD section flags + are different, assume --set-section-flags is in use for the section. + + FIXME: Is this correct for all OS/PROC specific flags? */ + if (link_info != NULL || osec->flags != isec->flags) + elf_section_flags (osec) &= (SHF_MASKOS | SHF_MASKPROC); + else + { + /* Clear only flags which are set below or elsewhere. */ + elf_section_flags (osec) &= ~(SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR + | SHF_MERGE | SHF_STRINGS | SHF_LINK_ORDER + | SHF_INFO_LINK | SHF_GROUP | SHF_TLS + | SHF_COMPRESSED); + if (elf_section_flags (osec) & ~(SHF_MASKOS | SHF_MASKPROC)) + _bfd_error_handler + (_("%pB:%pA: warning: retaining unknown section flag(s) %#" PRIx64), + ibfd, isec, + (uint64_t) (elf_section_flags (osec) + & ~(SHF_MASKOS | SHF_MASKPROC))); + } /* Copy sh_info from input for mbind section. */ if ((elf_tdata (ibfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0 @@ -8415,14 +8544,11 @@ _bfd_elf_init_private_section_data (bfd *ibfd, elf_section_flags (osec) |= (elf_section_flags (isec) & SHF_COMPRESSED); - ihdr = &elf_section_data (isec)->this_hdr; - /* We need to handle elf_linked_to_section for SHF_LINK_ORDER. We don't use the output section of the linked-to section since it may be NULL at this point. */ if ((ihdr->sh_flags & SHF_LINK_ORDER) != 0) { - ohdr = &elf_section_data (osec)->this_hdr; ohdr->sh_flags |= SHF_LINK_ORDER; elf_linked_to_section (osec) = elf_linked_to_section (isec); } @@ -8432,36 +8558,6 @@ _bfd_elf_init_private_section_data (bfd *ibfd, return true; } -/* Copy private section information. This copies over the entsize - field, and sometimes the info field. */ - -bool -_bfd_elf_copy_private_section_data (bfd *ibfd, - asection *isec, - bfd *obfd, - asection *osec) -{ - Elf_Internal_Shdr *ihdr, *ohdr; - - if (ibfd->xvec->flavour != bfd_target_elf_flavour - || obfd->xvec->flavour != bfd_target_elf_flavour) - return true; - - ihdr = &elf_section_data (isec)->this_hdr; - ohdr = &elf_section_data (osec)->this_hdr; - - ohdr->sh_entsize = ihdr->sh_entsize; - - if (ihdr->sh_type == SHT_SYMTAB - || ihdr->sh_type == SHT_DYNSYM - || ihdr->sh_type == SHT_GNU_verneed - || ihdr->sh_type == SHT_GNU_verdef) - ohdr->sh_info = ihdr->sh_info; - - return _bfd_elf_init_private_section_data (ibfd, isec, obfd, osec, - NULL); -} - /* Look at all the SHT_GROUP sections in IBFD, making any adjustments necessary if we are removing either the SHT_GROUP section or any of the group member sections. DISCARDED is the value that a section's @@ -10345,7 +10441,7 @@ elfcore_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) } /* Make a ".reg/999" section and a ".reg" section. */ - return _bfd_elfcore_make_pseudosection (abfd, ".reg", + return _bfd_elfcore_make_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, size, note->descpos + offset); } #endif /* defined (HAVE_PRSTATUS_T) */ @@ -10367,7 +10463,7 @@ elfcore_make_note_pseudosection (bfd *abfd, static bool elfcore_grok_prfpreg (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg2", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG2, note); } /* Linux dumps the Intel SSE regs in a note named "LINUX" with a note @@ -10377,7 +10473,7 @@ elfcore_grok_prfpreg (bfd *abfd, Elf_Internal_Note *note) static bool elfcore_grok_prxfpreg (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-xfp", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_XFP, note); } /* Linux dumps the Intel XSAVE extended state in a note named "LINUX" @@ -10387,230 +10483,235 @@ elfcore_grok_prxfpreg (bfd *abfd, Elf_Internal_Note *note) static bool elfcore_grok_xstatereg (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-xstate", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_XSTATE, note); +} + +static bool +elfcore_grok_sspreg (bfd *abfd, Elf_Internal_Note *note) +{ + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_SSP, note); } static bool elfcore_grok_ppc_vmx (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-vmx", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_VMX, note); } static bool elfcore_grok_ppc_vsx (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-vsx", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_VSX, note); } static bool elfcore_grok_ppc_tar (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tar", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TAR, note); } static bool elfcore_grok_ppc_ppr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-ppr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_PPR, note); } static bool elfcore_grok_ppc_dscr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-dscr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_DSCR, note); } static bool elfcore_grok_ppc_ebb (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-ebb", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_EBB, note); } static bool elfcore_grok_ppc_pmu (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-pmu", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_PMU, note); } static bool elfcore_grok_ppc_tm_cgpr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-cgpr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CGPR, note); } static bool elfcore_grok_ppc_tm_cfpr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-cfpr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CFPR, note); } static bool elfcore_grok_ppc_tm_cvmx (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-cvmx", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CVMX, note); } static bool elfcore_grok_ppc_tm_cvsx (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-cvsx", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CVSX, note); } static bool elfcore_grok_ppc_tm_spr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-spr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_SPR, note); } static bool elfcore_grok_ppc_tm_ctar (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-ctar", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CTAR, note); } static bool elfcore_grok_ppc_tm_cppr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-cppr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CPPR, note); } static bool elfcore_grok_ppc_tm_cdscr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-ppc-tm-cdscr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_PPC_TM_CDSCR, note); } static bool elfcore_grok_s390_high_gprs (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-high-gprs", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_HIGH_GPRS, note); } static bool elfcore_grok_s390_timer (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-timer", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_TIMER, note); } static bool elfcore_grok_s390_todcmp (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-todcmp", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_TODCMP, note); } static bool elfcore_grok_s390_todpreg (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-todpreg", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_TODPREG, note); } static bool elfcore_grok_s390_ctrs (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-ctrs", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_CTRS, note); } static bool elfcore_grok_s390_prefix (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-prefix", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_PREFIX, note); } static bool elfcore_grok_s390_last_break (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-last-break", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_LAST_BREAK, note); } static bool elfcore_grok_s390_system_call (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-system-call", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_SYSTEM_CALL, note); } static bool elfcore_grok_s390_tdb (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-tdb", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_TDB, note); } static bool elfcore_grok_s390_vxrs_low (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-vxrs-low", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_VXRS_LOW, note); } static bool elfcore_grok_s390_vxrs_high (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-vxrs-high", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_VXRS_HIGH, note); } static bool elfcore_grok_s390_gs_cb (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-gs-cb", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_GS_CB, note); } static bool elfcore_grok_s390_gs_bc (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-s390-gs-bc", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_S390_GS_BC, note); } static bool elfcore_grok_arm_vfp (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-arm-vfp", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_ARM_VFP, note); } static bool elfcore_grok_aarch_tls (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-tls", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_TLS, note); } static bool elfcore_grok_aarch_hw_break (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-hw-break", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_HW_BREAK, note); } static bool elfcore_grok_aarch_hw_watch (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-hw-watch", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_HW_WATCH, note); } static bool elfcore_grok_aarch_sve (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-sve", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_SVE, note); } static bool elfcore_grok_aarch_pauth (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-pauth", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_PAUTH, note); } static bool elfcore_grok_aarch_mte (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-mte", - note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_MTE, note); } static bool elfcore_grok_aarch_ssve (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-ssve", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_SSVE, note); } static bool elfcore_grok_aarch_za (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-za", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_ZA, note); } /* Convert NOTE into a bfd_section called ".reg-aarch-zt". Return TRUE if @@ -10619,13 +10720,22 @@ elfcore_grok_aarch_za (bfd *abfd, Elf_Internal_Note *note) static bool elfcore_grok_aarch_zt (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-aarch-zt", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_ZT, note); +} + +/* Convert NOTE into a bfd_section called ".reg-aarch-gcs". Return TRUE if + successful, otherwise return FALSE. */ + +static bool +elfcore_grok_aarch_gcs (bfd *abfd, Elf_Internal_Note *note) +{ + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_AARCH_GCS, note); } static bool elfcore_grok_arc_v2 (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-arc-v2", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_ARC_V2, note); } /* Convert NOTE into a bfd_section called ".reg-riscv-csr". Return TRUE if @@ -10634,7 +10744,7 @@ elfcore_grok_arc_v2 (bfd *abfd, Elf_Internal_Note *note) static bool elfcore_grok_riscv_csr (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-riscv-csr", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_RISCV_CSR, note); } /* Convert NOTE into a bfd_section called ".gdb-tdesc". Return TRUE if @@ -10647,27 +10757,34 @@ elfcore_grok_gdb_tdesc (bfd *abfd, Elf_Internal_Note *note) } static bool +elfcore_grok_i386_tls (bfd *abfd, Elf_Internal_Note *note) +{ + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_I386_TLS, + note); +} + +static bool elfcore_grok_loongarch_cpucfg (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-loongarch-cpucfg", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_LOONGARCH_CPUCFG, note); } static bool elfcore_grok_loongarch_lbt (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-loongarch-lbt", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_LOONGARCH_LBT, note); } static bool elfcore_grok_loongarch_lsx (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-loongarch-lsx", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_LOONGARCH_LSX, note); } static bool elfcore_grok_loongarch_lasx (bfd *abfd, Elf_Internal_Note *note) { - return elfcore_make_note_pseudosection (abfd, ".reg-loongarch-lasx", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_LOONGARCH_LASX, note); } #if defined (HAVE_PRPSINFO_T) @@ -10837,7 +10954,7 @@ elfcore_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note) /* Make a ".reg/999" section. */ - sprintf (buf, ".reg/%d", elfcore_make_pid (abfd)); + sprintf (buf, NOTE_PSEUDO_SECTION_REG "/%d", elfcore_make_pid (abfd)); len = strlen (buf) + 1; name = bfd_alloc (abfd, len); if (name == NULL) @@ -10861,12 +10978,12 @@ elfcore_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note) sect->alignment_power = 2; - if (!elfcore_maybe_make_sect (abfd, ".reg", sect)) + if (!elfcore_maybe_make_sect (abfd, NOTE_PSEUDO_SECTION_REG, sect)) return false; /* Make a ".reg2/999" section */ - sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd)); + sprintf (buf, NOTE_PSEUDO_SECTION_REG2 "/%d", elfcore_make_pid (abfd)); len = strlen (buf) + 1; name = bfd_alloc (abfd, len); if (name == NULL) @@ -10890,7 +11007,7 @@ elfcore_grok_lwpstatus (bfd *abfd, Elf_Internal_Note *note) sect->alignment_power = 2; - return elfcore_maybe_make_sect (abfd, ".reg2", sect); + return elfcore_maybe_make_sect (abfd, NOTE_PSEUDO_SECTION_REG2, sect); } #endif /* defined (HAVE_LWPSTATUS_T) */ @@ -10921,7 +11038,7 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note) type = bfd_get_32 (abfd, note->descdata); - struct + static const struct { const char *type_name; unsigned long min_size; @@ -10956,7 +11073,7 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note) /* Make a ".reg/<tid>" section containing the Win32 API thread CONTEXT structure. */ /* thread_info.tid */ - sprintf (buf, ".reg/%ld", (long) bfd_get_32 (abfd, note->descdata + 4)); + sprintf (buf, NOTE_PSEUDO_SECTION_REG "/%ld", (long) bfd_get_32 (abfd, note->descdata + 4)); len = strlen (buf) + 1; name = (char *) bfd_alloc (abfd, len); @@ -10979,7 +11096,7 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note) is_active_thread = bfd_get_32 (abfd, note->descdata + 8); if (is_active_thread) - if (! elfcore_maybe_make_sect (abfd, ".reg", sect)) + if (! elfcore_maybe_make_sect (abfd, NOTE_PSEUDO_SECTION_REG, sect)) return false; break; @@ -11040,6 +11157,64 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) { const struct elf_backend_data *bed = get_elf_backend_data (abfd); + /* Short cut for LINUX notes. */ + if (note->namesz == 6 /* strlen (NOTE_NAME_LINUX) + 1 */ + && streq (note->namedata, NOTE_NAME_LINUX)) + { + switch (note->type) + { + case NT_386_TLS: return elfcore_grok_i386_tls (abfd, note); + case NT_ARC_V2: return elfcore_grok_arc_v2 (abfd, note); + case NT_ARM_GCS: return elfcore_grok_aarch_gcs (abfd, note); + case NT_ARM_HW_BREAK: return elfcore_grok_aarch_hw_break (abfd, note); + case NT_ARM_HW_WATCH: return elfcore_grok_aarch_hw_watch (abfd, note); + case NT_ARM_PAC_MASK: return elfcore_grok_aarch_pauth (abfd, note); + case NT_ARM_SSVE: return elfcore_grok_aarch_ssve (abfd, note); + case NT_ARM_SVE: return elfcore_grok_aarch_sve (abfd, note); + case NT_ARM_TAGGED_ADDR_CTRL: return elfcore_grok_aarch_mte (abfd, note); + case NT_ARM_TLS: return elfcore_grok_aarch_tls (abfd, note); + case NT_ARM_VFP: return elfcore_grok_arm_vfp (abfd, note); + case NT_ARM_ZA: return elfcore_grok_aarch_za (abfd, note); + case NT_ARM_ZT: return elfcore_grok_aarch_zt (abfd, note); + case NT_LARCH_CPUCFG: return elfcore_grok_loongarch_cpucfg (abfd, note); + case NT_LARCH_LASX: return elfcore_grok_loongarch_lasx (abfd, note); + case NT_LARCH_LBT: return elfcore_grok_loongarch_lbt (abfd, note); + case NT_LARCH_LSX: return elfcore_grok_loongarch_lsx (abfd, note); + case NT_PPC_DSCR: return elfcore_grok_ppc_dscr (abfd, note); + case NT_PPC_EBB: return elfcore_grok_ppc_ebb (abfd, note); + case NT_PPC_PMU: return elfcore_grok_ppc_pmu (abfd, note); + case NT_PPC_PPR: return elfcore_grok_ppc_ppr (abfd, note); + case NT_PPC_TAR: return elfcore_grok_ppc_tar (abfd, note); + case NT_PPC_TM_CDSCR: return elfcore_grok_ppc_tm_cdscr (abfd, note); + case NT_PPC_TM_CFPR: return elfcore_grok_ppc_tm_cfpr (abfd, note); + case NT_PPC_TM_CGPR: return elfcore_grok_ppc_tm_cgpr (abfd, note); + case NT_PPC_TM_CPPR: return elfcore_grok_ppc_tm_cppr (abfd, note); + case NT_PPC_TM_CTAR: return elfcore_grok_ppc_tm_ctar (abfd, note); + case NT_PPC_TM_CVMX: return elfcore_grok_ppc_tm_cvmx (abfd, note); + case NT_PPC_TM_CVSX: return elfcore_grok_ppc_tm_cvsx (abfd, note); + case NT_PPC_TM_SPR: return elfcore_grok_ppc_tm_spr (abfd, note); + case NT_PPC_VMX: return elfcore_grok_ppc_vmx (abfd, note); + case NT_PPC_VSX: return elfcore_grok_ppc_vsx (abfd, note); + case NT_PRXFPREG: return elfcore_grok_prxfpreg (abfd, note); + case NT_S390_CTRS: return elfcore_grok_s390_ctrs (abfd, note); + case NT_S390_GS_BC: return elfcore_grok_s390_gs_bc (abfd, note); + case NT_S390_GS_CB: return elfcore_grok_s390_gs_cb (abfd, note); + case NT_S390_HIGH_GPRS: return elfcore_grok_s390_high_gprs (abfd, note); + case NT_S390_LAST_BREAK: return elfcore_grok_s390_last_break (abfd, note); + case NT_S390_PREFIX: return elfcore_grok_s390_prefix (abfd, note); + case NT_S390_SYSTEM_CALL: return elfcore_grok_s390_system_call (abfd, note); + case NT_S390_TDB: return elfcore_grok_s390_tdb (abfd, note); + case NT_S390_TIMER: return elfcore_grok_s390_timer (abfd, note); + case NT_S390_TODCMP: return elfcore_grok_s390_todcmp (abfd, note); + case NT_S390_TODPREG: return elfcore_grok_s390_todpreg (abfd, note); + case NT_S390_VXRS_HIGH: return elfcore_grok_s390_vxrs_high (abfd, note); + case NT_S390_VXRS_LOW: return elfcore_grok_s390_vxrs_low (abfd, note); + case NT_X86_SHSTK: return elfcore_grok_sspreg (abfd, note); + case NT_X86_XSTATE: return elfcore_grok_xstatereg (abfd, note); + default: break; + } + } + switch (note->type) { default: @@ -11065,341 +11240,24 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) return elfcore_grok_lwpstatus (abfd, note); #endif - case NT_FPREGSET: /* FIXME: rename to NT_PRFPREG */ + case NT_FPREGSET: /* FIXME: rename to NT_PRFPREG. */ return elfcore_grok_prfpreg (abfd, note); case NT_WIN32PSTATUS: return elfcore_grok_win32pstatus (abfd, note); - case NT_PRXFPREG: /* Linux SSE extension */ - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_prxfpreg (abfd, note); - else - return true; - - case NT_X86_XSTATE: /* Linux XSAVE extension */ - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_xstatereg (abfd, note); - else - return true; - - case NT_PPC_VMX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_vmx (abfd, note); - else - return true; - - case NT_PPC_VSX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_vsx (abfd, note); - else - return true; - - case NT_PPC_TAR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tar (abfd, note); - else - return true; - - case NT_PPC_PPR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_ppr (abfd, note); - else - return true; - - case NT_PPC_DSCR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_dscr (abfd, note); - else - return true; - - case NT_PPC_EBB: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_ebb (abfd, note); - else - return true; - - case NT_PPC_PMU: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_pmu (abfd, note); - else - return true; - - case NT_PPC_TM_CGPR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_cgpr (abfd, note); - else - return true; - - case NT_PPC_TM_CFPR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_cfpr (abfd, note); - else - return true; - - case NT_PPC_TM_CVMX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_cvmx (abfd, note); - else - return true; - - case NT_PPC_TM_CVSX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_cvsx (abfd, note); - else - return true; - - case NT_PPC_TM_SPR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_spr (abfd, note); - else - return true; - - case NT_PPC_TM_CTAR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_ctar (abfd, note); - else - return true; - - case NT_PPC_TM_CPPR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_cppr (abfd, note); - else - return true; - - case NT_PPC_TM_CDSCR: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_ppc_tm_cdscr (abfd, note); - else - return true; - - case NT_S390_HIGH_GPRS: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_high_gprs (abfd, note); - else - return true; - - case NT_S390_TIMER: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_timer (abfd, note); - else - return true; - - case NT_S390_TODCMP: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_todcmp (abfd, note); - else - return true; - - case NT_S390_TODPREG: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_todpreg (abfd, note); - else - return true; - - case NT_S390_CTRS: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_ctrs (abfd, note); - else - return true; - - case NT_S390_PREFIX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_prefix (abfd, note); - else - return true; - - case NT_S390_LAST_BREAK: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_last_break (abfd, note); - else - return true; - - case NT_S390_SYSTEM_CALL: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_system_call (abfd, note); - else - return true; - - case NT_S390_TDB: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_tdb (abfd, note); - else - return true; - - case NT_S390_VXRS_LOW: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_vxrs_low (abfd, note); - else - return true; - - case NT_S390_VXRS_HIGH: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_vxrs_high (abfd, note); - else - return true; - - case NT_S390_GS_CB: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_gs_cb (abfd, note); - else - return true; - - case NT_S390_GS_BC: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_s390_gs_bc (abfd, note); - else - return true; - - case NT_ARC_V2: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_arc_v2 (abfd, note); - else - return true; - - case NT_ARM_VFP: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_arm_vfp (abfd, note); - else - return true; - - case NT_ARM_TLS: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_tls (abfd, note); - else - return true; - - case NT_ARM_HW_BREAK: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_hw_break (abfd, note); - else - return true; - - case NT_ARM_HW_WATCH: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_hw_watch (abfd, note); - else - return true; - - case NT_ARM_SVE: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_sve (abfd, note); - 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_ARM_TAGGED_ADDR_CTRL: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_mte (abfd, note); - else - return true; - - case NT_ARM_SSVE: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_ssve (abfd, note); - else - return true; - - case NT_ARM_ZA: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_za (abfd, note); - else - return true; - - case NT_ARM_ZT: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_aarch_zt (abfd, note); - else - return true; - case NT_GDB_TDESC: - if (note->namesz == 4 - && strcmp (note->namedata, "GDB") == 0) + if (note->namesz == 4 && streq (note->namedata, NOTE_NAME_GDB)) return elfcore_grok_gdb_tdesc (abfd, note); else return true; case NT_RISCV_CSR: - if (note->namesz == 4 - && strcmp (note->namedata, "GDB") == 0) + if (note->namesz == 4 && streq (note->namedata, NOTE_NAME_GDB)) return elfcore_grok_riscv_csr (abfd, note); else return true; - case NT_LARCH_CPUCFG: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_loongarch_cpucfg (abfd, note); - else - return true; - - case NT_LARCH_LBT: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_loongarch_lbt (abfd, note); - else - return true; - - case NT_LARCH_LSX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_loongarch_lsx (abfd, note); - else - return true; - - case NT_LARCH_LASX: - if (note->namesz == 6 - && strcmp (note->namedata, "LINUX") == 0) - return elfcore_grok_loongarch_lasx (abfd, note); - else - return true; - case NT_PRPSINFO: case NT_PSINFO: if (bed->elf_backend_grok_psinfo) @@ -11421,7 +11279,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) case NT_SIGINFO: return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.siginfo", note); - } } @@ -11616,7 +11473,7 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) return false; /* Make a ".reg/999" section and a ".reg" section. */ - return _bfd_elfcore_make_pseudosection (abfd, ".reg", + return _bfd_elfcore_make_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, size, note->descpos + offset); } @@ -11658,7 +11515,7 @@ elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note) return elfcore_make_auxv_note_section (abfd, note, 4); case NT_FREEBSD_X86_SEGBASES: - return elfcore_make_note_pseudosection (abfd, ".reg-x86-segbases", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_X86_SEGBASES, note); case NT_X86_XSTATE: return elfcore_grok_xstatereg (abfd, note); @@ -11761,10 +11618,10 @@ elfcore_grok_netbsd_note (bfd *abfd, Elf_Internal_Note *note) switch (note->type) { case NT_NETBSDCORE_FIRSTMACH+0: - return elfcore_make_note_pseudosection (abfd, ".reg", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, note); case NT_NETBSDCORE_FIRSTMACH+2: - return elfcore_make_note_pseudosection (abfd, ".reg2", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG2, note); default: return true; @@ -11778,10 +11635,10 @@ elfcore_grok_netbsd_note (bfd *abfd, Elf_Internal_Note *note) switch (note->type) { case NT_NETBSDCORE_FIRSTMACH+3: - return elfcore_make_note_pseudosection (abfd, ".reg", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, note); case NT_NETBSDCORE_FIRSTMACH+5: - return elfcore_make_note_pseudosection (abfd, ".reg2", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG2, note); default: return true; @@ -11794,10 +11651,10 @@ elfcore_grok_netbsd_note (bfd *abfd, Elf_Internal_Note *note) switch (note->type) { case NT_NETBSDCORE_FIRSTMACH+1: - return elfcore_make_note_pseudosection (abfd, ".reg", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, note); case NT_NETBSDCORE_FIRSTMACH+3: - return elfcore_make_note_pseudosection (abfd, ".reg2", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG2, note); default: return true; @@ -11847,11 +11704,11 @@ elfcore_grok_solaris_prstatus (bfd *abfd, Elf_Internal_Note* note, int sig_off, elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + lwpid_off); - sect = bfd_get_section_by_name (abfd, ".reg"); + sect = bfd_get_section_by_name (abfd, NOTE_PSEUDO_SECTION_REG); if (sect != NULL) sect->size = gregset_size; - return _bfd_elfcore_make_pseudosection (abfd, ".reg", gregset_size, + return _bfd_elfcore_make_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, gregset_size, note->descpos + gregset_offset); } @@ -11885,7 +11742,7 @@ elfcore_grok_solaris_lwpstatus (bfd *abfd, Elf_Internal_Note* note, asection *sect = NULL; char reg2_section_name[16] = { 0 }; - (void) snprintf (reg2_section_name, 16, "%s/%i", ".reg2", + (void) snprintf (reg2_section_name, 16, "%s/%i", NOTE_PSEUDO_SECTION_REG2, elf_tdata (abfd)->core->lwpid); /* offsetof(lwpstatus_t, pr_lwpid) */ @@ -11895,10 +11752,10 @@ elfcore_grok_solaris_lwpstatus (bfd *abfd, Elf_Internal_Note* note, elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); - sect = bfd_get_section_by_name (abfd, ".reg"); + sect = bfd_get_section_by_name (abfd, NOTE_PSEUDO_SECTION_REG); if (sect != NULL) sect->size = gregset_size; - else if (!_bfd_elfcore_make_pseudosection (abfd, ".reg", gregset_size, + else if (!_bfd_elfcore_make_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, gregset_size, note->descpos + gregset_off)) return false; @@ -11909,7 +11766,7 @@ elfcore_grok_solaris_lwpstatus (bfd *abfd, Elf_Internal_Note* note, sect->filepos = note->descpos + fpregset_off; sect->alignment_power = 2; } - else if (!_bfd_elfcore_make_pseudosection (abfd, ".reg2", fpregset_size, + else if (!_bfd_elfcore_make_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG2, fpregset_size, note->descpos + fpregset_off)) return false; @@ -12023,13 +11880,13 @@ elfcore_grok_openbsd_note (bfd *abfd, Elf_Internal_Note *note) return elfcore_grok_openbsd_procinfo (abfd, note); if (note->type == NT_OPENBSD_REGS) - return elfcore_make_note_pseudosection (abfd, ".reg", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, note); if (note->type == NT_OPENBSD_FPREGS) - return elfcore_make_note_pseudosection (abfd, ".reg2", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG2, note); if (note->type == NT_OPENBSD_XFPREGS) - return elfcore_make_note_pseudosection (abfd, ".reg-xfp", note); + return elfcore_make_note_pseudosection (abfd, NOTE_PSEUDO_SECTION_XFP, note); if (note->type == NT_OPENBSD_AUXV) return elfcore_make_auxv_note_section (abfd, note, 0); @@ -12153,9 +12010,9 @@ elfcore_grok_nto_note (bfd *abfd, Elf_Internal_Note *note) case QNT_CORE_STATUS: return elfcore_grok_nto_status (abfd, note, &tid); case QNT_CORE_GREG: - return elfcore_grok_nto_regs (abfd, note, tid, ".reg"); + return elfcore_grok_nto_regs (abfd, note, tid, NOTE_PSEUDO_SECTION_REG); case QNT_CORE_FPREG: - return elfcore_grok_nto_regs (abfd, note, tid, ".reg2"); + return elfcore_grok_nto_regs (abfd, note, tid, NOTE_PSEUDO_SECTION_REG2); default: return true; } @@ -12305,7 +12162,7 @@ elfcore_write_prpsinfo (bfd *abfd, strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); return elfcore_write_note (abfd, buf, bufsiz, - "CORE", note_type, &data, sizeof (data)); + NOTE_NAME_CORE, note_type, &data, sizeof (data)); } else # endif @@ -12322,7 +12179,7 @@ elfcore_write_prpsinfo (bfd *abfd, strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); return elfcore_write_note (abfd, buf, bufsiz, - "CORE", note_type, &data, sizeof (data)); + NOTE_NAME_CORE, note_type, &data, sizeof (data)); } #endif /* PSINFO_T or PRPSINFO_T */ @@ -12343,7 +12200,7 @@ elfcore_write_linux_prpsinfo32 struct elf_external_linux_prpsinfo32_ugid16 data; swap_linux_prpsinfo32_ugid16_out (abfd, prpsinfo, &data); - return elfcore_write_note (abfd, buf, bufsiz, "CORE", NT_PRPSINFO, + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_PRPSINFO, &data, sizeof (data)); } else @@ -12351,7 +12208,7 @@ elfcore_write_linux_prpsinfo32 struct elf_external_linux_prpsinfo32_ugid32 data; swap_linux_prpsinfo32_ugid32_out (abfd, prpsinfo, &data); - return elfcore_write_note (abfd, buf, bufsiz, "CORE", NT_PRPSINFO, + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_PRPSINFO, &data, sizeof (data)); } } @@ -12367,7 +12224,7 @@ elfcore_write_linux_prpsinfo64 swap_linux_prpsinfo64_ugid16_out (abfd, prpsinfo, &data); return elfcore_write_note (abfd, buf, bufsiz, - "CORE", NT_PRPSINFO, &data, sizeof (data)); + NOTE_NAME_CORE, NT_PRPSINFO, &data, sizeof (data)); } else { @@ -12375,7 +12232,7 @@ elfcore_write_linux_prpsinfo64 swap_linux_prpsinfo64_ugid32_out (abfd, prpsinfo, &data); return elfcore_write_note (abfd, buf, bufsiz, - "CORE", NT_PRPSINFO, &data, sizeof (data)); + NOTE_NAME_CORE, NT_PRPSINFO, &data, sizeof (data)); } } @@ -12409,7 +12266,7 @@ elfcore_write_prstatus (bfd *abfd, prstat.pr_pid = pid; prstat.pr_cursig = cursig; memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); - return elfcore_write_note (abfd, buf, bufsiz, "CORE", + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_PRSTATUS, &prstat, sizeof (prstat)); } else @@ -12421,7 +12278,7 @@ elfcore_write_prstatus (bfd *abfd, prstat.pr_pid = pid; prstat.pr_cursig = cursig; memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); - return elfcore_write_note (abfd, buf, bufsiz, "CORE", + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_PRSTATUS, &prstat, sizeof (prstat)); } #endif /* HAVE_PRSTATUS_T */ @@ -12440,7 +12297,6 @@ elfcore_write_lwpstatus (bfd *abfd, const void *gregs) { lwpstatus_t lwpstat; - const char *note_name = "CORE"; memset (&lwpstat, 0, sizeof (lwpstat)); lwpstat.pr_lwpid = pid >> 16; @@ -12456,7 +12312,7 @@ elfcore_write_lwpstatus (bfd *abfd, gregs, sizeof (lwpstat.pr_context.uc_mcontext.__gregs)); #endif #endif - return elfcore_write_note (abfd, buf, bufsiz, note_name, + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_LWPSTATUS, &lwpstat, sizeof (lwpstat)); } #endif /* HAVE_LWPSTATUS_T */ @@ -12470,7 +12326,6 @@ elfcore_write_pstatus (bfd *abfd, int cursig ATTRIBUTE_UNUSED, const void *gregs ATTRIBUTE_UNUSED) { - const char *note_name = "CORE"; #if defined (HAVE_PSTATUS32_T) const struct elf_backend_data *bed = get_elf_backend_data (abfd); @@ -12480,7 +12335,7 @@ elfcore_write_pstatus (bfd *abfd, memset (&pstat, 0, sizeof (pstat)); pstat.pr_pid = pid & 0xffff; - buf = elfcore_write_note (abfd, buf, bufsiz, note_name, + buf = elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_PSTATUS, &pstat, sizeof (pstat)); return buf; } @@ -12491,7 +12346,7 @@ elfcore_write_pstatus (bfd *abfd, memset (&pstat, 0, sizeof (pstat)); pstat.pr_pid = pid & 0xffff; - buf = elfcore_write_note (abfd, buf, bufsiz, note_name, + buf = elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_CORE, NT_PSTATUS, &pstat, sizeof (pstat)); return buf; } @@ -12505,9 +12360,8 @@ elfcore_write_prfpreg (bfd *abfd, const void *fpregs, int size) { - const char *note_name = "CORE"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_FPREGSET, fpregs, size); + NOTE_NAME_CORE, NT_FPREGSET, fpregs, size); } char * @@ -12517,9 +12371,8 @@ elfcore_write_prxfpreg (bfd *abfd, const void *xfpregs, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_PRXFPREG, xfpregs, size); + NOTE_NAME_LINUX, NT_PRXFPREG, xfpregs, size); } char * @@ -12527,21 +12380,39 @@ elfcore_write_xstatereg (bfd *abfd, char *buf, int *bufsiz, const void *xfpregs, int size) { char *note_name; + if (get_elf_backend_data (abfd)->elf_osabi == ELFOSABI_FREEBSD) - note_name = "FreeBSD"; + note_name = NOTE_NAME_FREEBSD; else - note_name = "LINUX"; + note_name = NOTE_NAME_LINUX; + return elfcore_write_note (abfd, buf, bufsiz, note_name, NT_X86_XSTATE, xfpregs, size); } +static char * +elfcore_write_sspreg (bfd *abfd, char *buf, int *bufsiz, + const void *ssp, int size) +{ + return elfcore_write_note (abfd, buf, bufsiz, + NOTE_NAME_LINUX, NT_X86_SHSTK, ssp, size); +} + char * elfcore_write_x86_segbases (bfd *abfd, char *buf, int *bufsiz, const void *regs, int size) { - char *note_name = "FreeBSD"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_FREEBSD_X86_SEGBASES, regs, size); + NOTE_NAME_FREEBSD, NT_FREEBSD_X86_SEGBASES, + regs, size); +} + +char * +elfcore_write_i386_tls (bfd *abfd, char *buf, int *bufsiz, + const void *regs, int size) +{ + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_LINUX, NT_386_TLS, + regs, size); } char * @@ -12551,9 +12422,8 @@ elfcore_write_ppc_vmx (bfd *abfd, const void *ppc_vmx, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_PPC_VMX, ppc_vmx, size); + NOTE_NAME_LINUX, NT_PPC_VMX, ppc_vmx, size); } char * @@ -12563,9 +12433,8 @@ elfcore_write_ppc_vsx (bfd *abfd, const void *ppc_vsx, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_PPC_VSX, ppc_vsx, size); + NOTE_NAME_LINUX, NT_PPC_VSX, ppc_vsx, size); } char * @@ -12575,9 +12444,8 @@ elfcore_write_ppc_tar (bfd *abfd, 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_LINUX, NT_PPC_TAR, ppc_tar, size); } char * @@ -12587,9 +12455,8 @@ elfcore_write_ppc_ppr (bfd *abfd, 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_LINUX, NT_PPC_PPR, ppc_ppr, size); } char * @@ -12599,9 +12466,8 @@ elfcore_write_ppc_dscr (bfd *abfd, 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_LINUX, NT_PPC_DSCR, ppc_dscr, size); } char * @@ -12611,9 +12477,8 @@ elfcore_write_ppc_ebb (bfd *abfd, 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_LINUX, NT_PPC_EBB, ppc_ebb, size); } char * @@ -12623,9 +12488,8 @@ elfcore_write_ppc_pmu (bfd *abfd, 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_LINUX, NT_PPC_PMU, ppc_pmu, size); } char * @@ -12635,9 +12499,9 @@ elfcore_write_ppc_tm_cgpr (bfd *abfd, 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_LINUX, NT_PPC_TM_CGPR, + ppc_tm_cgpr, size); } char * @@ -12647,9 +12511,9 @@ elfcore_write_ppc_tm_cfpr (bfd *abfd, 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_LINUX, NT_PPC_TM_CFPR, + ppc_tm_cfpr, size); } char * @@ -12659,9 +12523,9 @@ elfcore_write_ppc_tm_cvmx (bfd *abfd, 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_LINUX, NT_PPC_TM_CVMX, + ppc_tm_cvmx, size); } char * @@ -12671,9 +12535,9 @@ elfcore_write_ppc_tm_cvsx (bfd *abfd, 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_LINUX, NT_PPC_TM_CVSX, + ppc_tm_cvsx, size); } char * @@ -12683,9 +12547,9 @@ elfcore_write_ppc_tm_spr (bfd *abfd, 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_LINUX, NT_PPC_TM_SPR, + ppc_tm_spr, size); } char * @@ -12695,9 +12559,9 @@ elfcore_write_ppc_tm_ctar (bfd *abfd, 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_LINUX, NT_PPC_TM_CTAR, + ppc_tm_ctar, size); } char * @@ -12707,9 +12571,9 @@ elfcore_write_ppc_tm_cppr (bfd *abfd, 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_LINUX, NT_PPC_TM_CPPR, + ppc_tm_cppr, size); } char * @@ -12719,9 +12583,9 @@ elfcore_write_ppc_tm_cdscr (bfd *abfd, 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_LINUX, NT_PPC_TM_CDSCR, + ppc_tm_cdscr, size); } static char * @@ -12731,9 +12595,8 @@ elfcore_write_s390_high_gprs (bfd *abfd, const void *s390_high_gprs, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_HIGH_GPRS, + NOTE_NAME_LINUX, NT_S390_HIGH_GPRS, s390_high_gprs, size); } @@ -12744,9 +12607,9 @@ elfcore_write_s390_timer (bfd *abfd, const void *s390_timer, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_TIMER, s390_timer, size); + NOTE_NAME_LINUX, NT_S390_TIMER, + s390_timer, size); } char * @@ -12756,9 +12619,9 @@ elfcore_write_s390_todcmp (bfd *abfd, const void *s390_todcmp, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_TODCMP, s390_todcmp, size); + NOTE_NAME_LINUX, NT_S390_TODCMP, + s390_todcmp, size); } char * @@ -12768,9 +12631,9 @@ elfcore_write_s390_todpreg (bfd *abfd, const void *s390_todpreg, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_TODPREG, s390_todpreg, size); + NOTE_NAME_LINUX, NT_S390_TODPREG, + s390_todpreg, size); } char * @@ -12780,9 +12643,8 @@ elfcore_write_s390_ctrs (bfd *abfd, const void *s390_ctrs, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_CTRS, s390_ctrs, size); + NOTE_NAME_LINUX, NT_S390_CTRS, s390_ctrs, size); } char * @@ -12792,9 +12654,9 @@ elfcore_write_s390_prefix (bfd *abfd, const void *s390_prefix, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_PREFIX, s390_prefix, size); + NOTE_NAME_LINUX, NT_S390_PREFIX, + s390_prefix, size); } char * @@ -12804,9 +12666,8 @@ elfcore_write_s390_last_break (bfd *abfd, const void *s390_last_break, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_LAST_BREAK, + NOTE_NAME_LINUX, NT_S390_LAST_BREAK, s390_last_break, size); } @@ -12817,9 +12678,8 @@ elfcore_write_s390_system_call (bfd *abfd, const void *s390_system_call, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_SYSTEM_CALL, + NOTE_NAME_LINUX, NT_S390_SYSTEM_CALL, s390_system_call, size); } @@ -12830,9 +12690,8 @@ elfcore_write_s390_tdb (bfd *abfd, const void *s390_tdb, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_TDB, s390_tdb, size); + NOTE_NAME_LINUX, NT_S390_TDB, s390_tdb, size); } char * @@ -12842,9 +12701,9 @@ elfcore_write_s390_vxrs_low (bfd *abfd, const void *s390_vxrs_low, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_VXRS_LOW, s390_vxrs_low, size); + NOTE_NAME_LINUX, NT_S390_VXRS_LOW, + s390_vxrs_low, size); } char * @@ -12854,9 +12713,8 @@ elfcore_write_s390_vxrs_high (bfd *abfd, const void *s390_vxrs_high, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_VXRS_HIGH, + NOTE_NAME_LINUX, NT_S390_VXRS_HIGH, s390_vxrs_high, size); } @@ -12867,9 +12725,8 @@ elfcore_write_s390_gs_cb (bfd *abfd, const void *s390_gs_cb, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_GS_CB, + NOTE_NAME_LINUX, NT_S390_GS_CB, s390_gs_cb, size); } @@ -12880,9 +12737,8 @@ elfcore_write_s390_gs_bc (bfd *abfd, const void *s390_gs_bc, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_S390_GS_BC, + NOTE_NAME_LINUX, NT_S390_GS_BC, s390_gs_bc, size); } @@ -12893,9 +12749,9 @@ elfcore_write_arm_vfp (bfd *abfd, const void *arm_vfp, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_VFP, arm_vfp, size); + NOTE_NAME_LINUX, NT_ARM_VFP, + arm_vfp, size); } char * @@ -12905,9 +12761,8 @@ elfcore_write_aarch_tls (bfd *abfd, const void *aarch_tls, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_TLS, aarch_tls, size); + NOTE_NAME_LINUX, NT_ARM_TLS, aarch_tls, size); } char * @@ -12917,9 +12772,9 @@ elfcore_write_aarch_hw_break (bfd *abfd, const void *aarch_hw_break, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_HW_BREAK, aarch_hw_break, size); + NOTE_NAME_LINUX, NT_ARM_HW_BREAK, + aarch_hw_break, size); } char * @@ -12929,9 +12784,9 @@ elfcore_write_aarch_hw_watch (bfd *abfd, const void *aarch_hw_watch, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_HW_WATCH, aarch_hw_watch, size); + NOTE_NAME_LINUX, NT_ARM_HW_WATCH, + aarch_hw_watch, size); } char * @@ -12941,9 +12796,8 @@ elfcore_write_aarch_sve (bfd *abfd, const void *aarch_sve, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_SVE, aarch_sve, size); + NOTE_NAME_LINUX, NT_ARM_SVE, aarch_sve, size); } char * @@ -12953,23 +12807,21 @@ elfcore_write_aarch_pauth (bfd *abfd, 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); + NOTE_NAME_LINUX, NT_ARM_PAC_MASK, + aarch_pauth, size); } char * elfcore_write_aarch_mte (bfd *abfd, - char *buf, - int *bufsiz, - const void *aarch_mte, - int size) + char *buf, + int *bufsiz, + const void *aarch_mte, + int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_TAGGED_ADDR_CTRL, - aarch_mte, - size); + NOTE_NAME_LINUX, NT_ARM_TAGGED_ADDR_CTRL, + aarch_mte, size); } char * @@ -12979,11 +12831,9 @@ elfcore_write_aarch_ssve (bfd *abfd, const void *aarch_ssve, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_SSVE, - aarch_ssve, - size); + NOTE_NAME_LINUX, NT_ARM_SSVE, + aarch_ssve, size); } char * @@ -12993,11 +12843,9 @@ elfcore_write_aarch_za (bfd *abfd, const void *aarch_za, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_ZA, - aarch_za, - size); + NOTE_NAME_LINUX, NT_ARM_ZA, + aarch_za, size); } /* Write the buffer of zt register values in aarch_zt (length SIZE) into @@ -13012,11 +12860,22 @@ elfcore_write_aarch_zt (bfd *abfd, const void *aarch_zt, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARM_ZT, - aarch_zt, - size); + NOTE_NAME_LINUX, NT_ARM_ZT, + aarch_zt, size); +} + +/* Write the buffer of GCS register values in AARCH_GCS (length SIZE) into + the note buffer BUF and update *BUFSIZ. ABFD is the bfd the note is being + written into. Return a pointer to the new start of the note buffer, to + replace BUF which may no longer be valid. */ + +static char * +elfcore_write_aarch_gcs (bfd *abfd, char *buf, int *bufsiz, + const void *aarch_gcs, int size) +{ + return elfcore_write_note (abfd, buf, bufsiz, NOTE_NAME_LINUX, NT_ARM_GCS, + aarch_gcs, size); } char * @@ -13026,9 +12885,8 @@ elfcore_write_arc_v2 (bfd *abfd, const void *arc_v2, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_ARC_V2, arc_v2, size); + NOTE_NAME_LINUX, NT_ARC_V2, arc_v2, size); } char * @@ -13038,9 +12896,8 @@ elfcore_write_loongarch_cpucfg (bfd *abfd, const void *loongarch_cpucfg, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_LARCH_CPUCFG, + NOTE_NAME_LINUX, NT_LARCH_CPUCFG, loongarch_cpucfg, size); } @@ -13051,9 +12908,9 @@ elfcore_write_loongarch_lbt (bfd *abfd, const void *loongarch_lbt, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_LARCH_LBT, loongarch_lbt, size); + NOTE_NAME_LINUX, NT_LARCH_LBT, + loongarch_lbt, size); } char * @@ -13063,9 +12920,9 @@ elfcore_write_loongarch_lsx (bfd *abfd, const void *loongarch_lsx, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_LARCH_LSX, loongarch_lsx, size); + NOTE_NAME_LINUX, NT_LARCH_LSX, + loongarch_lsx, size); } char * @@ -13075,9 +12932,9 @@ elfcore_write_loongarch_lasx (bfd *abfd, const void *loongarch_lasx, int size) { - char *note_name = "LINUX"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_LARCH_LASX, loongarch_lasx, size); + NOTE_NAME_LINUX, NT_LARCH_LASX, + loongarch_lasx, size); } /* Write the buffer of csr values in CSRS (length SIZE) into the note @@ -13092,9 +12949,8 @@ elfcore_write_riscv_csr (bfd *abfd, const void *csrs, int size) { - const char *note_name = "GDB"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_RISCV_CSR, csrs, size); + NOTE_NAME_GDB, NT_RISCV_CSR, csrs, size); } /* Write the target description (a string) pointed to by TDESC, length @@ -13109,9 +12965,8 @@ elfcore_write_gdb_tdesc (bfd *abfd, const void *tdesc, int size) { - const char *note_name = "GDB"; return elfcore_write_note (abfd, buf, bufsiz, - note_name, NT_GDB_TDESC, tdesc, size); + NOTE_NAME_GDB, NT_GDB_TDESC, tdesc, size); } char * @@ -13122,104 +12977,73 @@ elfcore_write_register_note (bfd *abfd, const void *data, int size) { - if (strcmp (section, ".reg2") == 0) - return elfcore_write_prfpreg (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-xfp") == 0) - return elfcore_write_prxfpreg (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-xstate") == 0) - return elfcore_write_xstatereg (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-x86-segbases") == 0) - return elfcore_write_x86_segbases (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-vmx") == 0) - return elfcore_write_ppc_vmx (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-vsx") == 0) - return elfcore_write_ppc_vsx (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tar") == 0) - return elfcore_write_ppc_tar (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-ppr") == 0) - return elfcore_write_ppc_ppr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-dscr") == 0) - return elfcore_write_ppc_dscr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-ebb") == 0) - return elfcore_write_ppc_ebb (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-pmu") == 0) - return elfcore_write_ppc_pmu (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-cgpr") == 0) - return elfcore_write_ppc_tm_cgpr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-cfpr") == 0) - return elfcore_write_ppc_tm_cfpr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-cvmx") == 0) - return elfcore_write_ppc_tm_cvmx (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-cvsx") == 0) - return elfcore_write_ppc_tm_cvsx (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-spr") == 0) - return elfcore_write_ppc_tm_spr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-ctar") == 0) - return elfcore_write_ppc_tm_ctar (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-cppr") == 0) - return elfcore_write_ppc_tm_cppr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-ppc-tm-cdscr") == 0) - return elfcore_write_ppc_tm_cdscr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-high-gprs") == 0) - return elfcore_write_s390_high_gprs (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-timer") == 0) - return elfcore_write_s390_timer (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-todcmp") == 0) - return elfcore_write_s390_todcmp (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-todpreg") == 0) - return elfcore_write_s390_todpreg (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-ctrs") == 0) - return elfcore_write_s390_ctrs (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-prefix") == 0) - return elfcore_write_s390_prefix (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-last-break") == 0) - return elfcore_write_s390_last_break (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-system-call") == 0) - return elfcore_write_s390_system_call (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-tdb") == 0) - return elfcore_write_s390_tdb (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-vxrs-low") == 0) - return elfcore_write_s390_vxrs_low (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-vxrs-high") == 0) - return elfcore_write_s390_vxrs_high (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-gs-cb") == 0) - return elfcore_write_s390_gs_cb (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-s390-gs-bc") == 0) - return elfcore_write_s390_gs_bc (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-arm-vfp") == 0) - return elfcore_write_arm_vfp (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-aarch-tls") == 0) - return elfcore_write_aarch_tls (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-aarch-hw-break") == 0) - return elfcore_write_aarch_hw_break (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-aarch-hw-watch") == 0) - 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); - if (strcmp (section, ".reg-aarch-mte") == 0) - return elfcore_write_aarch_mte (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-aarch-ssve") == 0) - return elfcore_write_aarch_ssve (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-aarch-za") == 0) - return elfcore_write_aarch_za (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-aarch-zt") == 0) - return elfcore_write_aarch_zt (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-arc-v2") == 0) - return elfcore_write_arc_v2 (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".gdb-tdesc") == 0) - return elfcore_write_gdb_tdesc (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-riscv-csr") == 0) - return elfcore_write_riscv_csr (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-loongarch-cpucfg") == 0) - return elfcore_write_loongarch_cpucfg (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-loongarch-lbt") == 0) - return elfcore_write_loongarch_lbt (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-loongarch-lsx") == 0) - return elfcore_write_loongarch_lsx (abfd, buf, bufsiz, data, size); - if (strcmp (section, ".reg-loongarch-lasx") == 0) - return elfcore_write_loongarch_lasx (abfd, buf, bufsiz, data, size); + static const struct + { + const char * section_name; + char * (*writer) (bfd *, char *, int *, const void *, int); + } + note_writers [] = + { + { NOTE_PSEUDO_SECTION_AARCH_GCS, elfcore_write_aarch_gcs}, + { NOTE_PSEUDO_SECTION_AARCH_HW_BREAK, elfcore_write_aarch_hw_break}, + { NOTE_PSEUDO_SECTION_AARCH_HW_WATCH, elfcore_write_aarch_hw_watch}, + { NOTE_PSEUDO_SECTION_AARCH_MTE, elfcore_write_aarch_mte}, + { NOTE_PSEUDO_SECTION_AARCH_PAUTH, elfcore_write_aarch_pauth}, + { NOTE_PSEUDO_SECTION_AARCH_SSVE, elfcore_write_aarch_ssve}, + { NOTE_PSEUDO_SECTION_AARCH_SVE, elfcore_write_aarch_sve}, + { NOTE_PSEUDO_SECTION_AARCH_TLS, elfcore_write_aarch_tls}, + { NOTE_PSEUDO_SECTION_AARCH_ZA, elfcore_write_aarch_za}, + { NOTE_PSEUDO_SECTION_AARCH_ZT, elfcore_write_aarch_zt}, + { NOTE_PSEUDO_SECTION_ARC_V2, elfcore_write_arc_v2}, + { NOTE_PSEUDO_SECTION_ARM_VFP, elfcore_write_arm_vfp}, + { NOTE_PSEUDO_SECTION_I386_TLS, elfcore_write_i386_tls}, + { NOTE_PSEUDO_SECTION_LOONGARCH_CPUCFG, elfcore_write_loongarch_cpucfg}, + { NOTE_PSEUDO_SECTION_LOONGARCH_LASX, elfcore_write_loongarch_lasx}, + { NOTE_PSEUDO_SECTION_LOONGARCH_LBT, elfcore_write_loongarch_lbt}, + { NOTE_PSEUDO_SECTION_LOONGARCH_LSX, elfcore_write_loongarch_lsx}, + { NOTE_PSEUDO_SECTION_PPC_DSCR, elfcore_write_ppc_dscr}, + { NOTE_PSEUDO_SECTION_PPC_EBB, elfcore_write_ppc_ebb}, + { NOTE_PSEUDO_SECTION_PPC_PMU, elfcore_write_ppc_pmu}, + { NOTE_PSEUDO_SECTION_PPC_PPR, elfcore_write_ppc_ppr}, + { NOTE_PSEUDO_SECTION_PPC_TAR, elfcore_write_ppc_tar}, + { NOTE_PSEUDO_SECTION_PPC_TM_CDSCR, elfcore_write_ppc_tm_cdscr}, + { NOTE_PSEUDO_SECTION_PPC_TM_CFPR, elfcore_write_ppc_tm_cfpr}, + { NOTE_PSEUDO_SECTION_PPC_TM_CGPR, elfcore_write_ppc_tm_cgpr}, + { NOTE_PSEUDO_SECTION_PPC_TM_CPPR, elfcore_write_ppc_tm_cppr}, + { NOTE_PSEUDO_SECTION_PPC_TM_CTAR, elfcore_write_ppc_tm_ctar}, + { NOTE_PSEUDO_SECTION_PPC_TM_CVMX, elfcore_write_ppc_tm_cvmx}, + { NOTE_PSEUDO_SECTION_PPC_TM_CVSX, elfcore_write_ppc_tm_cvsx}, + { NOTE_PSEUDO_SECTION_PPC_TM_SPR, elfcore_write_ppc_tm_spr}, + { NOTE_PSEUDO_SECTION_PPC_VMX, elfcore_write_ppc_vmx}, + { NOTE_PSEUDO_SECTION_PPC_VSX, elfcore_write_ppc_vsx}, + { NOTE_PSEUDO_SECTION_REG2, elfcore_write_prfpreg}, + { NOTE_PSEUDO_SECTION_RISCV_CSR, elfcore_write_riscv_csr}, + { NOTE_PSEUDO_SECTION_S390_CTRS, elfcore_write_s390_ctrs}, + { NOTE_PSEUDO_SECTION_S390_GS_BC, elfcore_write_s390_gs_bc}, + { NOTE_PSEUDO_SECTION_S390_GS_CB, elfcore_write_s390_gs_cb}, + { NOTE_PSEUDO_SECTION_S390_HIGH_GPRS, elfcore_write_s390_high_gprs}, + { NOTE_PSEUDO_SECTION_S390_LAST_BREAK, elfcore_write_s390_last_break}, + { NOTE_PSEUDO_SECTION_S390_PREFIX, elfcore_write_s390_prefix}, + { NOTE_PSEUDO_SECTION_S390_SYSTEM_CALL, elfcore_write_s390_system_call}, + { NOTE_PSEUDO_SECTION_S390_TDB, elfcore_write_s390_tdb}, + { NOTE_PSEUDO_SECTION_S390_TIMER, elfcore_write_s390_timer}, + { NOTE_PSEUDO_SECTION_S390_TODCMP, elfcore_write_s390_todcmp}, + { NOTE_PSEUDO_SECTION_S390_TODPREG, elfcore_write_s390_todpreg}, + { NOTE_PSEUDO_SECTION_S390_VXRS_HIGH, elfcore_write_s390_vxrs_high}, + { NOTE_PSEUDO_SECTION_S390_VXRS_LOW, elfcore_write_s390_vxrs_low}, + { NOTE_PSEUDO_SECTION_SSP, elfcore_write_sspreg}, + { NOTE_PSEUDO_SECTION_TDESC, elfcore_write_gdb_tdesc}, + { NOTE_PSEUDO_SECTION_X86_SEGBASES, elfcore_write_x86_segbases}, + { NOTE_PSEUDO_SECTION_XFP, elfcore_write_prxfpreg}, + { NOTE_PSEUDO_SECTION_XSTATE, elfcore_write_xstatereg} /* NB/ No comma. */ + }; + + int i; + + for (i = ARRAY_SIZE (note_writers); i--;) + if (streq (section, note_writers[i].section_name)) + return note_writers[i].writer (abfd, buf, bufsiz, data, size); + return NULL; } @@ -13228,7 +13052,7 @@ elfcore_write_file_note (bfd *obfd, char *note_data, int *note_size, const void *buf, int bufsiz) { return elfcore_write_note (obfd, note_data, note_size, - "CORE", NT_FILE, buf, bufsiz); + NOTE_NAME_CORE, NT_FILE, buf, bufsiz); } static bool @@ -13278,7 +13102,7 @@ elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset, case bfd_core: { #define GROKER_ELEMENT(S,F) {S, sizeof (S) - 1, F} - struct + static const struct { const char * string; size_t len; @@ -13287,13 +13111,13 @@ elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset, grokers[] = { GROKER_ELEMENT ("", elfcore_grok_note), - GROKER_ELEMENT ("FreeBSD", elfcore_grok_freebsd_note), + GROKER_ELEMENT (NOTE_NAME_FREEBSD, elfcore_grok_freebsd_note), GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note), GROKER_ELEMENT ("OpenBSD", elfcore_grok_openbsd_note), GROKER_ELEMENT ("QNX", elfcore_grok_nto_note), GROKER_ELEMENT ("SPU/", elfcore_grok_spu_note), GROKER_ELEMENT ("GNU", elfobj_grok_gnu_note), - GROKER_ELEMENT ("CORE", elfcore_grok_solaris_note) + GROKER_ELEMENT (NOTE_NAME_CORE, elfcore_grok_solaris_note) }; #undef GROKER_ELEMENT int i; @@ -13492,6 +13316,9 @@ _bfd_elf_section_offset (bfd *abfd, case SEC_INFO_TYPE_EH_FRAME: return _bfd_elf_eh_frame_section_offset (abfd, info, sec, offset); + case SEC_INFO_TYPE_SFRAME: + return _bfd_elf_sframe_section_offset (abfd, info, sec, offset); + default: if ((sec->flags & SEC_ELF_REVERSE_COPY) != 0) { |