aboutsummaryrefslogtreecommitdiff
path: root/libsframe
AgeCommit message (Collapse)AuthorFilesLines
2023-08-12regen configAlan Modra1-21/+52
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-06-29doc: sframe: update specification for SFRAME_VERSION_2Indu Bhagat1-10/+74
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-29sframe: bfd: gas: ld: format bump to SFrame version 2Indu Bhagat7-22/+98
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-29libsframe: add new APIs to get SFrame versionIndu Bhagat2-0/+22
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-29libsframe: fix sframe_find_fre for pltN entriesIndu Bhagat2-24/+60
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-27libsframe: bfd: use uint32_t for return type of get_num_fidx APIsIndu Bhagat1-5/+5
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-27libsframe: use appropriate data types for args of sframe_encodeIndu Bhagat1-2/+3
include/ * sframe-api.h (sframe_encode): Use of uint8_t is more appropriate. libsframe/ * sframe.c (sframe_encode): Likewise.
2023-06-27libsframe: use uint8_t for return type of sframe_fre_get_base_reg_idIndu Bhagat2-2/+2
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-27libsframe: use uint8_t instead of unsigned char for abi_archIndu Bhagat2-9/+9
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-27libsframe: bfd: use uint32_t for return type of sframe_calc_fre_typeIndu Bhagat1-1/+1
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-27libsframe: use uint32_t for fre_type and fde_type function argsIndu Bhagat1-21/+21
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-27libsframe: update the semantics of sframe_fre_get_fp_offsetIndu Bhagat1-6/+11
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-27libsframe: update the semantics of sframe_fre_get_ra_offsetIndu Bhagat2-9/+17
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-27libsframe: add symbol versioningIndu Bhagat5-6/+144
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-27libsframe: remove sframe_get_funcdesc_with_addr APIIndu Bhagat1-4/+16
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-27libsframe: add library versioningIndu Bhagat3-1/+43
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-09libsframe: testsuite: add sframe_find_fre tests for pltN entriesIndu Bhagat4-5/+175
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-09libsframe: fix sframe_find_fre for pltN entriesIndu Bhagat1-1/+1
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-07libsframe: reuse static function sframe_decoder_get_funcdesc_at_indexIndu Bhagat1-23/+25
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-06libsframe: fix cosmetic issues and typosIndu Bhagat2-4/+6
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-05libsframe: avoid unnecessary type castsIndu Bhagat2-25/+34
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-01libsframe: avoid using magic numberIndu Bhagat1-1/+1
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-05-31libsframe: minor fixups in flip_fre related functionsIndu Bhagat1-7/+5
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-25sframe/doc: minor improvements for readabilityIndu Bhagat1-10/+10
libsframe/ * sframe-spec.texi: Cosmetic fixes.
2023-05-25libsframe: revisit sframe_find_fre APIIndu Bhagat1-34/+49
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-25libsframe: use const char * consistently for immutable FRE buffersIndu Bhagat1-13/+11
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-25libsframe: use uint8_t data type for FRE info related stubsIndu Bhagat1-21/+20
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-17libsframe: testsuite: add tests for sframe_get_funcdesc_with_addr APIIndu Bhagat4-5/+252
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-17libsframe: testsuite: add new tests for sframe_find_fre APIIndu Bhagat5-10/+250
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-04-19libsframe: minor formatting fixes in sframe_encoder_write_freIndu Bhagat1-11/+7
libsframe/ * sframe.c (sframe_encoder_write_fre): Formatting fixes for readability.
2023-04-19libsframe: use consistent function argument namesIndu Bhagat1-14/+14
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-19sframe: correct some typosIndu Bhagat1-1/+1
include/ * sframe.h: Correct a typo. libsframe/ * sframe.c: Likewise.
2023-04-19libsframe: use return type of bool for predicate functionsIndu Bhagat1-9/+9
libsframe/ * sframe.c (sframe_header_sanity_check_p): Change return type to bool. (sframe_fre_sanity_check_p): Likewise.
2023-03-22Remove unnecessary memsets in sframe-dump.cAlan Modra1-3/+0
* sframe-dump.c (dump_sframe_func_with_fres): Don't memset temp.
2023-02-02libsframe/doc: use "stack trace" instead of "unwind" for SFrameIndu Bhagat1-18/+19
SFrame format is meant for generating stack traces only. libsframe/ * doc/sframe-spec.texi: Use "stack trace" instead of "unwind".
2023-01-24libsframe/doc: fix some warningsIndu Bhagat1-9/+17
'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-19libsframe: Use AM_SILENT_RULES macro in configure.acIndu Bhagat2-2/+42
Silence 'make' by default. libsframe/ * configure.ac: Use AM_SILENT_RULES. * configure: Regenerate.
2023-01-13libsframe: replace an strncat with strcatIndu Bhagat1-2/+1
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-06sframe: fix the defined SFRAME_FRE_TYPE_*_LIMIT constantsIndu Bhagat1-2/+4
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-06libsframe: adjust an incorrect check in flip_sframeIndu Bhagat1-9/+13
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-01Update year range in copyright notice of binutils filesAlan Modra16-17/+17
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.
2022-12-25libsframe: write out SFrame FRE start address correctlyIndu Bhagat1-3/+35
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-23libsframe: testsuite: fix memory leaks in testcasesIndu Bhagat3-0/+9
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-23libsframe: fix a memory leak in sframe_decodeIndu Bhagat2-4/+20
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-22sframe: doc: update documentation for pauth key in SFrame FDEIndu Bhagat1-1/+7
ChangeLog: * libsframe/doc/sframe-spec.texi
2022-12-22objdump/readelf: sframe: emit marker for SFrame FDE with B keyIndu Bhagat1-0/+19
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-16sframe: doc: update spec for the mangled-RA bit in FREIndu Bhagat1-2/+2
ChangeLog: * libsframe/doc/sframe-spec.texi
2022-12-16objdump/readelf: sframe: emit marker for FREs with mangled RAIndu Bhagat1-2/+9
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-16libsframe: provide new access API for mangled RA bitIndu Bhagat1-0/+18
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-15libsframe asan: avoid generating misaligned loadsIndu Bhagat2-10/+24
There are two places where unaligned loads were seen on aarch64: - #1. access to the SFrame FRE stack offsets in the in-memory representation/abstraction provided by libsframe. - #2. access to the SFrame FRE start address in the on-disk representation of the frame row entry. For #1, we can fix this by reordering the struct members of sframe_frame_row_entry in libsframe/sframe-api.h. For #2, we need to default to using memcpy instead, and copy out the bytes to a location for output. SFrame format is an unaligned on-disk format. As such, there are other blobs of memory in the on-disk SFrame FRE that are on not on their natural boundaries. But that does not pose further problems yet, because the users are provided access to the on-disk SFrame FRE data via libsframe's sframe_frame_row_entry, the latter has its' struct members aligned on their respective natural boundaries (and initialized using memcpy). PR 29856 libsframe asan: load misaligned at sframe.c:516 ChangeLog: PR libsframe/29856 * bfd/elf64-x86-64.c: Adjust as the struct members have been reordered. * libsframe/sframe.c (sframe_decode_fre_start_address): Use memcpy to perform 16-bit/32-bit reads. * libsframe/testsuite/libsframe.encode/encode-1.c: Adjust as the struct members have been reordered. include/ChangeLog: PR libsframe/29856 * sframe-api.h: Reorder fre_offsets for natural alignment.