Commit Graph

18760 Commits

Author SHA1 Message Date
GDB Administrator
2285e8952a Automatic date update in version.in 2023-11-02 00:00:15 +00:00
GDB Administrator
f514e6e480 Automatic date update in version.in 2023-11-01 00:00:16 +00:00
GDB Administrator
a05b22b6c7 Automatic date update in version.in 2023-10-31 00:00:22 +00:00
Nick Clifton
a4a51292bb Accept and ignore the R_BPF_64_NODLYD32 relocation. 2023-10-30 12:18:45 +00:00
GDB Administrator
5ea615a22b Automatic date update in version.in 2023-10-30 00:00:18 +00:00
GDB Administrator
ca362799ee Automatic date update in version.in 2023-10-29 00:00:08 +00:00
GDB Administrator
c62e5702f6 Automatic date update in version.in 2023-10-28 00:00:07 +00:00
Nelson Chu
2029e13917 RISC-V: Clarify the behaviors of SET/ADD/SUB relocations.
We are used to generate these kinds of relocations by data directives.
Considering the following example,
.word (A + 3) - (B + 2)
The GAS will generate a pair of ADD/SUB for this,
R_RISCV_ADD, A + 1
R_RISCV_SUB, 0

The addend of R_RISCV_SUB will always be zero, and the summary of the
constants will be stored in the addend of R_RISCV_ADD/SET.  Therefore,
we can always add the addend of these data relocations when doing relocations.

But unfortunately, I had heard that if we are using .reloc to generate
the data relocations will make the relocations failed.  Refer to this,
.reloc offset, R_RISCV_ADD32, A + 3
.reloc offset, R_RISCV_SUB32, B + 2
.word 0
Then we can get the relocations as follows,
R_RISCV_ADD, A + 3
R_RISCV_SUB, B + 2
Then...  Current LD does the relocation, B - A + 3 + 2, which is wrong
obviously...

So first of all, this patch fixes the wrong relocation behavior of
R_RISCV_SUB* relocations.

Afterwards, considering the uleb128 direcitve, we will get a pair of
SET_ULEB128/SUB_ULEB128 relocations for it for now,
.uleb128 (A + 3) - (B + 2)
R_RISCV_SET_ULEB128, A + 1
R_RISCV_SUB_ULEB128, B + 1

Which looks also wrong obviously, the summary of the constants should only
be stored into the addend of SET_ULEB128, and the addend of SUB_ULEB128 should
be zero like other SUB relocations.  But the current LD will still get the right
relocation values since we only add the addend of SUB_ULEB128 by accident...
Anyway, this patch also fixes the behaviors above, to make sure that no matter
using .uleb128 or .reloc directives, we should always get the right values.

bfd/
	* elfnn-riscv.c (perform_relocation):  Clarify that SUB relocations
	should substract the addend, rather than add.
	(riscv_elf_relocate_section): Since SET_ULEB128 won't go into
	perform_relocation, we should add it's addend here in advance.
gas/
	* config/tc-riscv.c (riscv_insert_uleb128_fixes): Set the addend of
	SUB_ULEB128 to zero since it should already be added into the addend
	of SET_ULEB128.
2023-10-27 08:33:19 +08:00
GDB Administrator
1c47569f53 Automatic date update in version.in 2023-10-27 00:00:08 +00:00
GDB Administrator
eefa1c2a64 Automatic date update in version.in 2023-10-26 00:00:29 +00:00
Alan Modra
7ac6d0c38c asan: _bfd_elf_slurp_version_tables memory leak
Extends commit 6136093c0d to handle verdefs as well as verrefs.

	PR 30886
	* elf.c (_bfd_elf_slurp_version_tables): See free_contents for
	verdefs too.  Use free_contents rather than elf_tdata fields.
2023-10-25 11:12:11 +10:30
Alan Modra
220be06018 asan: out of memory in som_set_reloc_info
Sections without SEC_HAS_CONTENTS avoid the file size checks, and of
course it doesn't make sense to read such as the contents are all
zero.

	* som.c (som_set_reloc_info): Don't read sections without contents.
2023-10-25 11:12:11 +10:30
Alan Modra
e3afa68558 asan: NULL deref in alpha_ecoff_get_relocated_section_contents
This fixes some holes found by fuzzers, and removes aborts that can be
triggered by user input to objdump.  Abort should only be used within
bfd to show programming errors in bfd.

	* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Handle
	NULL howto.  Don't abort on stack errors or on unexpected relocs.
	Show more bfd reloc status messages.
2023-10-25 11:12:11 +10:30
GDB Administrator
f959280488 Automatic date update in version.in 2023-10-25 00:00:25 +00:00
Lulu Cai
f87cf663af as: fixed internal error when immediate value of relocation overflow.
The as and ld use _bfd_error_handler to output error messages when
checking relocation alignment and relocation overflow. However, the
abfd value passed by as to the function is NULL, resulting in an
internal error. The ld passes a non-null value to the function,
so it can output an error message normally.
2023-10-24 15:27:39 +08:00
GDB Administrator
8bf3b48f72 Automatic date update in version.in 2023-10-24 00:00:35 +00:00
GDB Administrator
4d47dfdba3 Automatic date update in version.in 2023-10-23 00:00:07 +00:00
Alan Modra
23cdc1d6da bfd-in2.h BFD_RELOC_* comments
I noticed the regenerated BFD_RELOC_MICROBLAZE_32_NONE comment didn't
match that committed to bfd-in2.h, and was just going to regen
bfd-in2.h but then decided to do something about the silly formatting
of these comments in bfd-in2.h.  eg. the BFD_RELOC_MICROBLAZE_32_NONE
comment:

-/* This is a 32 bit reloc that stores the 32 bit pc relative
-value in two words (with an imm instruction).No relocation is
-done here - only used for relaxing  */
+  /* This is a 32 bit reloc that stores the 32 bit pc relative value in
+     two words (with an imm instruction).  No relocation is done here -
+     only used for relaxing.  */
   BFD_RELOC_MICROBLAZE_32_NONE,

You'll notice how the second and third line of the original comment
aren't indented properly relative to the first line, and the whole
comment needs to be indented to match the code.

I've also edited reloc.c ENUMDOC paragraphs.  Some of these had excess
indentation, presumably in an attempt to properly indent bfd-in2.h
comments but that fails due to chew.c removing leading whitespace
early by skip_white_and_stars.  COMMENT was used in reloc.c to add
extra blank lines in bfd-in2.h.  I've removed them too as I don't
think they add anything to readability of that file.  (Perhaps more
usefully, they also add blank lines to libbfd.h separating relocs for
one target from others, but this isn't done consistently.)

	* doc/chew.c (drop, idrop): Move earlier.
	(strip_trailing_newlines): Check index before accessing array,
	not after.
	(wrap_comment): New function.
	(main): Add "wrap_comment" intrinsic.
	* doc/proto.str (ENUMDOC): Use wrap_comment.
	(make_enum_header, ENDSENUM): Put start and end braces on
	separate lines.
	* reloc.c: Remove uses of COMMENT and edit ENUMDOC paragraphs.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
2023-10-23 10:02:53 +10:30
GDB Administrator
d249c8a63a Automatic date update in version.in 2023-10-22 00:00:08 +00:00
GDB Administrator
4a6daabb94 Automatic date update in version.in 2023-10-21 00:00:07 +00:00
Neal Frager
d605374748 bfd: microblaze: Add 32_NONE reloc type
This patch adds the R_MICROBLAZE_32_NONE relocation type.
This is a 32-bit reloc that stores the 32-bit pc relative
value in two words (with an imm instruction).

Add test case to gas test suite.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
2023-10-20 07:12:30 -07:00
GDB Administrator
4781e165dc Automatic date update in version.in 2023-10-20 00:00:11 +00:00
Nelson Chu
d08515a68e RISC-V: Don't do undefweak relaxations for the linker_def symbols.
I get the following truncated errors recently when running riscv-gnu-toolchain
regressions,

/scratch/riscv-gnu-toolchain/regression/build/linux-rv32imafdc-ilp32d-medlow/build-glibc-linux-rv32imafdc-ilp32d/libc.a(libc-start.o): in function `elf_irela':
/scratch/riscv-gnu-toolchain/glibc/csu/../sysdeps/riscv/dl-irel.h:47:(.text+0x88): relocation truncated to fit: R_RISCV_GPREL_I against symbol `__ehdr_start' defined in .note.ABI-tag section in /scratch/riscv-gnu-toolchain/regression/build/linux-rv32imafdc-ilp32d-medlow/build-glibc-linux-rv32imafdc-ilp32d/elf/sln

The linker_def symbols like __ehdr_start that may be undefweak in early stages
of linking, including relax stage, but are guaranteed to be defined later.
Therefore, it seems like we shouldn't do the undefweak relaxations for these
kinds of symbols since they may be defined after relaxations.

bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_section): Don't do undefweak
	relaxations for the linker_def symbols.
2023-10-19 12:19:53 +08:00
GDB Administrator
e734b3e980 Automatic date update in version.in 2023-10-19 00:00:24 +00:00
caiyinyu
85ad846e72 LoongArch: Correct comments. 2023-10-18 08:58:05 +08:00
GDB Administrator
cc45b28991 Automatic date update in version.in 2023-10-18 00:00:14 +00:00
mengqinggang
3233ad1e4e LoongArch: readelf -d RELASZ excludes .rela.plt size
Before, readelf -d RELASZ is the sum of .rela.dyn size and .rela.plt size.
To consistent with LoongArch lld, RELASZ chang to only the size of .rela.dyn.
2023-10-17 14:57:04 +08:00
Alan Modra
84f24adc5b asan: Invalid free in alpha_ecoff_get_relocated_section_contents
This fixes an ancient bug in commit a3a33af390 (which makes me think
this code has never been used).

	* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Iterate
	through reloc_vector using a temp.
2023-10-17 15:17:25 +10:30
GDB Administrator
43b1a3cb34 Automatic date update in version.in 2023-10-17 00:00:45 +00:00
Nick Clifton
fd00374fc7 Fix: GNU-ld: ARM: Issues when trying to set target output architecture
PR 28910
  * elf32-arm.c (elf32_arm_merge_private_bfd_data): Do not set output flags if the input flags have not been set.
2023-10-16 16:11:49 +01:00
Tsukasa OI
f1a0961ee0 RISC-V: Remove RV64E conflict
Since RV32E *and* RV64E are ratified, RV64E is no longer invalid.

This commit removes a restriction that prevents making base ISA with
reduced GPRs with XLEN > 32.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_parse_check_conflicts): Remove RV64E
	conflict since the ratified 'E' base ISAs include RV64E.

gas/ChangeLog:

	* testsuite/gas/riscv/march-fail-base-02.d: Removed.
	* testsuite/gas/riscv/march-fail-base-02.l: Removed.
2023-10-16 04:11:07 +00:00
GDB Administrator
de59d50076 Automatic date update in version.in 2023-10-16 00:00:38 +00:00
GDB Administrator
cd09b5ddef Automatic date update in version.in 2023-10-15 00:00:40 +00:00
GDB Administrator
5e2c9ce9c0 Automatic date update in version.in 2023-10-14 00:00:37 +00:00
GDB Administrator
59fed66dce Automatic date update in version.in 2023-10-13 00:00:30 +00:00
Andrew Burgess
b8ead7d503 bfd: add new bfd_cache_size() function
In GDB we have a problem with the BFD cache.

As GDB runs for a potentially extended period of time, if the BFD
cache holds a file descriptor for an open on-disk file, this can, on
some targets (e.g. Win32) prevent the OS writing to the file.

This might, for example, prevent a user from recompiling their
executable as GDB is (via the BFD cache) holding an open reference to
that file.

Another problem, relates to bfd_stat, for BFDs that are using the BFD
cache (i.e. they call cache_bstat to implement bfd_stat).  The
cache_bstat function finds the BFD in the cache, opening the file if
needed, and then uses fstat on the open file descriptor.

What this means is that, if the on-disk file changes, but the cache
was holding an open reference to the file, the bfd_stat will return
the 'struct stat' for the old file, not the new file.

Now, for this second problem, we might be tempted to make use of an
actual stat call, instead of calling bfd_stat, however, this isn't
ideal as we have some BFDs that use a custom iovec, and implement the
various functions over GDB's remote protocol.  By using bfd_stat we
can have a single call that should work for both local files, and for
remote files.

To solve both of these problems GDB has calls to bfd_cache_close_all
sprinkled around its code base.  And in theory this should work fine.

However, I recently ran into a case where we had missed a
bfd_cache_close_all call, and as a result some BFDs were held open.
This caused a bfd_stat call to return an unexpected result (old file
vs new file).

What I'd like is some way within GDB that I can do:

  gdb_assert ( /* Nothing is held open in the cache.  */ );

As this would allow GDB to quickly identify when we've missed some
bfd_cache_close_all calls.

And so, to support this, I would like to add a new bfd_cache_size
function.  This function returns an integer, which is the number of
open files in the cache.  I can then start adding:

  gdb_assert (bfd_cache_size() == 0);

to GDB in some strategic spots, and start fixing all of the missing
bfd_cache_close_all calls that crop up as a result.
2023-10-12 13:59:04 +01:00
Andrew Burgess
241f29fba6 bfd/cache: change type used to track cached BFDs from int to unsigned
Within bfd/cache.c change the type for max_open_files and open_files
variables from int to unsigned.  As a consequence of this, the return
type for bfd_cache_max_open() is also changed from int to unsigned.

Within bfd_cache_max_open I've left the local 'max' variable as an
int, this should ensure that if the sysconf call fails, and returns
-1, then the computed max value will be less than 10, which means
max_open_files will be set to 10.  If 'max' was changed to unsigned
then, should the sysconf call fail, we'd end up with max becoming a
very large positive number ... which is clearly not what we want.

And, while I was auditing how open_files is used, I added an assert
within bfd_cache_delete to ensure that we don't try to reduce
open_files below zero.

There should be no user visible change with this commit.
2023-10-12 13:58:19 +01:00
GDB Administrator
4b41a55fe5 Automatic date update in version.in 2023-10-12 00:00:55 +00:00
GDB Administrator
e6587c5e66 Automatic date update in version.in 2023-10-11 00:00:38 +00:00
Alan Modra
ae0d827fa4 asan: buffer overflow in elf32_arm_get_synthetic_symtab
Guard against fuzzed files where .plt size isn't commensurate with
plt relocations.

	* elf32-arm.c (elf32_arm_plt0_size): Add data_size param.
	Return -1 if data_size is too small.
	(elf32_arm_plt_size): Likewise.  Delete temp var.  Formatting.
	(elf32_arm_get_synthetic_symtab): Adjust to suit.
2023-10-10 22:17:29 +10:30
Alan Modra
322b071c45 asan: invalid free in bfd_init_section_compress_status
With specially crafted compressed sections, it's possible to tickle a
problem when decompressing:  If the compression headers says the
uncompressed size is zero, this will be seen as an error return from
bfd_compress_section_contents.  On errors the caller should free any
malloc'd input buffers, but this isn't really an error and the section
contents have been updated to a bfd_alloc'd buffer which can't be
freed.

	* compress.c (bfd_compress_section_contents): Return -1 as error
	rather than 0.
	(bfd_init_section_compress_status, bfd_compress_section): Adjust.
2023-10-10 22:17:29 +10:30
GDB Administrator
d883c61283 Automatic date update in version.in 2023-10-10 00:00:49 +00:00
Nick Clifton
cb0f1baf44 Fix: Null pointer dereference in elf32-i386.c
PR 30950
  * elf32-i386.c (elf_i386_convert_load_reloc): Check for elf_x86_hash_table returning a NULL pointer.
2023-10-09 16:53:27 +01:00
Nick Clifton
e7c3fa04b6 Fix: A potential bug of null pointer dereference
PR 30949
  * elflink.c (elf_gc_mark_debug_section): Check for bfd_section_from_elf_index returning a NULL pointer.
2023-10-09 15:14:52 +01:00
GDB Administrator
4503c19bc5 Automatic date update in version.in 2023-10-09 00:00:25 +00:00
GDB Administrator
b68c661196 Automatic date update in version.in 2023-10-08 00:00:44 +00:00
Michael J. Eager
a3f6124483 Revert "opcodes: microblaze: Add new bit-field instructions"
This reverts commit 6bbf249557.

Maciej W. Rozycki <macro@orcam.me.uk>:
 Yet it has caused numerous regressions:

microblaze-elf  +FAIL: unordered .debug_info references to .debug_ranges
microblaze-elf  +FAIL: binutils-all/pr26548
microblaze-elf  +FAIL: readelf -Wwi pr26548e (reason: unexpected output)
microblaze-elf  +FAIL: readelf --debug-dump=loc locview-1 (reason: unexpected output) Yet it has caused numerous regressions:
microblaze-elf  +FAIL: unordered .debug_info references to .debug_ranges
microblaze-elf  +FAIL: binutils-all/pr26548
microblaze-elf  +FAIL: readelf -Wwi pr26548e (reason: unexpected output)
...
2023-10-07 15:33:10 -07:00
GDB Administrator
c09200601f Automatic date update in version.in 2023-10-07 00:00:25 +00:00
Neal Frager
6bbf249557 opcodes: microblaze: Add new bit-field instructions
This patches adds new bsefi and bsifi instructions.
BSEFI- The instruction shall extract a bit field from a
register and place it right-adjusted in the destination register.
The other bits in the destination register shall be set to zero.
BSIFI- The instruction shall insert a right-adjusted bit field
from a register at another position in the destination register.
The rest of the bits in the destination register shall be unchanged.

Further documentation of these instructions can be found here:
https://docs.xilinx.com/v/u/en-US/ug984-vivado-microblaze-ref

This patch has been tested for years of AMD Xilinx Yocto
releases as part of the following patch set:

https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils

Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
Signed-off-by: Ibai Erkiaga <ibai.erkiaga-elorza@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
2023-10-06 10:53:45 -07:00
Nick Clifton
b75b3eb082 Fix: alpha: ld segfaults in
PR 30940
  * elf64-alpha.c (elf64_alpha_check_relocs): Correct error message.
2023-10-06 10:52:02 +01:00