aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2023-03-30Fix an illegal memory access when an accessing a zer0-lengthverdef table.Nick Clifton2-0/+11
PR 30285 * elf.c (_bfd_elf_slurp_version_tables): Fail if no version definitions are allocated.
2023-03-30Setting sh_link for SHT_REL/SHT_RELAAlan Modra1-14/+16
It's wrong to have an alloc reloc section trying to use a non-alloc symbol table. * elf.c (assign_section_numbers <SHT_REL, SHT_RELA>): Correct comment. Always set sh_link to .dynsym for alloc reloc sections and to .symtab for non-alloc.
2023-03-30Fix memory leak in bfd_get_debug_link_info_1Alan Modra2-13/+9
* opncls.c (bfd_get_alt_debug_link_info): Don't bother freeing after bfd_malloc_and_get_section failure. (get_build_id): Likewise. (bfd_get_debug_link_info_1): Likewise. Free section contents when crc not present. * section.c (bfd_malloc_and_get_section): Document that the buffer is NULL on error return.
2023-03-30Automatic date update in version.inGDB Administrator1-1/+1
2023-03-30RISC-V: PR28789, Reject R_RISCV_PCREL relocations with ABS symbol in PIC/PIE.Palmer Dabbelt1-0/+41
The non-preemptible SHN_ABS symbol with a pc-relative relocation should be disallowed when generating shared object (pic and pie). Generally, the following cases, which refer to pr25749, will cause a symbol be non-preemptible, * -pie, or -shared with -symbolic * STV_HIDDEN, STV_INTERNAL, STV_PROTECTED * Have dynamic symbol table, but without the symbol * VER_NDX_LOCAL However, PCREL_HI20/LO12 relocs are always bind locally when generating shared object, so not only the non-preemptible absolute symbol need to be disallowed, all absolute symbol references need but except that they are defined in linker script. If we also disallow the absolute symbol in linker script, then the glibc-linux toolchain build failed, so regard them as pc-relative symbols, just like what x86 did. Maybe we should add this check for all pc-relative relocations, rather than just handle in R_RISCV_PCREL relocs. Ideally, since the value of SHN_ABS symbol is a constant, only S - A relocations should be allowed in the shared object, so only BFD_RELOC_8/16/32/64 are allowed, which means R_RISCV_32/R_RISCV_64. bfd/ PR 28789 * elfnn-riscv.c (riscv_elf_check_relocs): The absolute symbol cannot be referneced with pc-relative relocation when generating shared object. ld/ PR 28789 * ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * ld/testsuite/ld-riscv-elf/pcrel-reloc*: New testcases.
2023-03-30RISC-V: Clarify link behaviors of R_RISCV_32/64 relocations with ABS symbol.Nelson Chu1-8/+53
There are two improvements, which are all referenced to aarch64, * R_RISCV_32 with non ABS symbol cannot be used under RV64 when making shard objects. * Don't need dynamic relocation for R_RISCV_32/64 under RV32/RV64 when making shared objects, if the referenced symbol is local ABS symbol. However, considering this link, https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/341 Seems like we should makes all R_RISCV_32/64 relocs with ABS symbol that don't need any dynamic relocations when making the shared objects. But anyway, I just sync the current behavior as aarch64 ld, in case there are any unexpected behaviors happen. Passed the gcc/binutils regressions in riscv-gnu-toolchain. bfd/ * elfnn-riscv.c (riscv_elf_check_relocs): Only allow R_RISCV_32 with ABS symbol under RV64. (riscv_elf_relocate_section): R_RISCV_32/64 with local ABS symbol under RV32/RV64 doesn't need any dynamic relocation when making shared objects. I just make the implementations similar to other targets, so that will be more easy to mainatain. ld/ * testsuite/ld-riscv-elf/data-reloc*: New testcases. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Added new data-reloc* testcases, and need to make ifunc-seperate* testcases work for rv32. * testsuite/ld-riscv-elf/ifunc-seperate-caller-nonplt.s: Likewise. * testsuite/ld-riscv-elf/ifunc-seperate-caller-plt.s: Likewise.
2023-03-30RISC-V: Extract the ld code which are too complicated, and may be reused.Nelson Chu1-74/+82
These types of codes are different for each target, I am not sure what are the best for RISC-V, so extract them out may be more easy to compare what's the difference. bfd/ * elfnn-riscv.c (RISCV_NEED_DYNAMIC_RELOC): New defined. Extracted from riscv_elf_check_relocs, to see if dynamic reloc is needed for the specific relocation. (RISCV_GENERATE_DYNAMIC_RELOC): New defined. Extracted from riscv_elf_relocate_section, to see if R_RISCV_32/64 need to generate dynamic relocation. (RISCV_COPY_INPUT_RELOC): New defined. Extracted from riscv_elf_relocate_section, to see if R_RISCV_32/64 need to copy itslef tp output file. (RISCV_RESOLVED_LOCALLY): New defined. Extracted from riscv_elf_relocate_section, to see if R_RISCV_GOT_HI20 can be resolved locally.
2023-03-29Sanity check section size in bfd_init_section_compress_statusAlan Modra1-1/+2
This function doesn't just initialise for compression, it actually compresses. This patch sanity checks section size before allocating buffers for the uncompressed contents. * compress.c (bfd_init_section_compress_status): Sanity check section size.
2023-03-29Re: Fix an aout memory leakAlan Modra1-2/+3
We have way too much duplicated code in bfd. Apply dd3a3d0af9f6 and 920581c57e08 to pdp11.c. * pdp11.c (bfd_free_cached_info): Free line_buf. Return true if tdata.aout_data is NULL.
2023-03-29Automatic date update in version.inGDB Administrator1-1/+1
2023-03-28ubsan: elfnn-aarch64.c:4595:19: runtime error: load of value 190Alan Modra1-8/+3
which is not a valid value for type '_Bool' * elfnn-aarch64.c (stub_hash_newfunc): Clear all fields past root.
2023-03-28Automatic date update in version.inGDB Administrator1-1/+1
2023-03-27Remove coff_pointerize_aux table_end paramAlan Modra1-9/+4
I'm fairly certain the table_end checks are redundant now. This patch reverts commit 334d4ced42d3. * coffgen.c (coff_pointerize_aux): Remove table_end parameter. (coff_get_normalized_symtab): Adjust to suit.
2023-03-27Use stdint types in coff internal_auxentAlan Modra9-95/+93
long is a poor choice of type to store 32-bit values read from objects files by H_GET_32. H_GET_32 doesn't sign extend so tests like that in gdb/coffread.c for "negative" values won't work if long is larger than 32 bits. If long is 32-bit then code needs to be careful to not accidentally index negative array elements. (I'd rather see a segfault on an unmapped 4G array index than silently reading bogus data.) long is also a poor choice for x_sect.s_scnlen, which might have 64-bit values. It's better to use unsigned exact width types to avoid surprises. I decided to change the field names too, which makes most of this patch simply renaming. Besides that there are a few places where casts are no longer needed, and where printf format strings or tests need adjusting. include/ * coff/internal.h (union internal_auxent): Use unsigned stdint types. Rename l fields to u32 and u64 as appropriate. bfd/ * coff-bfd.c, * coff-rs6000.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * coffswap.h, * peXXigen.c, * xcofflink.c: Adjust to suit internal_auxent changes. binutils/ * rdcoff.c: Adjust to suit internal_auxent changes. gas/ * config/obj-coff.h, * config/tc-ppc.c: Adjust to suit internal_auxent changes. gdb/ * coffread.c, * xcoffread.c: Adjust to suit internal_auxent changes. ld/ * pe-dll.c: Adjust to suit internal_auxent changes.
2023-03-27Set proper union selector tagAlan Modra1-9/+18
* coff-bfd.c (bfd_coff_get_auxent): After converting sym pointer to an index, reset the union tag.
2023-03-27coffgrok access of u.auxent.x_sym.x_tagndx.pAlan Modra2-30/+30
u.auxent.x_sym.x_tagndx is a union. The p field is only valid when fix_tag is set. This patch fixes code in coffgrok.c that accessed the field without first checking fix_tag, and removes a whole lot of code validating bogus pointers to prevent segfaults (which no longer happen, I checked the referenced PR 17512 testcases). The patch also documents this in the fix_tag comment, makes is_sym a bitfield, and sorts the selecter fields a little. bfd/ * coffcode.h (combined_entry_type): Make is_sym a bitfield. Sort and comment on union selectors. * libcoff.h: Regenerate. binutils/ * coffgrok.c (do_type): Make aux a combined_entry_type. Test fix_tag before accessing u.auxent.x_sym.x_tagndx.p. Remove now unnecessary pointer bounds checking.
2023-03-27Duplicate DW_AT_call_file leakAlan Modra1-2/+5
When given two or more DW_AT_call_file for a given function we currently leak the concat memory. * dwarf2.c (scan_unit_for_symbols): Don't leak on duplicate DW_AT_call_file.
2023-03-27XCOFF sanity checkAlan Modra1-1/+2
* coffcode.h (coff_pointerize_aux_hook): Sanity check x_csect.x_scnlen against raw_syment_count.
2023-03-27Automatic date update in version.inGDB Administrator1-1/+1
2023-03-26Automatic date update in version.inGDB Administrator1-1/+1
2023-03-25Automatic date update in version.inGDB Administrator1-1/+1
2023-03-24Tidy string_ptr incrementAlan Modra1-2/+2
* peicode.h (pe_ILF_make_a_symbol): Use sprintf output to increment string_ptr to end of new string.
2023-03-24Tidy dwarf1 cached section contentsAlan Modra5-1/+22
* dwarf1.c (_bfd_dwarf1_cleanup_debug_info): New function. * libbfd-in.h (_bfd_dwarf1_cleanup_debug_info): Declare. * elf.c (_bfd_elf_close_and_cleanup): Call it. * elf-bfd.h (struct elf_obj_tdata): Make dwarf1_find_line_info a void*. * libbfd.h: Regenerate.
2023-03-24Automatic date update in version.inGDB Administrator1-1/+1
2023-03-23bfd: aarch64: Optimize BTI stubs PR30076Szabolcs Nagy1-4/+32
Don't insert a second stub if the target is already compatible with an indirect branch.
2023-03-23bfd: aarch64: Fix stubs that may break BTI PR30076Szabolcs Nagy1-15/+160
Insert two stubs in a BTI enabled binary when fixing long calls: The first is near the call site and uses an indirect jump like before, but it targets the second stub that is near the call target site and uses a direct jump. This is needed when a single stub breaks BTI compatibility. The stub layout is kept fixed between sizing and building the stubs, so the location of the second stub is known at build time, this may introduce padding between stubs when those are relaxed. Stub layout with BTI disabled is unchanged.
2023-03-23bfd: aarch64: Refactor stub sizing codeSzabolcs Nagy1-273/+279
elfNN_aarch64_size_stubs has grown big, so factor out the call stub related code before adding new logic there.
2023-03-23Automatic date update in version.inGDB Administrator1-1/+1
2023-03-22coff_get_normalized_symtab bfd_releaseAlan Modra1-4/+1
We can't free "internal" on errors, since bfd_coff_swap_sym_in may call bfd_alloc. For example, _bfd_XXi_swap_sym_in may even create new sections, which use bfd_alloc'd memory. If "internal" is freed, all more recently bfd_alloc'd memory is also freed. * coffgen.c (coff_get_normalized_symtab): Don't bfd_release on error.
2023-03-22Automatic date update in version.inGDB Administrator1-1/+1
2023-03-22Sanity check coff-sh and coff-mcore sym string offsetAlan Modra2-2/+13
* coff-mcore.c (coff_mcore_relocate_section): Sanity check sym string offset when setting up name for use by error messages. * coff-sh.c (sh_relocate_section): Likewise.
2023-03-22PR17910 sym string offset checkAlan Modra2-4/+2
As far as I can see the only place that sets obj_coff_strings without setting obj_coff_strings_len is pe_ILF_build_a_bfd. Fix that and we can simplify the sym string offset check. This is just a tidy. pe_ILF_build_a_bfd doesn't create bad symbols and _bfd_coff_read_string_table will always result in non-zero obj_coff_strings_len when obj_coff_strings is non-NULL. PR 17910 * coffgen.c (_bfd_coff_internal_syment_name): Always sanity check sym string offset. * peicode.h (pe_ILF_build_a_bfd): Set obj_coff_strings_len.
2023-03-22PE fake section for C_SECTION symsAlan Modra1-12/+2
It's an odd thing to have objdump -x show a different section table to objdump -h, but that can happen if swapping in symbols leads to creating sections. Setting SEC_LINKER_CREATED stops the display of these sections, so that you get shown what is in the object file. * peXXigen.c (_bfd_XXi_swap_sym_in): Set SEC_LINKER_CREATED on fake section created for C_SECTION syms. Don't zero asection fields that are already zero.
2023-03-22XCOFF: use bfd_coff_close_and_cleanupAlan Modra2-3/+3
Free memory on closing bfds. The COFF close_and_cleanup does more work than _bfd_generic_close_and_cleanup (defined as _bfd_archive_close_and_cleanup). * coff-rs6000.c (_bfd_xcoff_close_and_cleanup): Define as _bfd_coff_close_and_cleanup. * coff64-rs6000.c (rs6000_xcoff64_vec, rs6000_xcoff64_aix_vec): Use _bfd_coff_close_and_cleanup.
2023-03-21Automatic date update in version.inGDB Administrator1-1/+1
2023-03-20Reloc howto access broken for BPFCupertino Miranda1-1/+4
Forgot to change the logic to access the reloc howto from bpf_elf_relocate_section. Problem was introduced in previous BPF commit.
2023-03-20Automatic date update in version.inGDB Administrator1-1/+1
2023-03-19Enable vector register visibility in core file for AIX binutilsAditya Vidyadhar Kamath2-1/+36
This patch will enable vector register visibility when AIX FOLKS do core file analysis.
2023-03-19XCOFF archive sanity checkAlan Modra1-4/+10
XCOFF archive elements are in a linked list. Add a little more sanity checking. This of course doesn't stop the fuzzers finding a way to make a loop, but this check is cheap. * coff-rs6000.c (_bfd_xcoff_openr_next_archived_file): Sanity check that next element isn't pointing back to the header.
2023-03-19rewrite_elf_program_header and want_p_paddr_set_to_zeroAlan Modra1-7/+8
Layout in rewrite_elf_program_header is really done by lma, even if program headers are going to have their p_paddr forced to zero. Thus when not matching against an existing segment, don't try to use a "vma" from elf_segment_map. * elf.c (is_contained_by): Replace "bed" param with "use_vaddr". (IS_SECTION_IN_INPUT_SEGMENT): Adjust is_contained_by call. (rewrite_elf_program_header): Always match against lma in calls to is_contained_by using new maps.
2023-03-19Automatic date update in version.inGDB Administrator1-1/+1
2023-03-18Automatic date update in version.inGDB Administrator1-1/+1
2023-03-17mach-o: out of memory in get_dynamic_reloc_upper_boundAlan Modra1-26/+29
* mach-o.c (bfd_mach_o_canonicalize_dynamic_reloc): Move sanity checks.. (bfd_mach_o_get_dynamic_reloc_upper_bound): ..to here.
2023-03-17Automatic date update in version.inGDB Administrator1-1/+1
2023-03-16readelf: add support for QNT_STACK note subsectionsClément Chigot1-9/+4
QNX provides some .note subsections. QNT_STACK is the one controling the stack allocation. bfd/ChangeLog: * elf.c (BFD_QNT_CORE_INFO): Delete. (BFD_QNT_CORE_STATUS): Likewise. (BFD_QNT_CORE_GREG): Likewise. (BFD_QNT_CORE_FPREG): Likewise. (elfcore_grok_nto_note): Replace BFD_QNT_* by QNT_*. binutils/ChangeLog: * readelf.c (get_qnx_elfcore_note_type): New function. (print_qnx_note): New function. (process_note): Add support for QNX support. include/ChangeLog: * elf/common.h (QNT_DEBUG_FULLPATH): New define. (QNT_DEBUG_RELOC): New define. (QNT_STACK): New define. (QNT_GENERATOR): New define. (QNT_DEFAULT_LIB): New define. (QNT_CORE_SYSINFO): New define. (QNT_CORE_INFO): New define. (QNT_CORE_STATUS): New define. (QNT_CORE_GREG): New define. (QNT_CORE_FPREG): New define. (QNT_LINK_MAP): New define.
2023-03-16configure: add new target aarch64-*-nto*Clément Chigot1-1/+1
This target has its own ld emulation based on aarch64elf.em.
2023-03-16BPF relocations review / refactoringCupertino Miranda5-279/+121
- Removed not needed relocations. - Renamed relocations to match llvm and linux kernel. Relocation changes: R_BPF_INSN_64 => R_BPF_64_64 R_BPF_INSN_DISP32 => R_BPF_64_32 R_BPF_DATA_32 => R_BPF_64_ABS32 R_BPF_DATA_64 => R_BPF_64_ABS64 ChangeLog: * bfd/bpf-reloc.def: Created file with BPF_HOWTO macro entries. * bfd/reloc.c: Removed non needed relocations. * bfd/bfd-in2.h: regenerated. * bfd/libbfd.h: regenerated. * bfd/elf64-bpf.c: Changed relocations. * include/elf/bpf.h: Adapted relocation values/names. * gas/config/tc-bpf.c: Changed relocation mapping.
2023-03-16Automatic date update in version.inGDB Administrator1-1/+1
2023-03-15Automatic date update in version.inGDB Administrator1-1/+1
2023-03-14Automatic date update in version.inGDB Administrator1-1/+1