Commit Graph

59 Commits

Author SHA1 Message Date
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
Adds two new external authors to etc/update-copyright.py to cover
bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then
updates copyright messages as follows:

1) Update cgen/utils.scm emitted copyrights.
2) Run "etc/update-copyright.py --this-year" with an extra external
   author I haven't committed, 'Kalray SA.', to cover gas testsuite
   files (which should have their copyright message removed).
3) Build with --enable-maintainer-mode --enable-cgen-maint=yes.
4) Check out */po/*.pot which we don't update frequently.
2024-01-04 22:58:12 +10:30
Alan Modra
6a6859cbff regen config
This regenerates config files changed by the previous 44 commits.
Note that subject lines in these commits mostly match the gcc git
originating commit.
2023-08-12 10:27:57 +09:30
Indu Bhagat
a5cddf7b64 doc: sframe: update specification for SFRAME_VERSION_2
Add details for the changes made from Version 1 to Version 2 of the format.

Also add details about alignment in the SFrame format.  A portion of the
SFrame stack trace format has an unaligned on-disk representation.  Add
description at relevant points in the specificatin to clarify the
alignment related details.
2023-06-29 16:32:26 -07:00
Indu Bhagat
ce9a87252c sframe: bfd: gas: ld: format bump to SFrame version 2
SFrame version 2 encodes the size of repetitive insn block explicitly
in the format.  Add information in the SFrame FDE to convey the size
of the block of repeating instructions.  This information is used only
for SFrame FDEs of type SFRAME_FDE_TYPE_PCMASK.

Introduce two extra bytes for padding: this ensures that the memory
accesses to the members of the SFrame Frame Descriptor Entry (FDE) are
naturally aligned.

gas generates SFrame section with version SFRAME_VERSION_2 by default.

libsframe provides two new APIs to:
  - get an SFrame FDE data from the decoder context, and
  - add an SFrame FDE to the encoder context.
The additional argument (for rep_block_size) is useful for SFrame FDEs
where FDE type is SFRAME_FDE_TYPE_PCMASK.

The linker will generate the output SFrame sections in the
SFRAME_VERSION_2 format.  If the input sections offered to the linker
are not all in the SFRAME_VERSION_2 format, the linker issues an error
to the user.

objdump/readelf will show the following message to the user if .sframe
section in SFRAME_VERSION_1 format is seen:

 "No further information can be displayed.  SFrame version not
 supported."

In other words, like the rest of the binutils, only the current SFrame
format version, i.e., SFRAME_VERSION_2 is supported by the textual dump
facilities.

bfd/
	* elf-sframe.c (_bfd_elf_merge_section_sframe): Generate an
	output SFrame section with version SFRAME_VERSION_2.  Also,
	error out if the SFrame sections do not all have
	SFRAME_VERSION_2.
	* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Generate SFrame
	section for plt entries with version SFRAME_VERSION_2.
gas/
	* gen-sframe.c (sframe_set_version): Update to SFRAME_VERSION_2.
	(output_sframe): Likewise.
gas/testsuite/
	* gas/cfi-sframe/cfi-sframe-aarch64-1.d: Use SFRAME_VERSION_2.
	* gas/cfi-sframe/cfi-sframe-aarch64-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-aarch64-pac-ab-key-1.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-1.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-3.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-4.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-5.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-6.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-7.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-8.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-1.d: Likewise.
	* gas/cfi-sframe/common-empty-1.d: Likewise.
	* gas/cfi-sframe/common-empty-2.d: Likewise.
	* gas/cfi-sframe/common-empty-3.d: Likewise.
ld/testsuite/
	* ld-aarch64/sframe-simple-1.d: Adjust for SFRAME_VERSION_2.
	* ld-x86-64/sframe-plt-1.d: Likewise.
	* ld-x86-64/sframe-simple-1.d: Likewise.
libsframe/
	* libsframe.ver: Add the new APIs.
	* sframe.c (sframe_decoder_get_funcdesc_v2): New definition.
	(sframe_encoder_add_funcdesc_v2): Likewise.
	(sframe_header_sanity_check_p): Include SFRAME_VERSION_2.
	(sframe_fre_check_range_p): Get rep_block_size info from SFrame
	FDE.
	* sframe-dump.c (dump_sframe_header): Add support for
	SFRAME_VERSION_2.
	(dump_sframe): Inform user if SFrame section in SFRAME_VERSION_1
	format is seen.
libsframe/testsuite/
	* libsframe.decode/DATA-BE: Regenerated data file.
	* libsframe.decode/DATA1: Likewise.
	* libsframe.decode/DATA2: Likewise.
	* libsframe.find/plt-findfre-1.c: Use new API in the testcase.
include/
	* sframe.h: Add member to encode size of the code block of
	repeating instructions.  Add 2 bytes of padding.
	* sframe-api.h (sframe_decoder_get_funcdesc_v2): New
	declaration.
	(sframe_encoder_add_funcdesc_v2): Likewise.
2023-06-29 16:31:58 -07:00
Indu Bhagat
9f71b60bd4 libsframe: add new APIs to get SFrame version
While the SFrame preamble is guaranteed to not change between versions,
providing these access APIs from the SFrame decoder and encoder APIs is
for convenience only.  The linker may want to use these APIs as the
format evolves.

include/
	* sframe-api.h (sframe_decoder_get_version): New declaration.
	(sframe_encoder_get_version): Likewise.

libsframe/
	* libsframe/libsframe.ver: Add new APIs.
	* libsframe/sframe.c (sframe_decoder_get_version): New
	definition.
	(sframe_encoder_get_version): Likewise.
2023-06-29 16:28:56 -07:00
Indu Bhagat
3169b734cf libsframe: fix sframe_find_fre for pltN entries
For a toy application on x86_64, for example, following is the SFrame
stack trace information for the 3 pltN entries of 16 bytes each:

   func idx [1]: pc = 0x401030, size = 48 bytes
   STARTPC[m]      CFA       FP        RA
   0000000000000000  sp+8      u         u
   000000000000000b  sp+16     u         u

The data in first column is the start_ip_offset.  Also note that the FDE
is of type SFRAME_FDE_TYPE_PCMASK (denoted by the [m] on LHS).

Where each pltN (note: excluding plt0 entry) entry looks like:

  401030: jmp    *0x2fca(%rip)
  401036: push   $0x0
  40103b: jmp    401020<_init+0x20>

  401040: jmp    *0x2fc2(%rip)
  401046: push   $0x1
  40104b: jmp    401020<_init+0x20>

  401050: jmp    *0x2fba(%rip)
  401056: push   $0x2
  40105b: jmp    401020<_init+0x20>

Now, to find SFrame stack trace information from an FDE of type
SFRAME_FDE_TYPE_PCMASK, sframe_find_fre () was doing an operation
like,
  (start_ip_offset & 0xf) >= (pc & 0xf)

This works for pltN entry of size, say, less than 16 bytes.  But if the
pltN entries or similar code stubs (for which SFrame FDE of type
SFRAME_FDE_TYPE_PCMASK may be used), evolve to be of size > 16 bytes,
this will cease to work.

To match the range covered by the SFrame FRE, one should instead perform
a modulo operation.  The constant for the modulo operation must be the
size of the pltN entry.  Further, this constant should ideally be
encoded in the format, as it may be different for each ABI.

In SFrame Version 2 of the format, we will move towards encoding it
explicitly in the SFrame FDE.  For now, fix up the logic to at least
move towards modulo operation.

libsframe/
	* sframe.c (sframe_fre_check_range_p): New definition.
	(sframe_find_fre): Refactor a bit and use the new definition
	above.
include/
	* sframe.h (SFRAME_FDE_TYPE_PCMASK): Update comment.
libsframe/doc/
	* sframe-spec.texi: Fix the text for SFRAME_FDE_TYPE_PCMASK FDE
	type.
2023-06-29 11:03:32 -07:00
Indu Bhagat
df6f1afb6d libsframe: bfd: use uint32_t for return type of get_num_fidx APIs
Keep the data types usage in libsframe look consistent.

bfd/
	* elf-sframe.c (_bfd_elf_merge_section_sframe): Use uint32_t
	type alias.
	* libsframe/sframe.c (sframe_decoder_get_funcdesc_at_index):
	Likewise.
	(sframe_decoder_get_num_fidx): Likewise.
	(sframe_encoder_get_num_fidx): Likewise.
include/
	* sframe-api.h (sframe_decoder_get_num_fidx): Likewise.
	(sframe_encoder_get_num_fidx): Likewise.
2023-06-27 12:01:56 -07:00
Indu Bhagat
3412dcec61 libsframe: use appropriate data types for args of sframe_encode
include/
	* sframe-api.h (sframe_encode): Use of uint8_t is more
	appropriate.
libsframe/
	* sframe.c (sframe_encode): Likewise.
2023-06-27 12:01:56 -07:00
Indu Bhagat
a9f1da26da libsframe: use uint8_t for return type of sframe_fre_get_base_reg_id
Use a more appropriate data type.

include/
	* sframe-api.h (sframe_fre_get_base_reg_id): Use uint8_t as
	return type.
libsframe/
	* sframe-dump.c (dump_sframe_func_with_fres): Use uint8_t type
	for base reg id.
	* sframe.c (sframe_fre_get_base_reg_id): Use uin8_t as return
	type.
2023-06-27 12:01:56 -07:00
Indu Bhagat
de4879feca libsframe: use uint8_t instead of unsigned char for abi_arch
Use uint8_t consistently for identifying ABI/arch in SFrame format.

bfd/
	* elf-sframe.c (_bfd_elf_merge_section_sframe):
libsframe/
	* sframe-dump.c (is_sframe_abi_arch_aarch64): Use uint8_t for
	local variable.
	* sframe.c (sframe_decoder_get_abi_arch): Update return type to
	uint8_t.
	(sframe_encoder_get_abi_arch): Likewise.
include/
	* sframe-api.h (sframe_decoder_get_abi_arch): Likewise.
	(sframe_encoder_get_abi_arch): Likewise.
2023-06-27 12:01:56 -07:00
Indu Bhagat
49e4485cba libsframe: bfd: use uint32_t for return type of sframe_calc_fre_type
Use uint32_t type alias consistently for all APIs in libsframe.

bfd/
	* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Adjust for the
	changed return type.
libsframe/
	* sframe.c (sframe_calc_fre_type): Use uint32_t for return type.
include/
	* sframe-api.h (sframe_calc_fre_type): Likewise.
2023-06-27 12:01:56 -07:00
Indu Bhagat
100d405dae libsframe: use uint32_t for fre_type and fde_type function args
The API sframe_fde_create_func_info is provided by libsframe.  Current
users are the bfd linker.  Adjust the argument type for the variables
carrying the SFrame FRE type and SFrame FDE type to consistenly use
uint32_t type alias.

include/
	* sframe-api.h (sframe_fde_create_func_info): Use uint32_t
	instead of unsigned int.
libsframe/
	* sframe.c (sframe_get_fre_type): Likewise.
	(sframe_get_fde_type): Likewise.
	(flip_fre_start_address): Likewise.
	(sframe_fre_start_addr_size): Likewise.
	(sframe_fre_entry_size): Likewise.
	(flip_fre): Likewise.
	(flip_sframe): Likewise.
	(sframe_fde_create_func_info): Likewise.
	(sframe_calc_fre_type): Likewise.
	(sframe_decode_fre_start_address): Likewise.
	(sframe_decode_fre): Likewise.
	(sframe_find_fre): Likewise.
	(sframe_decoder_get_fre): Likewise.
	(sframe_encoder_add_fre): Likewise.
	(sframe_encoder_write_fre_start_addr): Likewise.
	(sframe_encoder_write_fre): Likewise.
	(sframe_encoder_write_sframe): Likewise.
2023-06-27 12:01:56 -07:00
Indu Bhagat
526960c912 libsframe: update the semantics of sframe_fre_get_fp_offset
Until now, sframe_fre_get_fp_offset () would return
SFRAME_ERR_FREOFFSET_NOPRESENT if the ABI uses fixed FP offset.  A stack
tracer, then, would call an explicit sframe_decoder_get_fixed_fp_offset ()
to get the FP offset.

On second look, it appears to make sense to hide these details of
whether the FP offset is fixed or not in an ABI from the consumer.  Now,
with the changed semantics, the call to sframe_fre_get_fp_offset () will
fetch the fixed FP offset if applicable, or get the FP offset from FRE
when there is no fixed FP offset.

This patch changes the behavior of sframe_fre_get_fp_offset (): it turns
an error into non-error.  This change will be included with the next
release of libsframe, where all the exposed symbols will be versioned
with version node LIBSFRAME_1.0 for the first time.

libsframe/
	* sframe.c (sframe_fre_get_fp_offset): Return the fixed offset, if
	applicable. Else return the FP offset from the FRE.
2023-06-27 12:01:56 -07:00
Indu Bhagat
36aecb4197 libsframe: update the semantics of sframe_fre_get_ra_offset
Until now, sframe_fre_get_ra_offset () would return
SFRAME_ERR_FREOFFSET_NOPRESENT if the ABI uses fixed RA offset (e.g.,
AMD64).  A stack tracer, then, will call an explicit
sframe_decoder_get_fixed_ra_offset () to get the RA offset.

On second look, it appears to make sense to hide these details of
whether the RA offset is fixed or not from the consumer.  Now, with the
changed semantics, the call to sframe_fre_get_ra_offset () will fetch
the fixed RA offset if applicable, or get the RA offset from FRE when
there is no fixed RA offset.

Adjustments need to be made to ensure the textual dump remains the same
as preivous.  Currently, e.g., if RA is not being tracked per FRE,
following is seen with objdump --sframe:

    STARTPC         CFA       FP        RA
    000000000000NNNN  sp+X      u         u

This patch changes the behavior of sframe_fre_get_ra_offset: it turns an
error into non-error.  This change will be included with the next
release of libsframe, where all exposed symbols will be versioned for
the first time.

libsframe/
	* sframe.c (sframe_fre_get_ra_offset): Return the fixed offset,
	if applicable.  Else return the RA offset from the FRE.
	* sframe-dump.c (dump_sframe_func_with_fres): Make adjustments
	to keep the textual dump same as previous.
2023-06-27 12:01:56 -07:00
Indu Bhagat
99fde044fc libsframe: add symbol versioning
Define an empty base version LIBSFRAME_0.0 and add all symbols to
version LIBSFRAME_1.0.

The previous release of libsframe (libsframe.so.0) did not have
versioned symbols.  Adding a libsframe.ver file so that future releases
of the library (and its consumers) can manage the changes better.

For Solaris ld, use -M mapfile command line option.  libsframe does not
restrict the set of exported symbols, so at this time there is no need
to fall back on the libtool's -export-symbols option for platforms where
some other linker (with a different command line option for symbol
versioning) may be used.

libsframe/
	* Makefile.am: Use symbol versioning for libsframe.
	* Makefile.in: Regenerated.
	* configure: Check for Solaris ld.
	* configure.ac: Regenerated.
	* libsframe.ver: New file.
2023-06-27 12:01:56 -07:00
Indu Bhagat
852bb8c10d libsframe: remove sframe_get_funcdesc_with_addr API
This is an incompatible ABI change in libsframe.

The interface provided by this function is not a healthy abstraction to
expose: the return type sframe_func_desc_entry, which is defined in
include/sframe.h (the SFrame binary format definition).  This ties up
the library in a undesirable way.  Most importantly, this function
should technically not be directly necessary for a stack tracer.  A
stack tracer will likely only need to do a sframe_find_fre ().

Rename the API to continue to use the functionality internally in the
library.  bfd/linker does not use this function.

Change the return type of the previous definition and make a note about
its planned deprecation.

include/
	* sframe-api.h:  Change return type of sframe_get_funcdesc_with_addr.
	Add comment for intention to deprecate.
libsframe/
	*sframe.c (sframe_get_funcdesc_with_addr): Change return type
	and set error code. This API is deprecated.
        (sframe_get_funcdesc_with_addr_internal): New definition for
	internal use.
	(sframe_find_fre): Use sframe_get_funcdesc_with_addr_internal
	instead.
2023-06-27 12:01:56 -07:00
Indu Bhagat
b91671f3f9 libsframe: add library versioning
lisbframe was first released with Bintuils 2.40.  As the library
evolves, some changes will break the ABI.  Add library versioning for
users to manage these changes.

For the next release of the library (libsframe.so.1), incompatible ABI
changes are planned. These will include:
 - Deprecation of some APIs, like sframe_get_funcdesc_with_addr (), and
 - Change in the contract of some APIs (e.g., return type, behavior).

In libtool-version, set the current to 1 to prepare for the upcoming
release.  Reset revision and age to 0.

Add libtool-version file to EXTRA_DIST.

libsframe/
	* Makefile.am: Use libtool versioning.
	* Makefile.in: Regenerated.
	* libtool-version: New file.
2023-06-27 12:01:56 -07:00
Indu Bhagat
e4d5d12940 libsframe: testsuite: add sframe_find_fre tests for pltN entries
Add a new test plt-findfre-1 to ensure lookup of SFrame stack trace
information for pltN entries is correct.

In this test, a dummy SFrame FDE of type SFRAME_FDE_TYPE_PCMASK is
created.  The size of the 'function code block' covered by the SFrame
FDE is equivalent to 5 pltN entries of 16 bytes each.

The test first looks up SFrame FREs for some addresses in the first pltN
entry, followed by lookups for some addresses in the fourth pltN entry.

libsframe/
	* Makefile.in: Regenerated.
	* testsuite/libsframe.find/find.exp: Add new test.
	* testsuite/libsframe.find/local.mk: Likewise.
	* testsuite/libsframe.find/plt-findfre-1.c: New test.
2023-06-09 11:24:25 -07:00
Indu Bhagat
937c461e41 libsframe: fix sframe_find_fre for pltN entries
To find SFrame stack trace information from an FDE of type
SFRAME_FDE_TYPE_PCMASK, sframe_find_fre () was doing an operation
like,
  (start_ip_offset & 0xff) >= (pc & 0xff), etc.

This is buggy and needs correction.  The mask 0xff should be 0xf (to
work for a pltN entry of size say, 16 bytes).

At this time, the size of the pltN entry is implicitly assumed to be 16
bytes by libsframe.  In next version of the SFrame format, we can encode
this information explicitly in the SFrame FDE.

For now, we should fix the code to at least behave correctly for the
generated code and the generated SFrame stack trace information for the
pltN entries on x86_64.

libsframe/
	* sframe.c (sframe_find_fre): Correct the bitmask used for
	SFrame FDEs of type SFRAME_FDE_TYPE_PCMASK.
2023-06-09 11:14:05 -07:00
Indu Bhagat
676cb9d2e0 libsframe: reuse static function sframe_decoder_get_funcdesc_at_index
sframe_decoder_get_funcdesc_at_index () is the function to access SFrame
FDEs in the SFrame decoder context.  Use it consistently.

Avoid unnecessary type cast and include minor enhancements as the code
is moved around.

libsframe/
	* sframe.c (sframe_decoder_get_funcdesc_at_index): Move some
	checks here.  Move the static function definition before the new
	use.
	(sframe_decoder_get_funcdesc): Use
	sframe_decoder_get_funcdesc_at_index instead.
2023-06-07 15:14:39 -07:00
Indu Bhagat
f4af42724b libsframe: fix cosmetic issues and typos
include/
	* sframe-api.h (sframe_decoder_get_num_fidx): Use extern.
libsframe/
	* sframe-dump.c (dump_sframe_func_with_fres): Fix line length.
	* sframe.c (sframe_frame_row_entry_copy): Likewise.
	(sframe_decode_fre_start_address): Use the intended type uint32_t.
2023-06-06 10:50:07 -07:00
Indu Bhagat
1466e49f7d libsframe: avoid unnecessary type casts
Change the data type of some of the members of the sframe_decoder_ctx
and sframe_encoder_ctx data structures to use the applicable data types
explicitly. Current implementation in libsframe does type casts, which
seem unnecessary.

libsframe/
	* libsframe/sframe-impl.h (struct sframe_decoder_ctx): Use
	applicable data type explicitly.
	(struct sframe_encoder_ctx): Likewise. Use same style of
	comments consistently.
	* libsframe/sframe.c (struct sf_fde_tbl): Define without
	typedef.
	(struct sf_fre_tbl): Likewise.
	(sframe_decode): Remove unnecessary type casts.
	(sframe_encoder_get_funcdesc_at_index): Likewise.
	(sframe_encoder_add_fre): Likewise.
	(sframe_encoder_add_funcdesc): Likewise.
	(sframe_sort_funcdesc): Likewise.
	(sframe_encoder_write_sframe): Likewise.
2023-06-05 14:17:15 -07:00
Indu Bhagat
d987df5c95 libsframe: avoid using magic number
Define a new constant for the maximum number of stack offsets handled in
libsframe, and use it.  Note that the SFrame format does not define such
a constant (limit).  This is an implmentation-defined constant in
libsframe.

include/
	* sframe-api.h (MAX_NUM_STACK_OFFSETS): New definition.
libsframe/
	* sframe.c (sframe_fre_sanity_check_p): Use it.
2023-06-01 09:41:04 -07:00
Indu Bhagat
a5ffdcafc7 libsframe: minor fixups in flip_fre related functions
libsframe/
	* sframe.c (flip_fre_start_address): Remove unnecessary type
	cast.  Use uint16_t instead of unsigned short.
	(flip_fre_stack_offsets): Likewise.
2023-05-31 22:55:41 -07:00
Indu Bhagat
540034ec40 sframe/doc: minor improvements for readability
libsframe/
	* sframe-spec.texi: Cosmetic fixes.
2023-05-25 23:44:15 -07:00
Indu Bhagat
83c219872b libsframe: revisit sframe_find_fre API
Inspite of implementing a rather simple functionality, this function was
relatively difficult to follow, and maintain.  Some changes are done now
to address that - refactor the function and use better names to make it
more readable.

The changes to the implementation do not cause any change in the
contract of the API.

libsframe/
        * sframe.c (sframe_fre_get_end_ip_offset): to here...
        (sframe_find_fre): Refactor some bits from...
2023-05-25 23:44:09 -07:00
Indu Bhagat
812d868850 libsframe: use const char * consistently for immutable FRE buffers
libsframe/
        * sframe.c (sframe_decode_fre): Use const char * datatype when
	handling buffer containing the FREs.
	(sframe_fre_get_end_ip_offset): Likewise.
	(sframe_find_fre): Likewise.
	(sframe_decoder_get_fre): Likewise.
2023-05-25 23:44:02 -07:00
Indu Bhagat
e80578bea7 libsframe: use uint8_t data type for FRE info related stubs
libsframe/
	* sframe.c: Use uint8_t for FRE offset count and FRE offset
	size.  Use uint8_t for FRE info word as well.
2023-05-25 23:43:45 -07:00
Indu Bhagat
6a99f006ec libsframe: testsuite: add tests for sframe_get_funcdesc_with_addr API
sframe_get_funcdesc_with_addr API is currently used internally by the
sframe_find_fre ().

In this test, we create three dummy SFrame FDEs with 4 FREs each.  Then,
we use few negative tests to lookup FREs with PCs not in the range of
PCs covered by the FDEs, ensuring graceful return from
sframe_get_funcdesc_with_addr in all cases.  Some positive tests are
also added that exercise further scenarios as well.

libsframe/
	* Makefile.in: Regenerated.
	* testsuite/libsframe.find/find.exp: Include new test.
	* testsuite/libsframe.find/findfunc-1.c: New Test.
	* testsuite/libsframe.find/local.mk: Include new test.
2023-05-17 23:14:52 -07:00
Indu Bhagat
efd3b63b68 libsframe: testsuite: add new tests for sframe_find_fre API
libsframe provides an API to find the FRE associated with a given PC in
the program.  This patch adds a direct test of this API.

In this test, we create two dummy SFrame FDEs with 4 FREs each.  Then we
test that sframe_find_fre () works for the first, second, third and the
last FRE from one of the FDEs.  Such a test ensures better regression
testing for the sframe_find_fre () function which is going to be the
bread and butter of an SFrame based stack tracer.

libsframe/
	* Makefile.in: Regenerated.
	* testsuite/libsframe.find/find.exp: New test.
	* testsuite/libsframe.find/findfre-1.c: New test.
	* testsuite/libsframe.find/local.mk: Build new test.
	* testsuite/local.mk: Include libsframe.find.
2023-05-17 23:14:36 -07:00
Indu Bhagat
3cae258044 libsframe: minor formatting fixes in sframe_encoder_write_fre
libsframe/
	* sframe.c (sframe_encoder_write_fre): Formatting fixes for
	  readability.
2023-04-19 14:38:18 -07:00
Indu Bhagat
cb45766e48 libsframe: use consistent function argument names
libsframe/
	* sframe.c (sframe_decoder_get_header): Use consistent function
	arg names.
	(sframe_decoder_free): Likewise.
	(sframe_encode): Use more appropriate var name.
2023-04-19 14:38:09 -07:00
Indu Bhagat
8bb878b777 sframe: correct some typos
include/
	* sframe.h: Correct a typo.

libsframe/
	* sframe.c: Likewise.
2023-04-19 14:37:59 -07:00
Indu Bhagat
26be6015b7 libsframe: use return type of bool for predicate functions
libsframe/
	* sframe.c (sframe_header_sanity_check_p): Change return type to
	bool.
	(sframe_fre_sanity_check_p): Likewise.
2023-04-19 14:37:51 -07:00
Alan Modra
41738595c2 Remove unnecessary memsets in sframe-dump.c
* sframe-dump.c (dump_sframe_func_with_fres): Don't memset temp.
2023-03-22 09:39:41 +10:30
Indu Bhagat
469b6d54d3 libsframe/doc: use "stack trace" instead of "unwind" for SFrame
SFrame format is meant for generating stack traces only.

libsframe/
	* doc/sframe-spec.texi: Use "stack trace" instead of "unwind".
2023-02-02 00:47:22 -08:00
Indu Bhagat
436bcab712 libsframe/doc: fix some warnings
'make pdf' in libsframe shows some warnings, some of which (especially
the Overfull warnings) are causing undesirable effects on the rendered
output.  Few examples of the warnings:

  Underfull \hbox (badness 10000) in paragraph at lines 406--407
   @texttt pauth_

  Underfull \hbox (badness 10000) in paragraph at lines 407--410
   @textrm Specify which key is used for signing the return

  ...

  Overfull \hbox (2.0987pt too wide) in paragraph at lines 412--413
   @texttt fdetype[]|

  ...

  Overfull \hbox (28.87212pt too wide) in paragraph at lines 446--447
   @textrm SFRAME[]FDE[]TYPE[]PCMASK|

  ...

This patch adjusts column widths of the affected cells to fix a subset
of these warnings.  For the rest of the warnings, use explicit newline
command to fix them.

libsframe/
	* doc/sframe-spec.texi: Fix various underfull and overfull
	warnings.
2023-01-24 10:08:14 -08:00
Indu Bhagat
0fcd58d843 libsframe: Use AM_SILENT_RULES macro in configure.ac
Silence 'make' by default.

libsframe/
	* configure.ac: Use AM_SILENT_RULES.
	* configure: Regenerate.
2023-01-19 12:40:44 -08:00
Indu Bhagat
68e0003e12 libsframe: replace an strncat with strcat
Calling strncat with the size of the src string is not so meaningful.
The length argument to strncat should specify the remaining bytes
bytes in the destination; although in this case, it appears to be
unncessary altogether to use strncat in the first place.

libsframe/
        * sframe-dump.c (dump_sframe_func_with_fres): Use of strcat is
	just as fine.
2023-01-13 11:15:43 -08:00
Indu Bhagat
725a19bfd1 sframe: fix the defined SFRAME_FRE_TYPE_*_LIMIT constants
An earlier commit 3f107464 defined the SFRAME_FRE_TYPE_*_LIMIT
constants.  These constants are used (by gas and libsframe) to pick an
SFrame FRE type based on the function size.  Those constants, however,
were buggy, causing the generated SFrame sections to be bloated as
SFRAME_FRE_TYPE_ADDR2/SFRAME_FRE_TYPE_ADDR4 got chosen more often than
necessary.

gas/
	* sframe-opt.c (sframe_estimate_size_before_relax): Use
	typecast.
	(sframe_convert_frag): Likewise.

libsframe/
	* sframe.c (sframe_calc_fre_type): Use a more appropriate type
	for argument.  Adjust the check for SFRAME_FRE_TYPE_ADDR4_LIMIT
	to keep it warning-free but meaningful.

include/
	* sframe-api.h (sframe_calc_fre_type): Use a more appropriate
	type for the argument.
	* sframe.h (SFRAME_FRE_TYPE_ADDR1_LIMIT): Correct the constant.
	(SFRAME_FRE_TYPE_ADDR2_LIMIT): Likewise.
	(SFRAME_FRE_TYPE_ADDR4_LIMIT): Likewise.
2023-01-06 09:30:56 -08:00
Indu Bhagat
cd9aea32cf libsframe: adjust an incorrect check in flip_sframe
When sframe_encoder_write needs to flip the buffer containing the SFrame
section before writing, it is not necessary that the SFrame FDES are in
the order of their sfde_func_start_fre_off.  On the contrary, SFrame
FDEs will be sorted in the order of their start address.  So, remove
this incorrect assumption which is basically assuming that the last
sfde_func_start_fre_off seen will help determine the end of the flipped
buffer.

The function now keeps track of the bytes_flipped and then compares it with
the expected value.  Also, added two more checks at appropriate places:
 - check that the SFrame FDE read is within bounds
 - check that the SFrame FRE read is within bounds

libsframe/

	* sframe.c (flip_sframe): Adjust an incorrect check.
	Add other checks to ensure reads are within the buffer size.
2023-01-06 09:29:48 -08:00
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
The newer update-copyright.py fixes file encoding too, removing cr/lf
on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and
embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2023-01-01 21:50:11 +10:30
Indu Bhagat
68bb0d2765 libsframe: write out SFrame FRE start address correctly
The following test was failing on ppc64 and s390x:
  "FAIL: encode-1: Encode buffer match"

The offending stub was how we memcpy the FRE start address to the buffer
(on-disk format).  When the host is big-endian, the address of the
source buffer for the memcpy needs to point to the uint8_t/uint16_t sized
value of the FRE start addr, not uint32_t sized value; we intend to copy
out only the fre_start_addr_sz number of bytes.

ChangeLog:

	* libsframe/sframe.c (sframe_encoder_write_fre_start_addr): New
	function.
	(sframe_encoder_write_fre): Use it instead of memcpy.
2022-12-25 00:08:27 -08:00
Indu Bhagat
28f1a767db libsframe: testsuite: fix memory leaks in testcases
ChangeLog:

	* libsframe/testsuite/libsframe.decode/be-flipping.c: Free
	SFrame buffer.
	* libsframe/testsuite/libsframe.decode/frecnt-1.c: Likewise.
	* libsframe/testsuite/libsframe.decode/frecnt-2.c: Likewise.
2022-12-23 13:04:19 -08:00
Indu Bhagat
995bc59782 libsframe: fix a memory leak in sframe_decode
sframe_decode () needs to malloc a temporary buffer of the same size as
the input buffer (containing the SFrame section bytes) when endian
flipping is needed.  The decoder keeps the endian flipped contents in
this buffer for its usage.  This code is necessary when the target
endianneess is not the same as host endianness.

The malloc'd buffer needs to be kept track of, so that it can freed up in
sframe_decoder_free () later.

ChangeLog:

	* libsframe/sframe-impl.h (struct sframe_decoder_ctx): Add new
	member to keep track of the internally malloc'd buffer.
	* libsframe/sframe.c (sframe_decoder_free): Free it up.
	(sframe_decode): Update the reference to the buffer.
2022-12-23 13:04:06 -08:00
Indu Bhagat
2440ed038a sframe: doc: update documentation for pauth key in SFrame FDE
ChangeLog:

	* libsframe/doc/sframe-spec.texi
2022-12-22 09:58:21 -08:00
Indu Bhagat
95e829affb objdump/readelf: sframe: emit marker for SFrame FDE with B key
ChangeLog:

	* libsframe/sframe-dump.c (is_sframe_abi_arch_aarch64): New
	definition.
	(dump_sframe_func_with_fres): Emit a string if B key is used.
2022-12-22 09:57:27 -08:00
Indu Bhagat
6e09ae77a1 sframe: doc: update spec for the mangled-RA bit in FRE
ChangeLog:

	* libsframe/doc/sframe-spec.texi
2022-12-16 22:02:11 -08:00
Indu Bhagat
49948bce0e objdump/readelf: sframe: emit marker for FREs with mangled RA
In the textual dump of the SFrame section, when an SFrame FRE recovers a
mangled RA, use string "[s]" in the output to indicate that the return
address is a signed (mangled) one.

ChangeLog:

        * libsframe/sframe-dump.c (dump_sframe_func_with_fres): Postfix
	with "[s]" if RA is signed with authorization code.
2022-12-16 22:02:02 -08:00
Indu Bhagat
9c4b163cb5 libsframe: provide new access API for mangled RA bit
include/ChangeLog:

	* sframe-api.h (sframe_fre_get_ra_mangled_p): New declaration.

ChangeLog:

	* libsframe/sframe.c (sframe_get_fre_ra_mangled_p): New
	definition.
	(sframe_fre_get_ra_mangled_p): New static function.
2022-12-16 22:01:57 -08:00