GCC14 warns about the order of the arguments to calloc
libsframe/sframe-dump.c: In function ‘dump_sframe_header’:
libsframe/sframe-dump.c:70:39: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
70 | flags_str = (char*) calloc (sizeof (char), SFRAME_HEADER_FLAGS_STR_MAX_LEN);
| ^~~~
libsframe/sframe-dump.c:70:39: note: earlier argument should specify number of elements, later size of each element
Fix this by swapping the size and count arguments.
libsframe/
* sframe-dump.c (dump_sframe_header): Swap arguments to calloc
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.
This regenerates config files changed by the previous 44 commits.
Note that subject lines in these commits mostly match the gcc git
originating commit.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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...
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.
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.
libsframe/
* sframe.c (sframe_decoder_get_header): Use consistent function
arg names.
(sframe_decoder_free): Likewise.
(sframe_encode): Use more appropriate var name.
'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.
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.
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.
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.
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.
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.
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.
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.