Commit Graph

122646 Commits

Author SHA1 Message Date
GDB Administrator
4187ba1fc7 Automatic date update in version.in 2025-06-01 00:00:16 +00:00
Tom Tromey
4aac43f399 Do not allocate macro_scope on the heap
I noticed that there's no particular reason to allocate the
macro_scope objects on the heap.  They can be passed around by value
just as easily.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-31 08:50:34 -06:00
Tom Tromey
408984ea7b Define TLS in bfd.c if not already defined
If configure decides that thread-local storage isn't available, it
does not define "TLS".  However, this is used unconditionally in a
definition.  So, define it if it isn't already defined.
2025-05-31 08:32:43 -06:00
GDB Administrator
8077496876 Automatic date update in version.in 2025-05-31 00:00:25 +00:00
Alan Modra
dc5b07c23b PR 33020 segv in _bfd_elf_strtab_offset
The PR fuzzer testcase creates a SHT_NOBITS .debug_info section, then
triggers a bug in --compress-debug-sections=zlib whereby sh_name is
set to -1 in elf_fake_sections as a flag to indicate the name is not
set yet (may change to zdebug_*), but the section never hits the debug
compression code in assign_file_positions_for_non_load_sections that
is responsible for setting sh_name.

	PR 33020
	* elf.c (_bfd_elf_init_reloc_shdr): Rename delay_st_name_p
	param to delay_sh_name_p.
	(elf_fake_sections): Rename delay_st_name_p to delay_sh_name_p.
	Don't set delay_sh_name_p for no contents debug sections.
2025-05-31 08:17:40 +09:30
Alan Modra
47d7ab7057 Revert "Replace assertions with error return values, thus ensuring an illegal memory access does not occur."
This reverts commit 429fb15134.
2025-05-31 08:16:41 +09:30
Andrew Pinski
b0a2d9e968 gprofng: Use __x86_64__ instead of __x86_64
With some compilers, only __x86_64__ is defined so use that
instead of __x86_64.

gprofng/ChangeLog
2025-05-30  Andrew Pinski  <quic_apinski@quicinc.com>
	* common/core_pcbe.c: s/__x86_64/__x86_64__/.
	* common/cpu_frequency.h: Likewise.
	* common/cpuid.c: Likewise.
	* common/gp-defs.h: Likewise.
	* common/hwctable.c: Likewise.
	* libcollector/libcol-i386-dis.c: Likewise.
	* libcollector/libcol_util.h: Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-05-30 14:57:23 -07:00
Tom Tromey
9fe87c3cc8 Remove some Rust expression helpers
When I did the big expression conversion, I left some helper functions
lying around, primarily because the conversion was already quite large
and I didn't want to add on.

This patch removes a couple such helpers, turning them into methods on
the appropriate operation objects.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-05-30 14:21:06 -06:00
Simon Marchi
d85862106f gdb: fix DW_AT_compile_unit -> DW_TAG_compile_unit in comment
While (mistakenly) grepping for DW_AT_compile_unit, I found this typo.

Change-Id: I04d97d7b1b27eacfca9da3853711b6092d330575
2025-05-30 16:19:47 -04:00
Nick Clifton
61701c57f3 Prevent illegal memory access when generating map file entries for ifuncs removed by garbage collection 2025-05-30 15:31:14 +01:00
Tom Tromey
d61186d8f8 Require Python 3.4
I believe we previously agreed that the minimum supported Python
version should be 3.4.  This patch makes this change, harmonizing the
documentation (which was inconsistent about the minimum version) and
the code.

New in v2: rebased, and removed a pre-3.4 workaround from __init__.py.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-by: Kevin Buettner <kevinb@redhat.com>
Acked-By: Tom de Vries <tdevries@suse.de>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31870
2025-05-30 07:09:53 -06:00
Nick Clifton
429fb15134 Replace assertions with error return values, thus ensuring an illegal memory access does not occur.
PR 33020
2025-05-30 13:00:59 +01:00
Nick Clifton
777ca81cd8 Updated Malay translation for the bfd/ sub-directory 2025-05-30 10:04:49 +01:00
Alan Modra
bcbba25dfc elf symbol size
This changes elf_obj_sy.size from being malloc'd to being on the notes
obstack.  That means no code needs to free these expressions, which in
turn means that the size expression can be shared when cloning
symbols.  Nothing modifies the size expressions except when resolving.
In all cases I could see, if the size changes the entire expression is
replaced.

The patch also extracts code from elf_copy_symbol_attributes into a
separate function for use by riscv and aarch64.

	* config/obj-elf.c (elf_obj_symbol_clone_hook): Delete.
	(elf_copy_symbol_size): New function, extracted and modified from..
	(elf_copy_symbol_attributes): ..here.
	(obj_elf_size): Don't free size and use notes_alloc.
	(elf_frob_symbol): Don't free size.
	(elf_format_ops): Zero symbol_clone_hook.
	* config/obj-elf.h (elf_obj_symbol_clone_hook): Delete.
	(obj_symbol_clone_hook): Don't define.
	(elf_copy_symbol_size): Declare.
	* config/tc-aarch64.c (aarch64_elf_copy_symbol_attributes): Delete.
	* config/tc-aarch64.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Define as
	elf_copy_symbol_size.
	* config/tc-alpha.c (s_alpha_end): notes_alloc symbol size exp.
	* config/tc-ia64.c (dot_endp): Likewise.
	* config/tc-kvx.c (kvx_endp): Likewise.
	* config/tc-mips.c (s_mips_end): Likewise.
	* config/tc-riscv.c (riscv_elf_copy_symbol_attributes): Delete.
	* config/tc-riscv.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Define as
	elf_copy_symbol_size.
2025-05-30 10:16:19 +09:30
Alan Modra
da79d62c37 gas symbol_remove
If a symbol is at the start of the symbol chain then symbol_rootP
points at the symbol and symbol->x->previous is NULL.  Testing either
condition is sufficient, there is no need to test both.  Similarly for
the symbol at the end of the symbol chain.

I'm testing the previous/next pointer because it's most likely that
the symbol is not at the start/finish of the chain and thus we need to
use that pointer.

	* symbols.c (symbol_remove): Tidy list handling.
	(symbol_append, symbol_clone, symbol_insert): Likewise.
2025-05-30 10:16:19 +09:30
Alan Modra
5e5f37ed00 Reduce rs_align_code memory for small alignments
On x86, MAX_MEM_FOR_RS_ALIGN_CODE is 35, when the most common
alignment is 2**3 or 2**4, where the max memory required for the
alignment nops is 7 and 15 bytes respectively.  So there is some
memory wasted since commit 83d94ae428.  It's not a large amount,
especially considering that frag overhead on x86_46 is 144 bytes,
but even so I'd rather not be blamed for increasing gas memory usage.

So to reduce the memory we'd like to take the alignment into
consideration when initialising an rs_align_code frag.  The only
difficulty here is start_bundle making an rs_align_code frag with an
alignment of zero initially, then later increasing the alignment.  We
change that to use the bundle alignment when setting up the frag.  I
think that is sufficient as bundle_align_p2 can't change in the middle
of a start_bundle/finish_bundle sequence.

I haven't modified any targets other than x86 in this patch.  Most
won't benefit much due to using fairly small MAX_MEM_FOR_RS_ALIGN_CODE.

	* read.c (start_bundle): Create rs_align_code frag with
	bundle_align_p2 alignment, then set to zero alignment.
	(finish_bundle): Adjust comment.
	* frags.c (MAX_MEM_FOR_RS_ALIGN_CODE): Pass p2align and max
	to macro.
	* config/tc-i386.h (HANDLE_ALIGN): Assert that max_bytes is
	sufficient for nop padding.
	(max_mem_for_rs_align_code): New inline function.
	(MAX_MEM_FOR_RS_ALIGN_CODE): Use it.
	* config/tc-aarch64.h: Adjust MAX_MEM_FOR_RS_ALIGN_CODE.
	* config/tc-alpha.h: Likewise.
	* config/tc-arc.h: Likewise.
	* config/tc-arm.h: Likewise.
	* config/tc-epiphany.h: Likewise.
	* config/tc-frv.h: Likewise.
	* config/tc-ia64.h: Likewise.
	* config/tc-kvx.h: Likewise.
	* config/tc-loongarch.h: Likewise.
	* config/tc-m32r.h: Likewise.
	* config/tc-metag.h: Likewise.
	* config/tc-mips.h: Likewise.
	* config/tc-nds32.h: Likewise.
	* config/tc-ppc.h: Likewise.
	* config/tc-riscv.h: Likewise.
	* config/tc-rl78.h: Likewise.
	* config/tc-rx.h: Likewise.
	* config/tc-score.h: Likewise.
	* config/tc-sh.h: Likewise.
	* config/tc-sparc.h: Likewise.
	* config/tc-spu.h: Likewise.
	* config/tc-tilegx.h: Likewise.
	* config/tc-tilepro.h: Likewise.
	* config/tc-visium.h: Likewise.
	* config/tc-xtensa.h: Likewise.
2025-05-30 10:16:19 +09:30
GDB Administrator
d4de8fe856 Automatic date update in version.in 2025-05-30 00:00:16 +00:00
Guinevere Larsen
2490dbf4e4 gdb: update corner case when canonicalizing riscv syscall names
The script syscalls/riscv-canonicalize-syscall-gen.py has been recently
introduced to help support record-full in riscv systems.  However, it
was developed before commit 432eca4113,
which made the GDB enum more consistent, which forced the python script
to have a corner case for the "gdb_old_mmap" case.

Since the aforementioned commit has already been merged, we need to
update the special case for the mmap syscall. A special case is still
needed because the script would expect that the glibc sources call the
syscall "old_mmap", or that gdb call it "gdb_sys_mmap", neither of which
happens unfortunately.

This commit doesn't change the .c file because it was already fixed by a
different commit, 65ab41b7d5, which was
pushed as obvious to fix the build issues.

Approved-By: Tom Tromey <tom@tromey.com>
2025-05-29 14:40:11 -03:00
Jorenar
aed5eee5a3 gdb/dap: fix completion request for empty strings
When DAP completion requests receives empty string to complete,
the script crashes due trying to access element -1 from list
being a result of `text.splitlines()` (which for `text == ""`
evaluates into empty list).

This patch adds simple check if `text` is populated, and when it
is not, skips transformations and assigns correct result directly.

Approved-By: Tom Tromey <tom@tromey.com>
2025-05-29 11:04:18 -06:00
Simon Marchi
bc5237a263 gdb, gdbsupport: fix all ;; instances
I forgot to fix a `;;` typo when pushing a previous patch.  Fix it, and
fix all the other instances I could find in the code base.

Change-Id: I298f9ffb1a5157925076ef67b439579b1aeeaa2b
2025-05-29 11:13:08 -04:00
Pedro Alves
42339bc4e0 Fix build when RUSAGE_THREAD is not available & add warning
Building current GDB on Cygwin, fails like so:

 /home/pedro/gdb/src/gdbsupport/run-time-clock.cc: In function ‘void get_run_time(user_cpu_time_clock::time_point&, system_cpu_time_clock::time_point&, run_time_scope ’:
 /home/pedro/gdb/src/gdbsupport/run-time-clock.cc:52:13: error: ‘RUSAGE_THREAD’ was not declared in this scope; did you mean ‘SIGEV_THREAD’?
    52 |       who = RUSAGE_THREAD;
       |             ^~~~~~~~~~~~~
       |             SIGEV_THREAD

Cygwin does not implement RUSAGE_THREAD.  Googling around, I see
Cygwin is not alone, other platforms don't support it either.  For
example, here is someone suggesting an alternative for darwin/macos:
https://stackoverflow.com/questions/5652463/equivalent-to-rusage-thread-darwin

Fix this by falling back to process scope if thread scope can't be
supported.  I chose this instead of returning zero usage or some other
constant, because if gdb is built without threading support, then
process-scope run time usage is the right info to return.

But instead of falling back silently, print a warning (just once),
like so:

 (gdb) maint set per-command time on
 ⚠️ warning: per-thread run time information not available on this platform

... so that developers on other platforms at least have a hint
upfront.

This new warning also shows on platforms that don't have getrusage in
the first place, but does not show if the build doesn't support
threading at all.

New tests are added to gdb.base/maint.exp, to expect the warning, and
also to ensure other "mt per-command" sub commands don't trigger the
new warning.

Change-Id: Ie01b916b62f87006f855e31594a5ac7cf09e4c02
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Tom Tromey <tom@tromey.com>
2025-05-29 11:08:43 -04:00
Simon Marchi
c29af2b055 gdb/solib: make solib_ops::solib_create_inferior_hook optional
The solib-target implementation of solib_create_inferior_hook is empty.
Make that method / function pointer optional.

Change-Id: Ie27b8d2c4fc6df74069ac8f88fbe69cf88a6662d
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:49:37 -04:00
Simon Marchi
d5ef1fc282 gdb/solib: make solib_ops::in_dynsym_resolve_code optional
Two solib ops implementations have dummy implementations for the
in_dynsym_resolve_code callback.  Make it optional, to avoid this.

Change-Id: I786776fb82ce1b96335a97713fbfe8074c84c00c
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:49:37 -04:00
Simon Marchi
134767de03 gdb/solib: make implementation of solib_ops::open_symbol_file_object optional
The only solib implementation that implements open_symbol_file_object is
SVR4.  All others just return 0.  Make it optional, to avoid having
these empty functions.

Change-Id: I835197a73323d39231d071f9a9eaac2553f10726
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:49:37 -04:00
Simon Marchi
d309f4d8a7 gdb/solib: boolify in_dynsym_resolve_code functions
Change-Id: I66f5986e1a2452e3817f326d908b2e49f99e2fc6
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:49:37 -04:00
Simon Marchi
2c3e1c3f74 gdb/solib: move solist.h content to solib.h
I don't think that the file solist.h is useful.  It would make sense to
have `struct solib` in solib.h.  And then, all that would remain is
`struct solib_ops` and some solib-related function declarations.  So,
move it all to solib.h.

Change-Id: I20ecf19787c378066f2c7a6a8a737c1db7c55d9a
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:47:48 -04:00
Simon Marchi
87c1d01cad gdb/progspace: rename progspace::so_list, make private
Rename the field to m_solib_list, make it private.  Update users to go
through the accessor.

Change-Id: Id720c3a0b1781f4acf31e0dc626f1bd23ed8b39a
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:44:58 -04:00
Simon Marchi
cba1c145af gdb: fix stale references to so_list
Adjust some comments and function names that refer to the ancient
so_list type.

Update some other stale comments in solib-svr4.c at the same time.

Change-Id: Ia42efa6554d0cc6abb4183b6bffc96c6358c5735
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:44:58 -04:00
Simon Marchi
6896e62513 gdb/solib: remove so_ prefix from so_name and so_original_name
The `so_` prefix is unnecessary here, it's already clear by the fact
that they are field of the solib type (and previously so_list).

Change-Id: I2c6773afc121d7631901e602913ea8a068840d0b
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-29 10:44:58 -04:00
GDB Administrator
dbd830f14f Automatic date update in version.in 2025-05-29 00:00:17 +00:00
Tom de Vries
11cb20e27b [gdb/symtab] Note errors in process_skeletonless_type_units
With a hello world a.out, and using the compiler flags from target board
dwarf5-fission-debug-types:
...
$ gcc -gdwarf-5 -fdebug-types-section -gsplit-dwarf ~/data/hello.c
...
I run into:
...
$ gdb -q -batch a.out
terminate called after throwing an instance of 'gdb_exception_error'
...

What happens is that an error is thrown due to invalid dwarf, but the error is
not caught, causing gdb to terminate.

In a way, this is a duplicate of PR32861, in the sense that we no longer run
into this after:
- applying the proposed patch (work around compiler bug), or
- using gcc 9 or newer (compiler bug fixed).

But in this case, the failure mode is worse than in PR32861.

Fix this by catching the error in
cooked_index_worker_debug_info::process_skeletonless_type_units.

With the patch, we get instead:
...
$ gdb -q -batch a.out
Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \
  .debug_str.dwo section in CU at offset 0x0 [in module a.out]
...

While we're at it, absorb the common use of
cooked_index_worker_result::note_error:
...
  try
    {
      ...
    }
  catch (gdb_exception &exc)
    {
      (...).note_error (std::move (exc));
    }
...
into the method and rename it to catch_error, resulting in more compact code
for the fix:
...
  (...).catch_error ([&] ()
    {
      ...
    });
...

While we're at it, also use it in
cooked_index_worker_debug_info::process_units which looks like it needs the
same fix.

Tested on x86_64-linux.

PR symtab/32979
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32979
2025-05-28 22:17:19 +02:00
Alan Modra
f2172071e6 elfedit: segv with --enable-x86-feature
PR 33024
	PR 33025
	* elfedit.c (update_gnu_property): Sanity check program headers.
2025-05-28 22:34:50 +09:30
Alan Modra
ee623fdffd Further rs_code_align support refinement
Don't write the repeating nop pattern if it won't be used.
2025-05-28 21:10:48 +09:30
Alexandra Hájková
1c96b468be Call restore_original_signal_state after GDB forks.
When I run GDB under Valgrind, GDB seems to segfault
displaying:

Fatal signal: Segmentation fault
----- Backtrace -----
0x2803f7 ???
0x3c9696 ???
0x3c9899 ???
0x55f8fcf ???
0x486c000 ???
---------------------
A fatal error internal to GDB has been detected, further
debugging is not possible.  GDB will now terminate.

This is a bug, please report it.  For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

warning: linux_ptrace_test_ret_to_nx: PC 0x5821c09d is neither near return address 0x486c000 nor is the return instruction 0x4f8f4a!

but then, acts like nothing happened and excutes normally. This is
because it's the child from linux_ptrace_test_ret_to_nx that
segfaults and parent GDB carries on normally. Restore the original
signal states to not to print confusing backtrace. After restoring,
only such warning is displayed:

warning: linux_ptrace_test_ret_to_nx: WSTOPSIG 19 is neither SIGTRAP nor SIGSEGV!
2025-05-28 11:14:27 +02:00
Alan Modra
f601ffb521 PR 33029 segv in dwarf2_finish with --gdwarf-5
Specifying --gdwarf-5 with a source lacking a ".file 0" directive
results in this segfault.

	* dwarf2dbg.c (out_debug_str): Use files[1] if files[0] is
	empty regardless of dwarf level.
2025-05-28 18:27:23 +09:30
Alan Modra
5e3176dd79 PR 33023 memory leak in objdump when specifying --endian
* objdump.c (disassemble_data): Free modified xvec and replace
	original.
2025-05-28 15:55:27 +09:30
Alan Modra
5d4465be2b PR 33021, buffer overflow in write_dwarf_eh_frame_hdr
* elf-eh-frame.c (write_dwarf_eh_frame_hdr): Use size of
	contents, not section size, in bfd_set_section_contents call.
2025-05-28 15:26:01 +09:30
Alan Modra
04395ea004 PR 33018 segv in elf_x86_64_scan_relocs
* elf64-x86-64.c (elf_x86_64_scan_relocs): Error on NULL howto.
	Use bfd_reloc_offset_in_range.
2025-05-28 15:23:46 +09:30
GDB Administrator
882be0d57b Automatic date update in version.in 2025-05-28 00:00:19 +00:00
Simon Marchi
006fb76117 gdb: make objfile_has_full_symbols and objfile_has_symbols methods of objfile
They seem like good candidates to become methods, just like
objfile::has_partial_symbols.

Change-Id: Ic6df83012629c1137708b8ceb327f9868d8abcb5
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-05-27 09:46:28 -04:00
Thiago Jung Bauermann
95f0978bd0 gdb/testsuite: Clarify -lbl option in gdb_test_multiple
I was a bit confused about the -lbl option in gdb_test_multiple, and needed
to read its implementation to determine that it would be useful for my
needs.  Explicitly mention what the option does and why it's useful to
hopefully help other developers.

Reviewed-By: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-05-26 22:41:37 -03:00
Thiago Jung Bauermann
c833b2b5e8 gdb/testsuite: Fix flakiness in gdb.base/default.exp
The Linaro CI runs the GDB testsuite using the read1 tool, which
significantly increases the time it takes DejaGNU to read inferior output.
On top of that sometimes the test machine has higher than normal load,
which causes tests to run even slower.

Because gdb.base/default.exp tests some verbose commands such as "info
set", it sometimes times out while waiting for the complete command
output when running in the Linaro CI environment.

Fix this problem by consuming each line of output from the most verbose
commands with gdb_test_multiple's -lbl (line-by-line) option — which
causes DejaGNU to reset the timeout after each match — and also by
breaking up regular expressions that try to match more than 2000
characters (the default Expect buffer size) in one go into multiple
matches.

Some tests use the same regular expression, so I created a procedure for
them.  This is the case for "i" / "info", "info set" / "show", and "set
print" tests.

The tests for "show print" don't actually test their output, so this
patch improves them by checking some lines of the output.

Reviewed-By: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-05-26 22:41:37 -03:00
GDB Administrator
d13aaae402 Automatic date update in version.in 2025-05-27 00:00:21 +00:00
Alan Modra
998d4443ea ALPHA_R_OP_STORE
In commit db4ab410de I rewrote OP_STORE handling to support writing
near the end of a section.  The rewrite had some bugs, fixed in commit
3e02c4891d.  However I wasn't entirely happy with the code writing
the bitfield:
- it doesn't support 64-bit fields with a bit offset,
- the code is duplicated and inelegant,
- the stack ought to be popped whenever seeing one of these relocs,
  even if the reloc can't be applied.
This patch fixes all of the above.

In addition, it is clear from the OP_STORE description in the ABI that
a 64-bit field is encoded as 0 in r_size, so I've decoded that in
alpha_ecoff_swap_reloc_in.  The aborts there are not appropriate as
they can be triggered by user input (fuzzed object files).  Also,
stack underflow wasn't checked in alpha_relocate_section.

	* coff-alpha.c (alpha_ecoff_swap_reloc_in): Replace aborts
	with asserts.  Decode ALPHA_R_OP_STORE r_size of zero.
	(write_bit_field): New function.
	(alpha_ecoff_get_relocated_section_contents): Use it.
	(alpha_relocate_section): Here too.  Catch stack underflow.
2025-05-27 09:02:12 +09:30
Jens Remus
2adbf167ca libsframe: handle SFrame FRE start/end IP offsets as unsigned
The SFrame FRE start address (fre_start_addr) is defined as unsigned
32-bit integer, as it is an offset from SFrame FDE function start
address (sfde_func_start_address) and functions only grow upwards
(towards higher addresses).

The SFrame FRE start IP offset is a synonym to the SFrame FRE start
address.  The SFrame FRE end IP offset is either the value of the
subsequent FDE start address minus one, if that exists, or the FDE
function size minus one otherwise.  Both should therefore be handled
as unsigned 32-bit integer.

In libsframe the "lookup PC" (pc) and SFrame FDE function start address
(sfde_func_start_address) are both signed integers, as they are actually
offsets from the SFrame section.  The unsigned FDE start/end IP offsets
may therefore only be safely compared against the offset of the lookup
PC from FDE function start address if the FDE function start address is
lower or equal to the lookup PC, as this guarantees the offset to be
always positive:

Given:

  lookup_pc = pc - sframe_addr

  sfde_func_start_address = func_start_addr - sframe_addr

If the FDE function start address is lower or equal than the lookup PC,
which both are signed offsets from SFrame section, then the function
start address is also lower or equal to the PC, which are both unsigned:

  sfde_func_start_address <= lookup_pc
  func_start_addr - sframe_addr <= pc - sframe_addr
  func_start_addr <= pc

With that the offset of the lookup PC from FDE function start address
(lookup_pc - sfde_func_start_address) must always be positive, if
FDE function start address is lower or equal to the lookup PC:

  lookup_pc - sfde_func_start_address
  = pc - sframe_addr - (func_start_addr - sframe_addr)
  = pc - func_start_addr

libsframe/
	* sframe.c (sframe_find_fre): Define and handle start_ip_offset
	and end_ip_offset as unsigned (same as FRE fre_start_addr).
	(sframe_fre_check_range_p): Likewise.  Define PC offset (from
	function start address) as unsigned.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-05-26 11:02:47 -07:00
Jens Remus
ada5c6fa08 libsframe: stop search for SFrame FRE if its start IP is greater than PC
The SFrame FREs for an SFrame FDE are sorted on their start address.
Therefore the linear search for a matching SFrame FRE can be stopped,
if its start address is greater than the searched for PC.

libsframe/
	* sframe.c (sframe_find_fre): Stop search if FRE's start IP is
	greater than PC.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-05-26 11:02:29 -07:00
Jens Remus
9d2a24349e libsframe: correct binary search for SFrame FDE
sframe_get_funcdesc_with_addr_internal erroneously returns the last FDE,
if its function start address is lower than the searched for address.

Simplify the binary search for a SFrame FDE for a given address.  Only
return an FDE, if the searched for address is within the bounds of the
FDE function start address and function size.

libsframe/
	* sframe.c (sframe_get_funcdesc_with_addr_internal): Correct
	binary search for SFrame FDE.

libsframe/testsuite/
	* libsframe.find/plt-findfre-1.c: Add test for out of range
	PLT6.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-05-26 11:01:14 -07:00
Indu Bhagat
f0d72d3508 libsframe: testsuite: improve findfunc-1 testcase
The testcase had usages of some magic numbers, making it difficult to
keep up when format changes come along.

libsframe/testsuite/
	* libsframe.find/findfunc-1.c: Restructure a bit.  Run test for two
	ways of placement of .sframe and .text.
2025-05-26 10:54:56 -07:00
Indu Bhagat
0d15aea98b libsframe: testsuite: improve findfre-1 testcase
The testcase had usages of some magic numbers, making it difficult to
keep up when format changes come along.

libsframe/testsuite/
	* libsframe.find/findfre-1.c: Restructure a bit.  Run test for two
	ways of placement of .sframe and .text.
2025-05-26 10:54:35 -07:00
Indu Bhagat
4e94f00756 libsframe: fix issue finding FRE in PCMASK type SFrame FDEs
SFrame FDEs of type SFRAME_FDE_TYPE_PCMASK are used for repetitive code
patterns, e.g., pltN entries.  For SFrame FDEs of type
SFRAME_FDE_TYPE_PCMASK, sframe_fre_check_range_p erroneously tested the
given PC instead of the masked PC offset from function start address.
Therefore it only worked correctly by chance, e.g., if the function start
address was aligned on the repetition block size.

For regular SFrame FDEs the PC offset from function start address must
be within a SFrame FRE's start IP offset and end IP offset.  For SFrame
FDEs of type SFRAME_FDE_TYPE_PCMASK, the masked PC offset must be within
that range.

SFrame FRE start/end IP offsets are relative to the SFrame FDE function
start address. For regular SFrame FDEs, the PC offset from function
start address must be within a SFrame FRE's start IP offset and end IP
offset.  For SFRAME_FDE_TYPE_PCMASK type FDEs, the masked PC offset must
be within that range.

Exercise the testcase for a variety of placements; without the fix some
of these tests will fail.  Also, make the testcase itself easier to
follow by adding appropriate vars where applicable.

libsframe/
	* sframe.c (sframe_fre_check_range_p): Fix logic for
	SFRAME_FDE_TYPE_PCMASK type FDE.
libsframe/testsuite/
	* libsframe.find/plt-findfre-1.c: Adjust the test for a variety
	of placements of .sframe and .plt.

Co-Authored-by: Jens Remus <jremus@linux.ibm.com>
2025-05-26 10:54:06 -07:00