aboutsummaryrefslogtreecommitdiff
path: root/libsframe
AgeCommit message (Collapse)AuthorFilesLines
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.
2022-12-09libsframe: rename API sframe_fde_func_info to sframe_fde_create_func_infoIndu Bhagat2-7/+7
The new name better reflects the purpose of the function. ChangeLog: * bfd/elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Use new name. * libsframe/sframe.c (sframe_fde_create_func_info): Rename sframe_fde_func_info to this. * libsframe/testsuite/libsframe.encode/encode-1.c: Use new name. include/ChangeLog: * sframe-api.h (sframe_fde_create_func_info): Rename sframe_fde_func_info to this.
2022-12-09sframe: gas: libsframe: define constants and remove magic numbersIndu Bhagat1-3/+3
Define constants in sframe.h for the various limits associated with the range of offsets that can be encoded in the start address of an SFrame FRE. E.g., sframe_frame_row_entry_addr1 is used when start address offset can be encoded as 1-byte unsigned value. Update the code in gas to use these defined constants as it checks for these limits, and remove the usage of magic numbers. ChangeLog: * gas/sframe-opt.c (sframe_estimate_size_before_relax): (sframe_convert_frag): Do not use magic numbers. * libsframe/sframe.c (sframe_calc_fre_type): Likewise. include/ChangeLog: * sframe.h (SFRAME_FRE_TYPE_ADDR1_LIMIT): New constant. (SFRAME_FRE_TYPE_ADDR2_LIMIT): Likewise. (SFRAME_FRE_TYPE_ADDR4_LIMIT): Likewise.
2022-12-09libsframe: minor formatting nitsIndu Bhagat1-16/+14
ChangeLog: * libsframe/sframe.c: Fix formatting nits.
2022-11-24sframe/doc: remove usage of xrefautomaticsectiontitleIndu Bhagat1-5/+2
xrefautomaticsectiontitle appears to be available from texinfo 5.0 or greater. As such, it is not worthwhile to add requirement for a minimum necessary makeinfo version. So remove the usage of it. Also align node name with section title where possible. ChangeLog: * libsframe/doc/sframe-spec.texi: Remove usage of xrefautomaticsectiontitle.
2022-11-15doc: add SFrame spec fileIndu Bhagat6-51/+1137
ChangeLog: * libsframe/Makefile.am: Add info-in-builddir to AUTOMAKE_OPTIONS. Include doc/local.mk. * libsframe/Makefile.in: Regenerated. * libsframe/configure: Likewise. * libsframe/configure.ac: Check for makeinfo and set BUILD_INFO. * libsframe/doc/local.mk: New file. * libsframe/doc/sframe-spec.texi: Likewise.
2022-11-15readelf/objdump: support for SFrame sectionIndu Bhagat3-3/+192
This patch adds support for SFrame in readelf and objdump. The arguments of --sframe are optional for both readelf and objdump. include/ChangeLog: * sframe-api.h (dump_sframe): New function declaration. ChangeLog: * binutils/Makefile.am: Add dependency on libsframe for readelf and objdump. * binutils/Makefile.in: Regenerate. * binutils/doc/binutils.texi: Document --sframe=[section]. * binutils/doc/sframe.options.texi: New file. * binutils/objdump.c: Add support for SFrame format. * binutils/readelf.c: Likewise. * include/sframe-api.h: Add new API for dumping .sframe section. * libsframe/Makefile.am: Add sframe-dump.c. * libsframe/Makefile.in: Regenerate. * libsframe/sframe-dump.c: New file.
2022-11-15bfd: linker: merge .sframe sectionsIndu Bhagat1-5/+23
The linker merges all the input .sframe sections. When merging, the linker verifies that all the input .sframe sections have the same abi/arch. The linker uses libsframe library to perform key actions on the .sframe sections - decode, read, and create output data. This implies buildsystem changes to make and install libsframe before libbfd. The linker places the output .sframe section in a new segment of its own: PT_GNU_SFRAME. A new segment is not added, however, if the generated .sframe section is empty. When a section is discarded from the final link, the corresponding entries in the .sframe section for those functions are also deleted. The linker sorts the SFrame FDEs on start address by default and sets the SFRAME_F_FDE_SORTED flag in the .sframe section. This patch also adds support for generation of SFrame unwind information for the .plt* sections on x86_64. SFrame unwind info is generated for IBT enabled PLT, lazy/non-lazy PLT. The existing linker option --no-ld-generated-unwind-info has been adapted to include the control of whether .sframe unwind information will be generated for the linker generated sections like PLT. Changes to the linker script have been made as necessary. ChangeLog: * Makefile.def: Add install dependency on libsframe for libbfd. * Makefile.in: Regenerated. * bfd/Makefile.am: Add elf-sframe.c * bfd/Makefile.in: Regenerated. * bfd/bfd-in2.h (SEC_INFO_TYPE_SFRAME): Regenerated. * bfd/configure: Regenerate. * bfd/configure.ac: Add elf-sframe.lo. * bfd/elf-bfd.h (struct sframe_func_bfdinfo): New struct. (struct sframe_dec_info): Likewise. (struct sframe_enc_info): Likewise. (struct elf_link_hash_table): New member for encoded .sframe object. (struct output_elf_obj_tdata): New member. (elf_sframe): New access macro. (_bfd_elf_set_section_sframe): New declaration. * bfd/elf.c (get_segment_type): Handle new segment PT_GNU_SFRAME. (bfd_section_from_phdr): Likewise. (get_program_header_size): Likewise. (_bfd_elf_map_sections_to_segments): Likewise. * bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Add contents to the .sframe sections or .plt* entries. * bfd/elflink.c (elf_section_ignore_discarded_relocs): Handle SEC_INFO_TYPE_SFRAME. (_bfd_elf_default_action_discarded): Handle .sframe section. (elf_link_input_bfd): Merge .sframe section. (bfd_elf_final_link): Write the output .sframe section. (bfd_elf_discard_info): Handle discarding .sframe section. * bfd/elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Create .sframe section for .plt and .plt.sec. (_bfd_x86_elf_finish_dynamic_sections): Handle .sframe from .plt* sections. * bfd/elfxx-x86.h (PLT_SFRAME_FDE_START_OFFSET): New definition. (SFRAME_PLT0_MAX_NUM_FRES): Likewise. (SFRAME_PLTN_MAX_NUM_FRES): Likewise. (struct elf_x86_sframe_plt): New structure. (struct elf_x86_link_hash_table): New member. (struct elf_x86_init_table): New members for .sframe creation. * bfd/section.c: Add new definition SEC_INFO_TYPE_SFRAME. * binutils/readelf.c (get_segment_type): Handle new segment PT_GNU_SFRAME. * ld/ld.texi: Update documentation for --no-ld-generated-unwind-info. * ld/scripttempl/elf.sc: Support .sframe sections. * ld/Makefile.am (TESTSFRAMELIB): Use it. (check-DEJAGNU): Likewise. * ld/Makefile.in: Regenerated. * ld/configure.ac (TESTSFRAMELIB): Set to the .so or .a like TESTBFDLIB. * ld/configure: Regenerated. * bfd/elf-sframe.c: New file. include/ChangeLog: * elf/common.h (PT_GNU_SFRAME): New definition. * elf/internal.h (struct elf_segment_map): Handle new segment type PT_GNU_SFRAME. ld/testsuite/ChangeLog: * ld/testsuite/ld-bootstrap/bootstrap.exp: Add SFRAMELIB. * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add new test sframe-simple-1. * ld/testsuite/ld-aarch64/sframe-bar.s: New file. * ld/testsuite/ld-aarch64/sframe-foo.s: Likewise. * ld/testsuite/ld-aarch64/sframe-simple-1.d: Likewise. * ld/testsuite/ld-sframe/sframe-empty.d: New test. * ld/testsuite/ld-sframe/sframe-empty.s: New file. * ld/testsuite/ld-sframe/sframe.exp: New testsuite. * ld/testsuite/ld-x86-64/sframe-bar.s: New file. * ld/testsuite/ld-x86-64/sframe-foo.s: Likewise. * ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise. * ld/testsuite/ld-x86-64/sframe-plt-1.d: Likewise. * ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise. * ld/testsuite/ld-x86-64/x86-64.exp: Add new tests - sframe-simple-1, sframe-plt-1. * ld/testsuite/lib/ld-lib.exp: Add new proc to check if assembler supports SFrame section. * ld/testsuite/ld-sframe/discard.d: New file. * ld/testsuite/ld-sframe/discard.ld: Likewise. * ld/testsuite/ld-sframe/discard.s: Likewise.
2022-11-15libsframe: add the SFrame libraryWeimin Pan22-0/+20034
libsframe is a library that allows you to: - decode a .sframe section - probe and inspect a .sframe section - encode (and eventually write) a .sframe section. This library is currently being used by the linker, readelf, objdump. This library will also be used by the SFrame unwinder which is still to be upstream'd. The file include/sframe-api.h defines the user-facing APIs for decoding, encoding and probing .sframe sections. A set of error codes together with their error message strings are also defined. Endian flipping is performed automatically at read and write time, if cross-endianness is detected. ChangeLog: * Makefile.def: Add libsframe as new module with its dependencies. * Makefile.in: Regenerated. * binutils/Makefile.am: Add libsframe. * binutils/Makefile.in: Regenerated. * configure: Regenerated * configure.ac: Add libsframe to host_libs. * libsframe/Makefile.am: New file. * libsframe/Makefile.in: New file. * libsframe/aclocal.m4: New file. * libsframe/config.h.in: New file. * libsframe/configure: New file. * libsframe/configure.ac: New file. * libsframe/sframe-error.c: New file. * libsframe/sframe-impl.h: New file. * libsframe/sframe.c: New file. include/ChangeLog: * sframe-api.h: New file. testsuite/ChangeLog: * libsframe/testsuite/Makefile.am: New file. * libsframe/testsuite/Makefile.in: Regenerated. * libsframe/testsuite/libsframe.decode/Makefile.am: New file. * libsframe/testsuite/libsframe.decode/Makefile.in: Regenerated. * libsframe/testsuite/libsframe.decode/decode.exp: New file. * libsframe/testsuite/libsframe.encode/Makefile.am: Likewise. * libsframe/testsuite/libsframe.encode/Makefile.in: Regenerated. * libsframe/testsuite/libsframe.encode/encode.exp: New file. * libsframe/testsuite/libsframe.encode/encode-1.c: Likewise. * libsframe/testsuite/libsframe.decode/be-flipping.c: Likewise. * libsframe/testsuite/libsframe.decode/frecnt-1.c: Likewise. * libsframe/testsuite/libsframe.decode/frecnt-2.c: Likewise. * libsframe/testsuite/libsframe.decode/DATA-BE: New file. * libsframe/testsuite/libsframe.decode/DATA1: Likewise. * libsframe/testsuite/libsframe.decode/DATA2: Likewise.