Commit Graph

18304 Commits

Author SHA1 Message Date
Nick Clifton
c22d38baef Fix an illegal memory access when an accessing a zer0-lengthverdef table.
PR 30285
  * elf.c (_bfd_elf_slurp_version_tables): Fail if no version definitions are allocated.
2023-03-30 10:10:09 +01:00
Alan Modra
6b958fe36b Setting sh_link for SHT_REL/SHT_RELA
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-30 15:18:02 +10:30
Alan Modra
ea7672c10e Fix memory leak in bfd_get_debug_link_info_1
* 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-30 15:18:02 +10:30
GDB Administrator
8f797666d9 Automatic date update in version.in 2023-03-30 00:00:13 +00:00
Palmer Dabbelt
890744e858 RISC-V: PR28789, Reject R_RISCV_PCREL relocations with ABS symbol in PIC/PIE.
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-30 07:40:17 +08:00
Nelson Chu
b679fb488a RISC-V: Clarify link behaviors of R_RISCV_32/64 relocations with ABS symbol.
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-30 07:40:14 +08:00
Nelson Chu
23068b02d3 RISC-V: Extract the ld code which are too complicated, and may be reused.
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-30 07:40:02 +08:00
Alan Modra
aec101ab06 Sanity check section size in bfd_init_section_compress_status
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-29 12:56:46 +10:30
Alan Modra
647744420e Re: Fix an aout memory leak
We have way too much duplicated code in bfd.  Apply dd3a3d0af9 and
920581c57e to pdp11.c.

	* pdp11.c (bfd_free_cached_info): Free line_buf.  Return true
	if tdata.aout_data is NULL.
2023-03-29 12:56:46 +10:30
GDB Administrator
c3b5c85639 Automatic date update in version.in 2023-03-29 00:00:11 +00:00
Alan Modra
d75137c755 ubsan: elfnn-aarch64.c:4595:19: runtime error: load of value 190
which is not a valid value for type '_Bool'

	* elfnn-aarch64.c (stub_hash_newfunc): Clear all fields past root.
2023-03-28 12:10:28 +10:30
GDB Administrator
5d15dc7658 Automatic date update in version.in 2023-03-28 00:00:13 +00:00
Alan Modra
f00a29e30b Remove coff_pointerize_aux table_end param
I'm fairly certain the table_end checks are redundant now.  This
patch reverts commit 334d4ced42.

	* coffgen.c (coff_pointerize_aux): Remove table_end parameter.
	(coff_get_normalized_symtab): Adjust to suit.
2023-03-27 21:58:46 +10:30
Alan Modra
a2c7ca15a5 Use stdint types in coff internal_auxent
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-27 21:58:46 +10:30
Alan Modra
3bb1480e2a Set proper union selector tag
* coff-bfd.c (bfd_coff_get_auxent): After converting sym pointer
	to an index, reset the union tag.
2023-03-27 21:58:46 +10:30
Alan Modra
695c322803 coffgrok access of u.auxent.x_sym.x_tagndx.p
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-27 21:58:46 +10:30
Alan Modra
92479281c4 Duplicate DW_AT_call_file leak
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-27 21:58:46 +10:30
Alan Modra
58c4c6a0bf XCOFF sanity check
* coffcode.h (coff_pointerize_aux_hook): Sanity check
	x_csect.x_scnlen against raw_syment_count.
2023-03-27 21:58:46 +10:30
GDB Administrator
324998b473 Automatic date update in version.in 2023-03-27 00:00:07 +00:00
GDB Administrator
bc8b216886 Automatic date update in version.in 2023-03-26 00:00:07 +00:00
GDB Administrator
f06b840b9a Automatic date update in version.in 2023-03-25 00:00:08 +00:00
Alan Modra
9c26a640c7 Tidy string_ptr increment
* peicode.h (pe_ILF_make_a_symbol): Use sprintf output to
	increment string_ptr to end of new string.
2023-03-24 21:01:43 +10:30
Alan Modra
17749b3926 Tidy dwarf1 cached section contents
* 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-24 21:01:43 +10:30
GDB Administrator
232c5cec14 Automatic date update in version.in 2023-03-24 00:00:41 +00:00
Szabolcs Nagy
5834f36d93 bfd: aarch64: Optimize BTI stubs PR30076
Don't insert a second stub if the target is already compatible with
an indirect branch.
2023-03-23 12:49:32 +00:00
Szabolcs Nagy
15b4f66b0a bfd: aarch64: Fix stubs that may break BTI PR30076
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-23 12:49:32 +00:00
Szabolcs Nagy
557a2f2822 bfd: aarch64: Refactor stub sizing code
elfNN_aarch64_size_stubs has grown big, so factor out the call stub
related code before adding new logic there.
2023-03-23 12:49:32 +00:00
GDB Administrator
6891aaf70b Automatic date update in version.in 2023-03-23 00:00:59 +00:00
Alan Modra
bcefc6be97 coff_get_normalized_symtab bfd_release
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-22 10:39:18 +10:30
GDB Administrator
347ab61778 Automatic date update in version.in 2023-03-22 00:00:38 +00:00
Alan Modra
4d5b27b30b Sanity check coff-sh and coff-mcore sym string offset
* 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-22 09:06:48 +10:30
Alan Modra
317e47ee5e PR17910 sym string offset check
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-22 09:05:10 +10:30
Alan Modra
6634b21566 PE fake section for C_SECTION syms
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-22 09:02:57 +10:30
Alan Modra
509ab0875d XCOFF: use bfd_coff_close_and_cleanup
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-22 08:55:19 +10:30
GDB Administrator
003c8d67e7 Automatic date update in version.in 2023-03-21 00:00:49 +00:00
Cupertino Miranda
551fde0ae1 Reloc howto access broken for BPF
Forgot to change the logic to access the reloc howto from
bpf_elf_relocate_section.
Problem was introduced in previous BPF commit.
2023-03-20 15:35:21 +00:00
GDB Administrator
2f5dea4558 Automatic date update in version.in 2023-03-20 00:00:34 +00:00
Aditya Vidyadhar Kamath
1a2c0dc1ab Enable vector register visibility in core file for AIX binutils
This patch will enable vector register visibility when AIX FOLKS do
core file analysis.
2023-03-19 23:35:18 +10:30
Alan Modra
99b847478c XCOFF archive sanity check
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-19 22:19:19 +10:30
Alan Modra
5f51eb9397 rewrite_elf_program_header and want_p_paddr_set_to_zero
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-19 22:19:19 +10:30
GDB Administrator
52435e5ff6 Automatic date update in version.in 2023-03-19 00:00:39 +00:00
GDB Administrator
9e4b2a6697 Automatic date update in version.in 2023-03-18 00:00:41 +00:00
Alan Modra
92376883a9 mach-o: out of memory in get_dynamic_reloc_upper_bound
* mach-o.c (bfd_mach_o_canonicalize_dynamic_reloc): Move sanity
	checks..
	(bfd_mach_o_get_dynamic_reloc_upper_bound): ..to here.
2023-03-17 21:14:46 +10:30
GDB Administrator
abee4501eb Automatic date update in version.in 2023-03-17 00:00:31 +00:00
Clément Chigot
e263a66b01 readelf: add support for QNT_STACK note subsections
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-16 15:01:05 +01:00
Clément Chigot
567e0dfb01 configure: add new target aarch64-*-nto*
This target has its own ld emulation based on aarch64elf.em.
2023-03-16 15:01:05 +01:00
Cupertino Miranda
5e4c7a839d BPF relocations review / refactoring
- 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-16 09:11:09 +00:00
GDB Administrator
5a8b54ae6b Automatic date update in version.in 2023-03-16 00:00:51 +00:00
GDB Administrator
48c35a820d Automatic date update in version.in 2023-03-15 00:00:51 +00:00
GDB Administrator
712d71a24a Automatic date update in version.in 2023-03-14 00:01:02 +00:00